OnJava8-Examples/gui/SimpleMenus.java

38 lines
1.0 KiB
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: gui/SimpleMenus.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import static net.mindview.util.SwingConsole.*;
public class SimpleMenus extends JFrame {
private JTextField t = new JTextField(15);
2015-05-06 12:09:38 -07:00
private ActionListener al = e ->
2015-05-05 14:05:39 -07:00
t.setText(((JMenuItem)e.getSource()).getText());
2015-04-20 15:36:01 -07:00
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);
}
} ///:~