【发布时间】:2018-05-15 20:16:45
【问题描述】:
我正在尝试使用窗口生成器来编写这个简单的任务,但是,eclipse 总是说它错误并且不执行。请问这段代码有什么错误? *所有的包都是进口的。您好,我正在尝试使用窗口生成器来编写这个简单的任务,但是,eclipse 总是说它错误并且不执行。请问这段代码有什么错误? *所有的包都是进口的。
private JPanel contentPane;
private JTextField nota_periodo1;
private JTextField nota_periodo2;
private JTextField nota_periodo3;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ventana1 frame = new Ventana1();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @return
*/
public Ventana1() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(new Color(176, 224, 230));
contentPane.setForeground(new Color(176, 224, 230));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblCalculadoraDeNotas = new JLabel("CALCULADORA DE NOTAS SGS");
lblCalculadoraDeNotas.setBounds(146, 20, 200, 16);
contentPane.add(lblCalculadoraDeNotas);
JLabel lblNewLabel = new JLabel("Nota Periodo I:");
lblNewLabel.setBounds(20, 60, 104, 16);
contentPane.add(lblNewLabel);
nota_periodo1 = new JTextField();
nota_periodo1.setBounds(118, 55, 130, 26);
contentPane.add(nota_periodo1);
nota_periodo1.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("Nota Periodo 2:");
lblNewLabel_1.setBounds(20, 88, 104, 16);
contentPane.add(lblNewLabel_1);
JLabel lblNotaPeriodo = new JLabel("Nota Periodo 3:");
lblNotaPeriodo.setBounds(20, 113, 104, 16);
contentPane.add(lblNotaPeriodo);
nota_periodo2 = new JTextField();
nota_periodo2.setBounds(128, 83, 130, 26);
contentPane.add(nota_periodo2);
nota_periodo2.setColumns(10);
nota_periodo3 = new JTextField();
nota_periodo3.setBounds(118, 108, 130, 26);
contentPane.add(nota_periodo3);
nota_periodo3.setColumns(10);
// OBJETO DE INICIO
Ventana1 start = new Ventana1();
String principio = start.Inicio();
JButton calcular = new JButton("Calcular");
calcular.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(principio);
}
});
calcular.setBounds(40, 159, 104, 29);
contentPane.add(calcular);
JLabel lblUstedTieneQue = new JLabel("Usted Tiene que Sacar: ");
lblUstedTieneQue.setBounds(23, 200, 157, 16);
contentPane.add(lblUstedTieneQue);
JLabel nota_examen_final = new JLabel("");
nota_examen_final.setBounds(172, 200, 61, 16);
contentPane.add(nota_examen_final);
JLabel lblEnElExamen = new JLabel("en el Examen Final");
lblEnElExamen.setBounds(245, 200, 124, 16);
contentPane.add(lblEnElExamen);
}
//METODO INICIO
public String Inicio (){
int nota1 = Integer.parseInt(nota_periodo1.getText());
int nota2 = Integer.parseInt(nota_periodo2.getText());
int nota3 = Integer.parseInt(nota_periodo3.getText());
double nota1p = nota1*0.35;
double nota2p = nota2*0.25;
double nota3p = nota3*0.2;
double notapass = 60-(nota1p+nota2p+nota3p);
double notaex = notapass/0.2;
JOptionPane.showMessageDialog(null, notaex);
return null;
}
【问题讨论】:
-
鼓励问题提供Minimum Complete and Verifiable Example,尝试改进你的。该代码缺少导入语句,并且没有证据表明“eclipse 总是说错”是什么。
-
更多信息比一遍又一遍地复制你的一小部分文本来绕过内容要求更好。
标签: java jframe windowbuilder