我试图在框架内制作一个简单的按钮,但按钮图标未正确显示我的问题是为什么?2.) 为什么我们不能把
S 放在 SwingDemo() 或 public void actionPerformed(ActionEvent ae) 3.) 哪个语句使 edt 线程?请尽量用简单的语言解释,否则会产生更多的疑问。wingUtilities.invokeLater(new Runnable() {
public void run() {
new SwingDemo();
}
});
import javax.swing.*;
import java.awt.event.*;
class SwingDemo implements ActionListener {
SwingDemo() {
JFrame jfrm = new JFrame("A Simple Swing Application");
jfrm.setSize(275, 100);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jlab = new JButton(" Button ");
jfrm.add(jlab);
jfrm.setVisible(true);
}
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() { //2
public void run() {
new SwingDemo();
}
});
}
public void actionPerformed(ActionEvent ae) {
//jlab.setText("You selected " + ae.getActionCommand());
//showStatus("You selected " + ae.getActionCommand());
} }