Action Event in Frame

// AcctionListener in swing frame:
import java.awt.event.*;
import javax.swing.*;

public class ActionListenerDemo extends JFrame 
{
	JButton b1, b2, b3;
	ActionListenerDemo() {
		super("nitin");
		setSize(300, 400);
		setVisible(true);
		getContentPane().setLayout(null);
		b1 = new JButton("SAVE");
		b2 = new JButton("Submit");
		b3 = new JButton("Cancel");
		b1.setBounds(50, 50, 100, 20);
		b2.setBounds(50, 80, 100, 20);
		b3.setBounds(50, 110, 100, 20);
		getContentPane().add(b1);
		getContentPane().add(b2);
		getContentPane().add(b3);
		ab ob = new ab();
		b1.addActionListener(ob);
		b2.addActionListener(ob);
		b3.addActionListener(ob);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	class ab implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent ae) {
			if (ae.getSource() == b1) {
				System.out.println(" u have clicked me");
			}
			if (ae.getSource() == b2) {
				System.out.println(" u have clicked me");
			}
			if (ae.getSource() == b3) {
				System.out.println(" u have clicked me");
			}
		}
	}
	public static void main(String a[])
	{
		ActionListenerDemo obj = new ActionListenerDemo();
	}
}

Download

Event handling in Java

Action Event with Menu Item
Action Event in Applet
Action Event
Adjustment Event
Focus Event
Item Event
Key Event
MOuse Event
Event with Timer
Window Event


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code