2015-09-07 11:44:36 -06:00
|
|
|
|
// ui/SimpleMenus.java
|
2015-11-14 16:18:05 -08:00
|
|
|
|
// <20>2016 MindView LLC: see Copyright.txt
|
2015-06-15 17:47:35 -07:00
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.*;
|
2015-11-11 20:20:04 -08:00
|
|
|
|
import static onjava.SwingConsole.*;
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
|
|
public class SimpleMenus extends JFrame {
|
|
|
|
|
private JTextField t = new JTextField(15);
|
|
|
|
|
private ActionListener al = e ->
|
|
|
|
|
t.setText(((JMenuItem)e.getSource()).getText());
|
|
|
|
|
private JMenu[] menus = {
|
|
|
|
|
new JMenu("Winken"), new JMenu("Blinken"),
|
|
|
|
|
new JMenu("Nod")
|
|
|
|
|
};
|
|
|
|
|
private JMenuItem[] items = {
|
|
|
|
|
new JMenuItem("Fee"), new JMenuItem("Fi"),
|
|
|
|
|
new JMenuItem("Fo"), new JMenuItem("Zip"),
|
|
|
|
|
new JMenuItem("Zap"), new JMenuItem("Zot"),
|
|
|
|
|
new JMenuItem("Olly"), new JMenuItem("Oxen"),
|
|
|
|
|
new JMenuItem("Free")
|
|
|
|
|
};
|
|
|
|
|
public SimpleMenus() {
|
|
|
|
|
for(int i = 0; i < items.length; i++) {
|
|
|
|
|
items[i].addActionListener(al);
|
|
|
|
|
menus[i % 3].add(items[i]);
|
|
|
|
|
}
|
|
|
|
|
JMenuBar mb = new JMenuBar();
|
|
|
|
|
for(JMenu jm : menus)
|
|
|
|
|
mb.add(jm);
|
|
|
|
|
setJMenuBar(mb);
|
|
|
|
|
setLayout(new FlowLayout());
|
|
|
|
|
add(t);
|
|
|
|
|
}
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
run(new SimpleMenus(), 200, 150);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
}
|