- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一个带有 GUI 的 Hangman 游戏,我想为其构建一个 jar。在 Netbeans 中,我转到“运行”>“清理并构建项目”,它似乎构建了 jar 得很好。然而,当我真正去运行这个 jar 时,它所做的只是在屏幕左上角打开一个小窗口,而不是我设计的 GUI。不过,当我在 Netbeans 中运行 GUI 时,它会按预期打开。此外,当我尝试关闭它打开的这个窗口时,它实际上并没有结束 java 进程 - 它会保持运行状态,直到我从任务管理器结束它。下面将提供图片和代码。
这就是我运行 jar 时打开的内容 - 一个空框架,里面什么也没有。
这是应该打开的内容,也是我从 Netbeans 内部运行项目时打开的内容。
我尝试通过命令提示符运行它,它以相同的方式运行,没有错误。这是我的代码:
HangmanGUI 类(主类):
package csci242.a03;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.io.FileNotFoundException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
public class HangmanGUI extends javax.swing.JFrame {
/**
* A hangman object used for the creation of the game
*/
protected Hangman hang;
/**
* A JLabel for displaying the text to label the currently guessed letters
*/
private javax.swing.JLabel guessedLettersInfo;
/**
* A JLabel for displaying the text to label the number of guesses remaining
*/
private javax.swing.JLabel guessesRemainingInfo;
/**
* A JLabel for displaying the text to label the current progress of the word
*/
private javax.swing.JLabel currentStateInfo;
/**
* A JLabel for displaying the text to label where to enter the next letter
*/
private javax.swing.JLabel enterLetterInfo;
/**
* A JLabel for displaying the text which says whether the user won or loss
*/
private javax.swing.JLabel winLabel;
/**
* A JLabel for displaying what the word was if the user lost
*/
private javax.swing.JLabel wordLabel;
/**
* A JButton for starting a new game
*/
private javax.swing.JButton newGameButton;
/**
* A JLabel for displaying what letters have been guessed
*/
private javax.swing.JLabel guessedLettersDisplay;
/**
* A JLabel for displaying the number of guesses remaining
*/
private javax.swing.JLabel guessesRemainingDisplay;
/**
* A JLabel for displaying the current progress of the word being sought
*/
private javax.swing.JLabel currentStateDisplay;
/**
* A JTextField to gather input for the next guess
*/
private javax.swing.JTextField guessTextField;
/**
* A JPanel to draw the hangman on
*/
private csci242.a03.HangmanPanel1 hangmanPanel1;
/**
* A JPanel used to separate the program into two halves for layout purposes
*/
private javax.swing.JPanel rightPanel;
/**
* A JPanel used to separate the program into two halves for layout purposes
*/
private javax.swing.JPanel leftPanel;
/**
* A JPanel used as a sub-container for JTextField
*/
private javax.swing.JPanel textFieldPanel;
/**
* A JPanel used as a sub-container for winLabel and wordLabel
*/
private javax.swing.JPanel winMessagePanel;
/**
* An empty panel to take up space in the gridLayout
*/
private javax.swing.JPanel emptyPanel1;
/**
* An empty panel to take up space in the gridLayout
*/
private javax.swing.JPanel emptyPanel2;
/**
* A JPanel used as a sub-container for buttonPanel
*/
private javax.swing.JPanel buttonPanel;
/**
* A constructor for creating a new HangmanGUI frame that will house the hangman game
*
*/
public HangmanGUI() {
try {
//Create a new hangman for the game
this.hang = new Hangman(new Lexicon("lexicon.txt"), 8);
//Initialize all GUI components for the game
initComponents();
//Share the hangman object with the hangmanPanel to help draw the hangman
hangmanPanel1.setHangman(hang);
}
catch (FileNotFoundException ex) {
}
}
/**
* This method initializes all of the components used for displaying the game such
* as the outer frame and any text/buttons/textFields.
*
*/
private void initComponents() {
//Set up the outer frame
setSize(1000,550);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set the frames layout to a GridLayout with 2 columns
setLayout(new GridLayout(0,2));
//Instantiate all of the components
guessedLettersInfo = new javax.swing.JLabel();
guessesRemainingInfo = new javax.swing.JLabel();
currentStateInfo = new javax.swing.JLabel();
enterLetterInfo = new javax.swing.JLabel();
winLabel = new javax.swing.JLabel();
winLabel.setVisible(false);
wordLabel = new javax.swing.JLabel();
wordLabel.setVisible(false);
newGameButton = new javax.swing.JButton();
guessedLettersDisplay = new javax.swing.JLabel();
guessesRemainingDisplay = new javax.swing.JLabel();
currentStateDisplay = new javax.swing.JLabel();
guessTextField = new javax.swing.JTextField();
hangmanPanel1 = new csci242.a03.HangmanPanel1();
rightPanel = new javax.swing.JPanel();
leftPanel = new javax.swing.JPanel();
textFieldPanel = new javax.swing.JPanel();
winMessagePanel = new javax.swing.JPanel();
emptyPanel1 = new javax.swing.JPanel();
emptyPanel2 = new javax.swing.JPanel();
buttonPanel = new javax.swing.JPanel();
//Add leftPanel and rightPanel and set each to take up half of the frame
add(leftPanel);
add(rightPanel);
leftPanel.setSize(700,225);
rightPanel.setSize(300,225);
//Set each panel's layout based on what will be inside of them
leftPanel.setLayout(new GridLayout(6,3));
rightPanel.setLayout(new GridBagLayout());
//Add guessedLettersInfo and guessedLettersDisplay to the left panel as well as set the text of each if needed
guessedLettersInfo.setText("Letters Guessed:");
leftPanel.add(guessedLettersInfo);
guessedLettersInfo.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
leftPanel.add(guessedLettersDisplay);
//Add guessesRemainingInfo and guessesRemainingDisplay to the left panel as well as set the text of each if needed
guessesRemainingInfo.setText("Guesses Remaining:");
leftPanel.add(guessesRemainingInfo);
guessesRemainingInfo.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
leftPanel.add(guessesRemainingDisplay);
//Add currentStateInfo and currentStateDisplay to the left panel as well as set the text of each if needed
currentStateInfo.setText("Current Word Progress:");
currentStateDisplay.setFont(new java.awt.Font("Tahoma", 0, 24));
leftPanel.add(currentStateInfo);
currentStateInfo.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
leftPanel.add(currentStateDisplay);
//Add enterLetterInfo to the left panel as well as set the text if needed
enterLetterInfo.setText("Enter a Letter:");
leftPanel.add(enterLetterInfo);
enterLetterInfo.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
//Set the layout of the textFieldPanel to position the textField that will be inside
textFieldPanel.setLayout(new GridBagLayout());
//Make a GridBagConstraints object for positioning the textField
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0,0,0,210);
guessTextField.setColumns(2);
//Add the textField to the panel then add the panel to the leftPanel
textFieldPanel.add(guessTextField, gbc);
leftPanel.add(textFieldPanel);
//Set the layout of the winMessagePanel to a GridLayout with 2 rows
winMessagePanel.setLayout(new GridLayout(2,0));
//Set the text of each label and add them to the winMessage Panel
winLabel.setText("Win message here");
winMessagePanel.add(winLabel);
winLabel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
wordLabel.setText("Word here");
winMessagePanel.add(wordLabel);
wordLabel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
//Add winMessagePanel to leftPanel
leftPanel.add(winMessagePanel);
//Add an emtpty panel to take up space
leftPanel.add(emptyPanel1);
//Set the layout of the buttonPanel, add newGameButton to the buttonPanel, and add buttonPanel to the leftPanel
buttonPanel.setLayout(new GridBagLayout());
newGameButton.setText("New Game");
buttonPanel.add(newGameButton);
leftPanel.add(buttonPanel);
//Add an empty panel to take up space
leftPanel.add(emptyPanel2);
//Set the insets for the hangmanPanel as well as the prefered/minimum size
gbc.insets = new Insets(0,0,-50,0);
hangmanPanel1.setPreferredSize(new Dimension(300,450));
hangmanPanel1.setMinimumSize(new Dimension(300,450));
//Add the hangmanPanel to the right Panel with the insets defined above
rightPanel.add(hangmanPanel1, gbc);
//Create a new action lister for the textField
guessTextField.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessTextFieldActionPerformed(evt);
}
});
//Create a new action lister for the new game button
newGameButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
newGameButtonActionPerformed(evt);
}
});
//Make the frame visible
setVisible(true);
}
/**
* This method updates the game when a user enters something in the text field.
* The display is also updated.
*
* @param evt An event passed into the action listener
*/
private void guessTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
char guess; //Make a character to hold the guess
if (!(hang.gameOver())) {
try {
//Grab the first character of whatever is entered in the textField and assign it to guess
guess = Character.toUpperCase(guessTextField.getText().charAt(0));
//Update the game
hang.update(guess);
//Update the display
updateDisplay();
//Set the textField to be empty again
guessTextField.setText("");
}
catch (StringIndexOutOfBoundsException ex) {
guessTextField.setText("");
}
}
//Repaint the hangman
hangmanPanel1.repaint();
}
/**
* This method creates a new hangman game when the hangman button is pressed
* and updates the game/display along with it.
*
* @param evt An event passed into the action listener
*/
private void newGameButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
//Make a new hangman
hang = new Hangman(new Lexicon("lexicon.txt"), 8);
//Share the new hangman with the hangmanPanel
hangmanPanel1.setHangman(hang);
guessTextField.setText("");
//Make a new character set to null used for setting up the next game
char guess = '\u0000';
//Update the game
hang.update(guess);
//Update the display for the new game
updateDisplay();
}
catch (FileNotFoundException ex) {
}
//Repaint the hangman to restart the game
hangmanPanel1.repaint();
}
/**
* This method updates the display to display the guessedLetters, guesses
* remaining, and currentState in the game. In addition to that, it also
* displays a message if the user has won or lost the game.
*
*/
public void updateDisplay() {
winLabel.setVisible(false);
wordLabel.setVisible(false);
//Update the values for guessedLetters, guessesRemaining, and currentState
guessedLettersDisplay.setText(hang.getGuessedLetters().toString());
guessesRemainingDisplay.setText(Integer.toString(hang.getIncorrectGuessesRemaining()));
currentStateDisplay.setText(hang.getCurrentState());
//Create new font objects
Font winFont = winLabel.getFont();
Font wordFont = wordLabel.getFont();
//Create a new color - the Color.GREEN is too flourescent/bright - this one shows up better in the frame
Color darkGreen = new Color(0,100,0);
//Checks to how the game is over if it has ended and displays the appropriate message
if (hang.incorrectGuesses >= hang.allowedGuesses) {
winLabel.setText("You have run out of guesses!");
winLabel.setForeground(Color.red);
winLabel.setFont(new Font(winFont.getFontName(), Font.BOLD, winFont.getSize()));
winLabel.setVisible(true);
wordLabel.setText("The word was: " + hang.getWord());
wordLabel.setFont(new Font(wordFont.getFontName(), Font.BOLD, wordFont.getSize()));
wordLabel.setVisible(true);
} else if (hang.currentState.equalsIgnoreCase(hang.getWord())){
winLabel.setText("You win!");
winLabel.setForeground(darkGreen);
winLabel.setFont(new Font(winFont.getFontName(), Font.BOLD, winFont.getSize()));
winLabel.setVisible(true);
}
}
/**
*
* @param args
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(HangmanGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(HangmanGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(HangmanGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(HangmanGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new HangmanGUI().setVisible(true);
}
});
}
}
绘制刽子手的面板:
package csci242.a03;
import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
public class HangmanPanel1 extends javax.swing.JPanel {
/**
* A hangman object used for the drawing of the hangman
*
*/
protected Hangman hang;
/**
* A constructor for creating a panel that will house the hangman and gallows
*
*/
public HangmanPanel1() {
initComponents();
}
/**
* This method sets the Hangman instance variable to a new value.
*
* @param hang A new hangman object
*/
public void setHangman(Hangman hang) {
this.hang = hang;
}
/**
* This method draws the gallows for the hangman as well as the head,
* arms, legs, and feet depending on the number of incorrect guesses that
* have been made.
*
* @param g A graphics object
*/
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (this.hang != null) {
if (hang.getIncorrectGuessesMade() >= 0) {
//Draw the gallows
Graphics2D g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(9));
g2.draw(new Line2D.Float(0,0,0,450));
g2.draw(new Line2D.Float(0,0,150,0));
g2.setStroke(new BasicStroke(5));
g2.draw(new Line2D.Float(152,0,152,50));
g2.draw(new Line2D.Float(0,350,450,350));
g2.draw(new Line2D.Float(150,350,150,450));
g2.draw(new Line2D.Float(297,350,297,450));
g2.draw(new Line2D.Float(0,350,150,450));
g2.draw(new Line2D.Float(150,351,297,450));
g2.draw(new Line2D.Float(150,351,0,450));
g2.draw(new Line2D.Float(150,450,300,350));
g2.setStroke(new BasicStroke(1));
//Draw the head/face if there is 1 incorrect guess
if (hang.getIncorrectGuessesMade() >= 1) {
g.drawOval(127,51,50,50);
g.fillOval(137,61,10,10);
g.fillOval(157,61,10,10);
g.drawLine(137, 81, 167, 81);
//Draw the torso if there are 2 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 2) {
g.drawRoundRect(127,101,50,100,30,30);
//Draw the left arm if there are 3 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 3) {
g.drawLine(127, 110, 100, 175);
//Draw the right arm if there are 4 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 4) {
g.drawLine(177, 110, 205, 175);
//Draw the left leg if there are 5 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 5) {
g.drawLine(127, 190, 127, 270);
//Draw the right leg if there are 6 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 6) {
g.drawLine(177, 190, 177, 270);
//Draw the left foot if there are 7 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 7) {
g.drawRoundRect(100,268,27,10,10,10);
//Draw the right foot if there are 8 incorrect guesses
if (hang.getIncorrectGuessesMade() >= 8) {
g.drawRoundRect(177,268,27,10,10,10);
}
}
}
}
}
}
}
}
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
// Variables declaration - do not modify
// End of variables declaration
}
还有另外两个类可以解决这个问题,但我认为它们不会造成问题。由于 30,000 字符的限制,我也无法在 OP 中发帖。感谢您的帮助。
最佳答案
尝试减少您提交的内容,遗憾的是没有人愿意筛选您的代码,因此您得不到答案
关于java - Netbeans JAR 未正常运行/打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29571707/
自从我 faced an issue由于背景图片对于不同分辨率的内容来说太短,我尝试将背景分成 3 部分并自动拉伸(stretch)中间部分以相应地填充顶部和底部图像之间的空间。不幸的是我没能在 CS
我从去年开始就在我的程序中运行这个函数(Linux 和 Windows)。 现在我需要实现一个新功能,我的新构建不再运行。 我还有其他使用 POST 的 CUrl 函数,结果是一样的:没问题,但我的
在评估函数应用方面,Haskell 是只支持普通降阶还是也支持应用降阶?我是否认为正常顺序是 Haskell 惰性的原因? 最佳答案 GHC 运行时不使用术语缩减策略,因为那会非常低效。事实上,GHC
怎么来的multi使用多处理池对多个“进程”上的数据进行分段和处理的函数比仅调用 map 慢(8 秒)。功能(6 秒)? from multiprocessing import Pool import
假设我正在渲染一个 3d GL_TRIANGLE。该对象需要 3 个顶点才能定义:A、B、C。我将此类数据放入缓冲区并通过 glVertexAttribPointer 将其绑定(bind)到着色器。
我有一个字体的三个文件,普通的,粗体的和浅色的。由于 font-weight:light 不存在,我该如何在 font-face 上设置 light 呢? 顺便问一下,font-weight:ligh
我是 C 的新手,我似乎无法弄清楚什么似乎是一个非常简单的指针问题。我的程序将行号添加到文件中。它逐行读入文件,然后在每行的开头添加一个行号。它在每个文件上都可以正常工作,如下所示: soccer@s
我有以下代码,我不确定为什么当它命中 Myclass 的析构函数时我会收到堆损坏检测错误。我相信我正在正确地释放内存?? #include #include using namespace std
有什么方法可以将“正常”数学符号解释为逆波兰符号 (RPN)..? 例如1) 2 + 3*4 - 1 = 234*+1-2) 5 (4-8) = 548- 你可以假设遵循 BODMAS 规则并且必须首
http://www.ergotopia.de/ergonomie-shop/ergonomische-kissen/orthopaedisches-sitzkissen的手机页面应该看起来像右边(检
我正在 Phonegap/Cordova 中构建一个应用程序。应用目前相当简单,但确实需要网络状态和地理定位插件才能工作。 到目前为止,我已经在 Android 上开发了该应用程序(目前它仅由一些基本
我一整天都在做这个,但没有运气 我设法在一行 TfidfVectorizer 中消除了问题 这是我的工作代码 from sklearn.feature_extraction.text import C
也许有人看到一个错误,问题是当我按btn2 (button 2)和btn3 (button 3)应用程序crashes时,但操作仍然有效,即video正在运行并且PDF打开,而button 1正常工作
我正在开发一个应用程序。它的第一页是登录屏幕。成功登录后,我想将用户带到选项卡式 Activity 。我怎样才能在安卓中做到这一点?谢谢 最佳答案 在 Android 中,启动 Activity 是通
我不确定我在这里做错了什么。 :normal! I### 当我对一个单词执行此命令时,我想要的最终结果是: ### word 但是我得到了这个: ###word 最佳答案 Vim 的 :normal是
我必须将 2 个静态矩阵发送到分配动态矩阵的函数,将矩阵 1 乘以矩阵 2,并返回新矩阵的地址。请注意,COMM 很常见。 我尝试删除 free_matrix 行,它工作正常。 void main()
我在我的一个项目中使用 Gnome libglib 并遇到了一个奇怪的错误。我可以输入 GList 的元素数量看起来仅限于 45 个。在第 45 个元素处,它给出了此错误 40 counter 41
我正在尝试获取“顶级”HWND 的尺寸。即,我想要 Firefox/Windows 资源管理器等的主 HWND 的当前尺寸。窗口。如果窗口最小化, GetWindowRect() 将不起作用。 Get
相同的标题:什么是索引 - 正常 - 全文 - 唯一? 最佳答案 普通索引用于通过仅包含行数据的切片或散列来加速操作。 全文索引向数据库的全文搜索 (FTS) 引擎指示它应该将数据存档在给定字段中,以
我正在使用 EnumParser来自 here它在 VC++ 中编译得很好,但是使用 gcc 我有这样的错误: ./Terminator.o: In function `EnumParser::Enu
我是一名优秀的程序员,十分优秀!