Tricky Tricks ›› Programming Tricks ›› Java Tricks ›› Better Buttons

Better Buttons

Java Programming Tricks

Better Buttons:

 Traditionally, implementing a button is done in two steps: 
 
 l. Add the button to the user interface in the constructor or init method 
 
 add(new JButton("Click me")); 
 
 2. Put the button action into the actionPerformed method 
 
 if (arg.equals("Click me")) ( /* button action goes here */ ) 
 
 This separates the button creation from the button action.
 

Partners