- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一款小游戏。我已经快完成了,但我面临的剩余问题可以分为三个:
ScorePanel
。这是我的代码的三个主要类:
public class Fenetre extends JFrame {
private JMenuBar menu = new JMenuBar();
private JMenu file = new JMenu("Fichier");
private JMenuItem neew = new JMenuItem("Nouveau");
private JMenuItem score = new JMenuItem("Score");
private JMenuItem quit = new JMenuItem("Quitter");
private JMenu about = new JMenu("About");
private JMenuItem how = new JMenuItem("Règles");
private JMenuItem who = new JMenuItem("Credit");
private int i=1;
private ScorePanel scorepan = new ScorePanel(900,650);
private ReglesJeuPanel rgpan = new ReglesJeuPanel(900,650);
private GamePanel gamepan = new GamePanel();
private JPanel pan = new JPanel();
private JPanel container = new JPanel();
private JLabel label = new JLabel("------------------------SAMAIKOM------------------------");
private JTextArea texte = new JTextArea( "Vous avez sept coups pour trouver le mot caché. Si vous réussissez, on recommence !\n" +
"Plus vous trouvez de mots, plus votre score augmente. Alors, à vous de jouer !\n" +
"Proverbe :\t« Pas vu, pas pris !\n" +
"\tPris ! PENDU ! »");
public Fenetre(){
this.setTitle("Le Pendu ...");
this.setSize(900, 650);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
initMenu();
initAcceuilPan();
initListeners();
this.setContentPane(container);
}
private void initMenu(){
file.add(neew);
file.add(score);
file.addSeparator();
file.add(quit);
file.setMnemonic('F');
neew.setMnemonic('N');
neew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,KeyEvent.CTRL_DOWN_MASK));
score.setMnemonic('S');
score.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,KeyEvent.CTRL_DOWN_MASK));
quit.setMnemonic('Q');
quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,KeyEvent.CTRL_DOWN_MASK));
about.add(how);
about.addSeparator();
about.add(who);
about.setMnemonic('A');
how.setMnemonic('R');
how.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,KeyEvent.CTRL_DOWN_MASK));
who.setMnemonic('C');
who.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,KeyEvent.CTRL_DOWN_MASK));
menu.add(file);
menu.add(about);
this.setJMenuBar(menu);
}
private void initListeners(){
score.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
container.removeAll();
container.add(scorepan);
}
});
quit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
how.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
container.removeAll();
container.add(rgpan);
}
});
neew.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
gamepan.setNewWord();
gamepan.resetButtons();
container.removeAll();
container.add(gamepan);
}
});
gamepan.addCustomListener(new CustomListener(){
public void wordFound() {
neew.doClick();
}
public void wordNotFound() {
if(!ScorePanel.isScoreSuffisant())
{
container.removeAll();
initAcceuilPan();
}
if(ScorePanel.isScoreSuffisant()){
scorepan.initLeftPan();
container.removeAll();
container.add(scorepan);
}
}
});
}
private void initAcceuilPan(){
pan.removeAll(); // si on ne met pas cette methode, apres la réinisialisation du container si le mot n'a pas été trouvé on trouve 2 images!
pan.setBackground(Color.white);
pan.add(new JLabel(new ImageIcon("131868.jpg")));
texte.setEditable(false);
Font F1 = new Font("arial",Font.BOLD,20);
Font F2 = new Font("arial",Font.BOLD,15);
label.setFont(F1);
texte.setFont(F2);
container.setBackground(Color.white);
container.add(label);
container.add(pan);
container.add(texte);
//container.add(gamepan);
}
}
public class GamePanel extends JPanel{
private JPanel leftPan = new JPanel();
private JPanel rightPan = new JPanel();
private String[] letters = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",};
private JButton Button[] = new JButton[26];
private JLabel label1;
private JLabel label2;
private JLabel label3;
private String mistakeslabel; // pour savoir si un traitement a été fais ou non sur le tWord ( pour les mistakes )
private ActionListener buttonListener;
private JOptionPane jop = new JOptionPane();
private Word randWord = new Word(); // mot aléatoire
private TreatedWord tWord = new TreatedWord(randWord.getRandWord());// mot aléatoire traité ( etoiles et tout ça )
private char clickedButton;// lettre tappée
private int mistakes = 0;
private int coups = 0;
private final List<CustomListener> customListener = new LinkedList<>(); //On crée une liste de CustomListener pour en ajouter autant qu'on veut(Via addCustomListener)
public GamePanel(){
this.setBackground(Color.white);
initGamePan();
initListeners();
this.setLayout(new BorderLayout());
this.add(leftPan,BorderLayout.WEST);
this.add(rightPan,BorderLayout.EAST);
}
public void initGamePan(){
label1 = new JLabel("Nombre de mots trouvés : 0");
label1.setHorizontalAlignment(JLabel.CENTER);
label1.setFont(new Font("arial",Font.BOLD,20));
label1.setPreferredSize(new Dimension(300,50));
label2 = new JLabel("Score Actuel : 0 point");
label2.setHorizontalAlignment(JLabel.CENTER);
label2.setFont(new Font("arial",Font.BOLD,20));
label2.setPreferredSize(new Dimension(300,50));
label3 = new JLabel(tWord.getStars());
label3.setHorizontalAlignment(JLabel.CENTER);
label3.setFont(new Font("arial",Font.BOLD,30));
label3.setForeground(Color.blue);
label3.setPreferredSize(new Dimension(450,50));
mistakeslabel=label3.getText();
leftPan.add(label1);
leftPan.add(label2);
leftPan.add(label3);
for(int i=0;i<letters.length;i++){
Button[i]= new JButton(letters[i]);
leftPan.add(Button[i]);
}
leftPan.setPreferredSize(new Dimension(460,650));
leftPan.setBackground(Color.WHITE);
rightPan.setPreferredSize(new Dimension(420,650));
rightPan.setBackground(Color.WHITE);
}
public void initListeners(){
buttonListener= new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
clickedButton = ((JButton)(arg0.getSource())).getText().charAt(0); // on prend le bouton cliqué, on le convertis en string puis en char
label3.setText(tWord.treatedWord(clickedButton));// on donne a la methode tretedWord de l'objet tWord le char clickedbutton pour faire le traitement sur le mot mystère
((JButton)(arg0.getSource())).setEnabled(false);
if(mistakeslabel==label3.getText()){
mistakes++;
rightPan.removeAll();
switch(mistakes){
case 1 : rightPan.add(new JLabel(new ImageIcon("131870.jpg")));
break;
case 2 : rightPan.add(new JLabel(new ImageIcon("131871.jpg")));
break;
case 3 : rightPan.add(new JLabel(new ImageIcon("131872.jpg")));
break;
case 4 : rightPan.add(new JLabel(new ImageIcon("131873.jpg")));
break;
case 5 : rightPan.add(new JLabel(new ImageIcon("131874.jpg")));
break;
case 6 : rightPan.add(new JLabel(new ImageIcon("131875.jpg")));
break;
case 7 : rightPan.add(new JLabel(new ImageIcon("131876.jpg")));
break;
}
}
mistakeslabel=label3.getText();
coups++;
System.out.println(randWord.getRandWord());
if(tWord.isFound()){
String S;
S=ScorePanel.updateScore(coups,mistakes);
jop.showMessageDialog(null, "Bravo t'a trouvé le mot "+randWord.getRandWord()+" !\n en "+coups+" coups et "+mistakes+" erreur"+(mistakes>1 ? "s" : "")+S, "U don't Say B|", JOptionPane.INFORMATION_MESSAGE);
GamePanel.this.notifyWordFound(); // explications à la fin
}
if(mistakes==7){
if(!ScorePanel.isScoreSuffisant())
{
jop.showMessageDialog(null, "Score Insuffisant pour l'enregistrer ...", "hahahah wa l3iaaaan !", JOptionPane.INFORMATION_MESSAGE);
}
if(ScorePanel.isScoreSuffisant())
{
String Sc;
Sc=jop.showInputDialog(null,"Entrez un pseudo","Mabikch",JOptionPane.INFORMATION_MESSAGE);
ScorePanel.updateScoreLeftPan(Sc);
}
GamePanel.this.notifyWordNotFound();
mistakes=0;
}
}
};
for(int i=0;i<letters.length;i++){
Button[i].addActionListener(buttonListener);
}
}
public void setNewWord(){
this.randWord = new Word();
this.tWord = new TreatedWord(randWord.getRandWord());
this.label3.setText(tWord.getStars());
this.mistakeslabel=label3.getText();
this.mistakes=0;
this.rightPan.add(new JLabel(new ImageIcon("131869.jpg")));
}
public void resetButtons(){
for(JButton B : this.Button){
B.setEnabled(true);
}
}
public void addCustomListener(final CustomListener listener) {
this.customListener.add(listener);
}
private void notifyWordFound(/* any data you could use */) {
for(final CustomListener listener : this.customListener) {
listener.wordFound(/* any data you could use */);
}
}
private void notifyWordNotFound(/* any data you could use */) {
for(final CustomListener listener : this.customListener) {
listener.wordNotFound(/* any data you could use */);
}
}
}
public class ScorePanel extends JPanel{
private JPanel rightpan = new JPanel();
private JPanel leftpan = new JPanel();
private static int[] scores = {200,100,100,100,50,50,50,25,15,15};
private static String players[] = {"Haytam lwa3er","Player1","Player2","Player3","Player4","Player5","Player6","Player7","Player8","Player9"};
private int[] policeSize = {30, 28, 27, 26, 25, 24, 23, 22, 21, 20};
private JLabel label;
private static int score=0;
private static int scoreTotal=0;
public ScorePanel(int w,int h){
this.setPreferredSize(new Dimension(w,h));
this.setBackground(Color.white);
this.setLayout(new BorderLayout());
initLeftPan();
rightpan.setPreferredSize(new Dimension(430,650));
rightpan.setBackground(Color.white);
rightpan.add(new JLabel(new ImageIcon("131876.jpg")));
this.add(leftpan,BorderLayout.CENTER);
this.add(rightpan,BorderLayout.EAST);
}
public void initLeftPan(){
leftpan.removeAll();
leftpan.setPreferredSize(new Dimension(470,500));
leftpan.setBackground(Color.white);
for(int i=0;i<players.length;i++){
label= new JLabel(" "+players[i]+" : "+scores[i]+" pts "+"(1mot)"+" ");
Font F1= new Font("Comics Sans MS", Font.BOLD, policeSize[i]);
label.setFont(F1);
leftpan.add(label);
}
}
public static String updateScore(int coups,int mistakes){
switch(mistakes){
case 0 : score = 100;
break;
case 1 : score = 50;
break;
case 2 : score = 35;
break;
case 3 : score = 25;
break;
case 4 : score = 15;
break;
case 5 : score = 10;
break;
case 6 : score = 5;
break;
}
scoreTotal=scoreTotal+score;
return "\n Vous parquez "+score+" Points\nScore Total : "+scoreTotal;
}
public static boolean isScoreSuffisant(){
if(scoreTotal>=scores[9])return true;
else return false;
}
public static void updateScoreLeftPan(String pseudo){
for(int i=0;i<scores.length;i++){
if(scoreTotal>=scores[i]){
for(int j=scores.length-1;j>i-1;j--){
if(scoreTotal>=scores[j] && j!=0){
scores[j]=scores[j-1];
players[j]= players[j-1];
}
if(j==i){scores[j]=scoreTotal; players[j]=pseudo;}
}
break;
}
}
}
}
最佳答案
The first one is, when I execute my game, nothings shows up on the window just a gray background, when I reduce it and clic on it again, I find what normally I should see; and this problem with all the panels, for exemple to move from the game panel to the score panel I should reduce it again ...
这通常是在您实际向窗口添加任何内容之前调用 setVisible(true)
的症状...
The third problem is that I cannot execute my generated JAR file, I sought a sollution for a while but in vain
这可能是因为您未能向 mainfest 文件提供 Main-Class
条目。看看Setting an Application's Entry Point
==
不是 Java 中 String
比较的方式,而是您想要使用 String#equals
,例如...
if (mistakeslabel == label3.getText()) {...
应该是
if (mistakeslabel.equals(label3.getText())) {...
The second problem is that it is slow ! especially if it needs to calculate score when I lose and seeds to display my updated scorepanel ...
这还不清楚,但我怀疑,如果您在更改面板后调用 revalidate
和 repaint
或使用 CardLayout
,您可能会发现这样效果更好
关于java - JPanels显示问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21106370/
我的Angular-Component位于一个flexbox(id =“log”)中。可以显示或隐藏flexbox。 我的组件内部有一个可滚动区域,用于显示日志消息。 (id =“message-li
我真的很困惑 有一个 phpinfo() 输出: MySQL 支持 启用 客户端 API 版本 5.5.40 MYSQL_MODULE_TYPE 外部 phpMyAdmin 显示: 服务器类型:Mar
我正在研究这个 fiddle : http://jsfiddle.net/cED6c/7/我想让按钮文本在单击时发生变化,我尝试使用以下代码: 但是,它不起作用。我应该如何实现这个?任何帮助都会很棒
我应该在“dogs_cats”中保存表“dogs”和“cats”各自的ID,当看到数据时显示狗和猫的名字。 我有这三个表: CREATE TABLE IF NOT EXISTS cats ( id
我有一个字符串返回到我的 View 之一,如下所示: $text = 'Lorem ipsum dolor ' 我正在尝试用 Blade 显示它: {{$text}} 但是,输出是原始字符串而不是渲染
我无法让我的链接(由图像表示,位于页面左侧)真正有效地显示一个 div(包含一个句子,位于中间)/单击链接时隐藏。 这是我的代码: Practice
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
最初我使用 Listview 来显示 oracle 结果,但是最近我不得不切换到 datagridview 来处理比 Listview 允许的更多的结果。然而,自从切换到数据网格后,我得到的结果越来越
我一直在尝试插入一个 Unicode 字符 ∇ 或 ▽,所以它显示在 Apache FOP 生成的 PDF 中。 这是我到目前为止所做的: 根据这个基本帮助 Apache XSL-FO Input,您
我正在使用 node v0.12.7 编写一个 nodeJS 应用程序。 我正在使用 pm2 v0.14.7 运行我的 nodejs 应用程序。 我的应用程序似乎有内存泄漏,因为它从我启动时的大约 1
好的,所以我有一些 jQuery 代码,如果从下拉菜单中选择了带有前缀 Blue 的项目,它会显示一个输入框。 代码: $(function() { $('#text1').hide();
当我试图检查 Chrome 中的 html 元素时,它显示的是 LESS 文件,而 Firefox 显示的是 CSS 文件。 (我正在使用 Bootstrap 框架) 如何在 Chrome 中查看 c
我是 Microsoft Bot Framework 的新手,我正在通过 youtube 视频 https://youtu.be/ynG6Muox81o 学习它并在 Ubuntu 上使用 python
我正在尝试转换从 mssql 生成的文件到 utf-8。当我打开他的输出 mssql在 Windows Server 2003 中使用 notepad++ 将文件识别为 UCS-2LE我使用 file
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我正在尝试执行单击以打开/关闭一个 div 的功能。 这是基本的,但是,点击只显示 div,当我点击“关闭”时,没有任何反应。 $(".inscricao-email").click(function
假设我有 2 张卡片,屏幕上一次显示一张。我有一个按钮可以用其他卡片替换当前卡片。现在假设卡 1 上有一些数据,卡 2 上有一些数据,我不想破坏它们每个上的数据,或者我不想再次重建它们中的任何一个。
我正在使用 Eloquent Javascript 学习 Javascript。 我在 Firefox 控制台上编写了以下代码,但它返回:“ReferenceError:show() 未定义”为什么?
我正在使用 Symfony2 开发一个 web 项目,我使用 Sonata Admin 作为管理面板,一切正常,但我想要做的是,在 Sonata Admin 的仪表板菜单上,我需要显示隐藏一些菜单取决
我试图显示一个div,具体取决于从下拉列表中选择的内容。例如,如果用户从列表中选择“现金”显示现金div或用户从列表中选择“检查”显示现金div 我整理了样本,但样本不完整,需要接线 http://j
我是一名优秀的程序员,十分优秀!