添加注释后如下
public class ReportDialog extends JDialog implements ActionListener {
// 这是构造函数,基于一个父窗口弹窗
public ReportDialog(JFrame parent) {
super(parent, true);
// 自动缩放至最适合的大小
pack();
// 相对于父窗口的位置弹框
setLocationRelativeTo(parent);
// 给按钮设置点击事件
jButtion1.addActionListener(this);
// 设置弹框标题
setTitle("分数报告");
// 设置弹框大小
this.setSize(200,200);
// 显示弹框
this.show();
}
private void initComponents() {
// 创建一个Score对象
Score score = new Score();
// 创建一个面板,并且使用网格布局,这个网格是10行2列
jPanel1 = new JPanel(new GridLayout(10, 2));
for(int i=0; i<sName.length; i++) {
jLabel1 = new JLabel();
jLabel2 = new JLabel();
// 设置姓名
jLabel1.setText("" + sName[i]+":");
// 设置分数
jLabel2.setText("" + nScore[i]+":");
// 把姓名标签加到面板中
jPanel1.add(jLabel1);
// 把分数标签加到面板中
jPanel1.add(jLabel2);
}
jButton1 = new JButton("确定");
// 把积分面板添加到窗口的中间位置
getContentPane().add(jPanel1, BorderLayout.CENTER);
// 把按钮放到窗口的下面位置
getContentPane().add(jButton1, BorderLayout.CENTER);
}
}
如有帮助,请采纳,十分感谢!
把代码贴出来就好了,目前图片里的代码只是对界面做初始化而已,没有到关键位置,不知道你哪一段代码搞不懂