forked from kishanrajput23/Programming-Resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJbtn_Shape.java
59 lines (50 loc) · 1 KB
/
Jbtn_Shape.java
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
53
54
55
56
57
58
59
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Jbtn_Shape1 extends JFrame implements ActionListener
{
JButton b1,b2;
Container con;
Jbtn_Shape1(String s)
{
super(s);
setSize(500,500);
con = getContentPane();
con.setLayout(new FlowLayout(FlowLayout.LEFT));
b1 = new JButton("Circle");
b1.addActionListener(this);
con.add(b1);
b2= new JButton("Rectangle");
b2.addActionListener(this);
con.add(b2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
Graphics g = getGraphics();
if(e.getActionCommand()=="Circle")
{
b1.setText("This is Circle");
g.drawOval(50,50,100,100);
}
else if(e.getActionCommand()=="Rectangle")
{
b2.setText("This is Rect");
g.drawRect(50,260,150,100);
}
}
}
class Jbtn_Shape
{
public static void main(String[] args)
{
Jbtn_Shape1 fb = new Jbtn_Shape1("Button Click");
fb.setVisible(true);
}
}