import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class menu extends JFrame implements ActionListener
{
JMenuBar mb;
JMenu draw;
JMenuItem rect,line,oval;
Container c;
menu()
{
c=getContentPane();
setLayout(null);
mb=new JMenuBar();
draw=new JMenu("Draw");
draw.setMnemonic('d');
mb.add(draw);
rect=new JMenuItem("Rect");
rect.addActionListener(this);
rect.setMnemonic('r');
draw.add(rect);
line=new JMenuItem("Line");
line.addActionListener(this);
line.setMnemonic('l');
draw.add(line);
oval=new JMenuItem("circle");
oval.addActionListener(this);
oval.setMnemonic('c');
draw.add(oval);
setJMenuBar(mb);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
Graphics g=getGraphics();
if(str=="Rect")
{
g.drawRect(100,100,50,50);
}
if(str=="Line")
{
g.drawLine(300,50,400,350);
}
if(str=="circle")
{
g.drawOval(400,50,50,50);
}
}
public static void main(String args[])
{
menu m=new menu();
m.setTitle("Application for Menu");
m.setVisible(true);
m.setSize(700,700);
}
}
No comments:
Post a Comment