【发布时间】:2015-03-10 00:48:16
【问题描述】:
我的程序有问题。这是我的代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;`
public class click_rep extends JFrame{`
public click_rep(){
super("CLICK");
final JButton btn1 = new JButton("CLICK HERE");
final JLabel label = new JLabel();
FlowLayout flo = new FlowLayout();
setLayout(flo);
add(btn1);
setSize(315,120);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
String command = e.getActionCommand();
if (command.equals(btn1)){
label.setText("CLICK");
setVisible(true);
}
}catch(Exception e1){
e1.printStackTrace();
}
}
});
}
public static void main(String[] a){
click_rep cp = new click_rep();
}
}
我的问题是 ActionEvent 不会出现。我该怎么做才能让 ActionEvent 出现?
希望有人可以帮助我。感谢您的帮助。
【问题讨论】:
标签: java swing awt actionevent