This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi all! What code should i write in the following program so that when the button is pressed the label changes to "Hello all !". I don't know how to write the action listeners.
import java.awt.*; import java.awt.event.*; public class hello1 {
Hi, Inside your main code after creating b you have two choices: 1. Use your class Hello1 to be the action listener:
Or you can use an anonymous class to perform the function: [CODE] public class Hello1 { public static void main( String[] args ) { ... Button b = new Button( "Hello" ); b.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { // Perform label change here ae.getSource().setLabel( "Changed" ); } }); } } [CODE] Good Luck, Manfred.