import java.awt.*;
import java.awt.event.*;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Menu extends Frame{
private static Picture pic;
private static Button b1;
private Triangle triangle;
private static Button b2;
private Serpinsky s;
private static Button b3;
private Smiley sm;
private static Button b4;
private Rectangles r;
private static Button b5;
private MovePingPong mpp;
public Menu(String st,Triangle tri,Serpinsky s,Smiley sm,Rectangles r,MovePingPong mpp)
{
super(st);
this.setSize(800, 600);
this.addWindowListener(new ExitListener());
ButtonListener al=new ButtonListener();
b1=new Button("Traingle");
b1.setBackground(Color.gray);
b1.addActionListener(al);
b2=new Button("Serpinsky");
b2.setBackground(Color.gray);
b2.addActionListener(al);
b3=new Button("Smiley");
b3.setBackground(Color.gray);
b3.addActionListener(al);
b4=new Button("Rectangles");
b4.setBackground(Color.gray);
b4.addActionListener(al);
b5=new Button("Ping Pong ball");
b5.setBackground(Color.gray);
b5.addActionListener(al);
this.mpp=mpp;
this.sm=sm;
this.s=s;
this.triangle=tri;
this.r=r;
pic=new Picture(this.triangle,this.s,this.sm,this.r,this.mpp);
pic.setBackground(Color.LIGHT_GRAY);
pic.add(b1);
pic.add(b2);
pic.add(b3);
pic.add(b4);
pic.add(b5);
this.add(pic);
this.setFocusable(true);
this.setVisible(true);
}
public class ButtonListener implements ActionListener,KeyListener{
public ButtonListener(){
addKeyListener(this);
}
public void actionPerformed(ActionEvent e){
Button b=(Button)e.getSource();
Graphics g=pic.getGraphics();
if(b.equals(Menu.b1))
pic.paintFrameTraing(Menu.this.triangle, g);
if(b.equals(Menu.b2))
pic.paintFrameSerpinsky(Menu.this.s, g);
if(b.equals(Menu.b3))
pic.paintFrameSmiley(sm, g);
if(b.equals(Menu.b4))
pic.paintFrameRectangles(r, g);
if(b.equals(Menu.b5))
pic.paintFramePingPong(mpp, g);
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_RIGHT){
triangle.Move(10, 0);
repaint();
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
}
public class ExitListener extends WindowAdapter{
@Override
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public static void main(String[] args)
{
Triangle triangle=new Triangle(Color.black);
Serpinsky s=new Serpinsky();
Smiley sm=new Smiley();
Rectangles r=new Rectangles();
MovePingPong mpp=new MovePingPong(5);
new Menu("This is an Applicaion Biiaaaaacch!!",triangle,s,sm,r,mpp);
}
}