Swing components not working
I am trying to implement an interface which responds to mouseclick and with buttons Circle, Rectangle and Quit. On pressing Circle a Circle is drawn on the frame and so on. I cant get this code to work. Your help would be much appreciated.
Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.util.EventListener;
import javax.swing.*;
interface ActionListener extends EventListener{
public void actionPerformed(ActionEvent ae);
}
public class india extends JFrame implements ActionListener {
JButton b1, b2, b3;
JLabel lbl;
String isCircle="N", isRectangle="N";
public india(String strname){
super(strname);
getContentPane().setLayout(new FlowLayout());
JPanel p = new JPanel();
b1 = new JButton("Rectangle");
b2 = new JButton("Circle");
b3 = new JButton("Quit");
p.setLayout(new FlowLayout());
p.add(b1);
p.add(b2);
p.add(b3);
getContentPane().add(p);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
String s = ae.getActionCommand();
if("Rectangle".equals(s)){
isRectangle = "Y";
repaint();
}
if("Circle".equals(s)){
isCircle = "Y";
repaint();
}
if("Quit".equals(s)){
System.exit(0);
}
}
public void paint(Graphics g){
if(isRectangle == "Y"){
g.drawRect(10, 10, 50, 50);
}
if(isCircle == "Y"){
g.drawOval(10, 10, 50, 50);
}
}
public static void main(String args[]){
india t = new india("Paint");
t.setSize(300, 300);
t.setVisible(true);
}
}