forked from Ashish8104/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonClickDemo.java
More file actions
38 lines (36 loc) · 801 Bytes
/
ButtonClickDemo.java
File metadata and controls
38 lines (36 loc) · 801 Bytes
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
import java.awt.*;
import java.awt.event.*;
class ButtonClickDemo extends Frame implements ActionListener
{
Button cb;
public ButtonClickDemo()
{
cb= new Button("Bharat");
cb.addActionListener(this);
cb.setBackground(Color.pink);
cb.setForeground(Color.blue);
cb.setFont(new Font("Arial",Font.BOLD,16));
add(cb,"Center");
setSize(300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals("Bharat"))
cb.setLabel("India");
else if(str.equals("India"))
cb.setLabel("Bharat");
String str1=cb.getLabel();
System.out.println("you clicked"+str1);
}
public static void main(String args[])
{
new ButtonClickDemo();
}
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals("Bharat"))
cb.setLabel("India");