import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Test extends JFrame{
JLabel label = new JLabel("Leann will come again");
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("Yes");
JPanel panel = new JPanel();
public Test(){
panel.add(label);
panel.add(yesButton);
panel.add(noButton);
add(panel);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addAction();
}
public void addAction(){
yesButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "Are you sure?");
}
});
noButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "Too bad!");
}
});
}
public static void main(String args[]){
Test app = new Test();
}
}
当我在eclipse的ubuntu电脑上运行它时,它的停止(终止)没有任何错误。控制台中也没有错误。并没有语法错误。Java - 这个简单的程序有什么问题?
怎么了?是因为我运行openjdk吗?
1+为所有答案中最重要的信息:链接到教程。 –