输入并按下按钮后,JLabel的“结果”不会出现
public class qes{
static String special1;
public static void Count(double a, double b, double c) {
Double d = (b*b) - (4 * a * c);
Double temp = Math.sqrt(d);
Double res1 = (-b + temp)/(2*a);
Double res2 = (-b - temp)/(2*a);
String res = "x1 = " + res1 + " x2 = " + res2;
special1 = res;
}
public static void main(String[] args){
String path = "C:\\SPC\\res\\bckg.jpg";
String font = "Calibri";
String path1 = "C:\\SPC\\res\\close1.png";
int size = 24;
int size1 = 36;
JFrame wndw1 = new JFrame("Quadratic Equations Solver");
wndw1.setUndecorated(true);
wndw1.setExtendedState(JFrame.MAXIMIZED_BOTH);
wndw1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel bckg = new JLabel(new ImageIcon(path));
wndw1.setContentPane(bckg);
JTextField first = new JTextField();
first.setEditable(true);
first.setFont(new Font(font, Font.PLAIN, size));
first.setBounds(600, 400, 50, 50);
first.setVisible(true);
bckg.add(first);
JLabel txt1 = new JLabel("X\u00B2 +");
txt1.setFont(new Font(font, Font.PLAIN, size1));
txt1.setBounds(655, 400, 60, 50);
txt1.setVisible(true);
bckg.add(txt1);
JTextField second = new JTextField();
second.setEditable(true);
second.setFont(new Font(font, Font.PLAIN, size));
second.setBounds(720, 400, 50, 50);
second.setVisible(true);
bckg.add(second);
JLabel txt2 = new JLabel("X +");
txt2.setFont(new Font(font, Font.PLAIN, size1));
txt2.setBounds(775, 400, 50, 50);
txt2.setVisible(true);
bckg.add(txt2);
JTextField third = new JTextField();
third.setEditable(true);
third.setFont(new Font(font, Font.PLAIN, size));
third.setBounds(830, 400, 50, 50);
third.setVisible(true);
bckg.add(third);
JLabel txt3 = new JLabel("= 0");
txt3.setFont(new Font(font, Font.PLAIN, size1));
txt3.setBounds(885, 400, 50, 50);
txt3.setVisible(true);
bckg.add(txt3);
JButton but = new JButton("Calculate equation roots");
but.setFont(new Font(font, Font.PLAIN, size));
but.setBounds(620, 550, 280, 80);
but.setVisible(true);
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent f){
Double x = Double.parseDouble(first.getText());
Double y = Double.parseDouble(second.getText());
Double z = Double.parseDouble(third.getText());
qes.Count(x, y, z);
JLabel result = new JLabel(special1);
result.setFont(new Font(font, Font.PLAIN, size1));
result.setBounds(200, 700, 500, 100);
result.setForeground(Color.BLACK);
result.setVisible(true);
bckg.add(result);
}
});
bckg.add(but);
wndw1.setVisible(true);
}
}
我个人在这里看不到任何错误 而且我没有收到任何警告 也。我只填写 附言另外,当我尝试写那个:
if(x == null){
x = 1;
}
我收到警告,说这是无效代码
P.P.S。而且,我很乐意得到有关我的代码的任何建议
P.P.P.S我写了这一行和上一行,只是因为Stack Overflow不允许发布带有大量代码和少量文本的问题,我无话可说