import j ava.awt.*;
import j ava.awt.event.*;
public class MenuScribble extends Frame{
public MenuScribble(String s) { super(s);
ScrollPane pane = new ScrollPane();
pane.setSize(300, 300);
add(pane, BorderLayout.CENTER);
Scribble scr = new Scribble(this, 500, 500);
pane.add(scr);
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu f = new Menu("Файл");
Menu v = new Menu("Вий");
mb.add(f);
mb.add(v);
Menuitem open = new Menuitem("Открыть...",
new MenuShortcut(KeyEvent.VK_0));
Menuitem save = new Menuitem("Сохранить",
new MenuShortcut(KeyEvent.VK_S));
Menuitem saveAs = new Menultera("Сохранить как...");
Menuitem exit = new Menuitem("Выход",
new MenuShortcut(KeyEvent.VK_Q));
f.add(open);
f.add(save);
f.add(saveAs);
f.addSeparator();
f.add(exit);
open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
FileDialog fd = new FileDialog(new Frame(),
" Загрузить", FileDialog.LOAD);
fd.setVisible(true);
}
});
saveAs.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
FileDialog fd = new FileDialog(new Frame(),
" Сохранить", FileDialog.SAVE);
fd.setVisible(true);
}
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
Menu с = new Menu("Цвет");
Menultem clear = new Menultem("Очистить",
new MenuShortcut(KeyEvent.VK_D));
v.add(c);
v.add(clear);
Menultem red = new Menultem("Красный");
Menultem green = new Menultem("Зеленый");
Menultem blue = new Menultem("Синий");
Menultem black = new Menultem("Черный");
c.add(red);
c.add(green);
c.add(blue);
c.add(black);
red.addActionListener(scr);
green.addActionListener(scr);
blue.addActionListener(scr) ;
black.addActionListener(scr) ;
clear.addActionListener(scr) ;
addWindowListener(new WinClose());
pack();
setVisible(true) ;
}
class WinClose extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public static void main(String[] args){
new MenuScribble(" \"Рисовалка\" с меню");
}
}