-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionTester1.java
More file actions
52 lines (44 loc) · 1.1 KB
/
ActionTester1.java
File metadata and controls
52 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ActionTester1 extends JFrame implements ActionListener
{
int clicked;
final String str="button is clicked=";
JButton b1,b2;
JLabel l1;
public ActionTester1()
{
getContentPane().setLayout(new FlowLayout());
//getContentPane() set before using swing and awt its very important without it object cannot displayed & add panel to it
JPanel p=new JPanel();
b1=new JButton("Clicked Here");
b2=new JButton("Quit");
p.setLayout(new FlowLayout());
p.add(b1);
p.add(b2);
getContentPane().add(p);
l1=new JLabel(str+clicked,JLabel.CENTER);
getContentPane().add(l1);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s2=e.getActionCommand();
System.out.println(s2);
if(s2.equals("Clicked Here"))
{
clicked++;
l1.setText(str+clicked);
}
else if(s2.equals("Quit"))
{
System.exit(0);
}
}
public static void main(String args[])
{
ActionTester1 t=new ActionTester1();
}
}