這裏是我的源代碼:
主類:
Eclipse不啓動我的程序,但沒有錯誤
package daPackage;
import javax.swing.JFrame;
class apples{
public static void main(String args[]){
Gui go = new Gui();
setUpGUI(go);
}
private static void setUpGUI(Gui g){
g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
g.setVisible(true);
g.setSize(375, 175);
}
}
這裏是我的第二類:
package daPackage;
import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;
import javax.swing.event.*;
public class Gui extends JFrame{
private JButton button;
private JTextField field1;
private JTextField field2;
private JTextField field3;
private int num1;
private int num2;
private int num3;
public Gui(){
super("Testing!");
setLayout(new FlowLayout());
field1 = new JTextField("" + num1);
num1 = Integer.parseInt(field2.getText()) + Integer.parseInt(field3.getText());
add(field1);
field2 = new JTextField("" + num2);
num2 = Integer.parseInt(field1.getText()) + Integer.parseInt(field3.getText());
add(field2);
field3 = new JTextField("" + num3);
num3 = Integer.parseInt(field1.getText()) + Integer.parseInt(field2.getText());
add(field3);
button = new JButton();
button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
field1.setText("" + num1);
field2.setText("" + num2);
field3.setText("" + num3);
}
}
);
add(button);
}
}
Eclipse中說:沒有錯誤,但是當我點擊運行按鈕沒有任何反應。我檢查了我的代碼幾次,但我找不到問題。
刷新您的項目一次。 –