how to use button handler in java?

If you search the net with: "ActionListener" you will receive plenty of examples:
http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html
I took an example from that page and modified it to be more simple for you:

import javax.swing.*;
import java.awt.event.*;

public class AL extends JFrame implements [B]ActionListener[/B] {
	JTextField text = new JTextField(20);
	[B]JButton b = new JButton("Click me");[/B]
    JPanel panel= new JPanel();
    
	private int numClicks = 0;

	public static void main(String[] args) {
		AL myWindow = new AL("My first window");
		myWindow.setSize(350,100);
		myWindow.setVisible(true);
	}

	public AL(String title) {
		super(title);

        panel.add([B]b[/B]);
        [B]b[/B].addActionListener([B]this[/B]);

        panel.add(text);

        add(panel);
	}

	public void [B]actionPerformed[/B](ActionEvent e) {
                // For debugging purposes. Just to show how you can find which button was clicked in case you have more than one.
                /*
                Object source = e.getSource();
                if (source==b) {
                    System.out.println("The button b was clicked: "+source);
                }
                */
		numClicks++;
		text.setText("Button Clicked " + numClicks + " times");
	}
}

Check the API for the interface: ActionListener.
Then search the sun tutorials for creating swing guis

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.