import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
[B]// Please give IDEA!!![/B]
public class MyQ3FrameTrials extends JFrame
{
JPanel p1, p2;
JCheckBox Face, Head, Tail, Body;
JButton Left, Right, Reset, Load, Save;
public MyFrameTrials()
{
setTitle("MyTrialsForLearningButtonComma…
setSize(600, 250);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
p1 = new JPanel();
p2 = new JPanel();
Face = new JCheckBox("String");
Head = new JCheckBox("Circle");
Tail = new JCheckBox("Line");
Body = new JCheckBox("Rectangle");
Left = new JButton("<< Move left");
Right = new JButton(">> Move right");
Reset = new JButton("Reset coordinates");
Load = new JButton("Load last saved coordinates");
Save = new JButton("Save current coordinates");
Container cp = getContentPane();
cp.add(p1, BorderLayout.WEST);
cp.add(p2, BorderLayout.SOUTH);
p1.setLayout(new GridLayout(5, 1));
p1.add(Face);
p1.add(Head);
p1.add(Tail);
p1.add(Body);
p2.setLayout(new GridLayout(2 ,3));
p2.add(Left);
p2.add(Right);
p2.add(Reset);
p2.add(Load);
p2.add(Save);
Face.addMouseListener(new ButtonWatcher());
Head.addMouseListener(new ButtonWatcher());
Tail.addMouseListener(new ButtonWatcher());
Body.addMouseListener(new ButtonWatcher());
Left.addMouseListener(new ButtonWatcher());
Right.addMouseListener(new ButtonWatcher());
Reset.addMouseListener(new ButtonWatcher());
Load.addMouseListener(new ButtonWatcher());
Save.addMouseListener(new ButtonWatcher());
}
public class ButtonWatcher extends MouseAdapter
{
public void mouseClick (MouseEvent e)
{
Object buttonPressed = e.getSource();
if (buttonPressed.equals(Left))
{
[B]// what to code here ... Please give IDEA![/B]
}
if (buttonPressed.equals(Right))
{
[B]// what to code here ... Please give IDEA![/B]
}
}
}
public void paint (Graphics g)
{
g.drawRect(140, 40, 440, 140);
g.setColor(Color.WHITE);
g.fill3DRect(140, 40, 440, 140, true);
g.setColor(Color.WHITE);
if(Head.isSelected())
{
g.setColor(Color.RED);
g.fillOval(250 ,85 ,40 ,25);
}
if(Tail.isSelected())
{
g.setColor(Color.RED);
g.drawLine(200, 100, 190, 75);
}
if(Body.isSelected())
{
g.setColor(Color.RED);
g.fillRect(200, 100, 60, 40);
}
if(Face.isSelected())
{
g.setColor(Color.BLACK);
g.setFont(new Font(" ",Font.BOLD, 20));
g.drawString("* --", 260, 105);
}
}
public static void main (String[] args)
{
MyFrameTrials f1 = new MyFrameTrials();
f1.paint(null);
}
}