我已经在这上面工作了大约一个小时,现在试图让它工作,但无济于事。
我对Java相当陌生,这是我第一次使用JFrame
s,但由于某种原因,当我试图从另一个JFrame
初始化这个JFrame
时,它拒绝工作。
循序渐进:
NumberFormatExceptions
JFrame
对话框设置为可见JFrame
不出现
值得注意的是,对话框
JFrame
正在被另一个JFrame
StudentDetails
调用。
鼠标点击事件监听器代码:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int score1 = 0;
int score2 = 0;
int score3 = 0;
int score4 = 0;
int score5 = 0;
int score6 = 0;
dialogueBox db = new dialogueBox();
try {
score1 = Integer.parseInt(this.testScore1Input.getText());
score2 = Integer.parseInt(this.TestScore2Input.getText());
score3 = Integer.parseInt(this.testScore3Input.getText());
score4 = Integer.parseInt(this.testScore4Input.getText());
score5 = Integer.parseInt(this.testScore5Input.getText());
score6 = Integer.parseInt(this.testScore6Input.getText());
} catch (NumberFormatException numberFormatException) {
System.out.println(numberFormatException.toString());
db.setVisible(true);
}
int total = (score1 + score2 + score3 + score4 + score5 + score6);
float average = total / 6;
averageScoreOutput.setText(Float.toString(average));
}
我只是在寻找一些见解,为什么这不会工作,如果有人有使用JFrame
s时的最佳实践的任何提示。
如果有人有关于使用JFrames的最佳实践的建议。
应用程序应该只有一个JFrame。对于子窗口/弹出窗口,您应该使用JDialog
.
在您的情况下,您应该使用JOptionPane
,这是一个自定义的JDialog。
请阅读Swing教程中关于如何制作对话框的部分,以获取使用JOptionPane
的示例。