lundi 9 mars 2015

ActionEvent won't appear



I have a problem in my program. Here's my code:


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();
}


}


My problem is that the ActionEvent won't appear. What will I do to make the ActionEvent appear? Hopefully someone can help me. Thanks for the help.




Aucun commentaire:

Enregistrer un commentaire