COMP2396
Loading...
Searching...
No Matches
SimpleMenu.java
Go to the documentation of this file.
1import javax.swing.*;
2import java.awt.event.*;
3
4public class SimpleMenu implements ActionListener {
5 JTextArea text;
6
7 public static void main(String[] args) {
8 SimpleMenu simpleMenu = new SimpleMenu();
9 simpleMenu.go();
10 }
11
12 public void go() {
13 JFrame frame = new JFrame();
14 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15
16 JMenuBar menuBar = new JMenuBar();
17 JMenu menu = new JMenu("Menu A");
18
19 JMenuItem menuItem = new JMenuItem("Item");
20 menuItem.addActionListener(this);
21 menu.add(menuItem);
22 menuBar.add(menu);
23 frame.setJMenuBar(menuBar);
24
25 text = new JTextArea();
26 text.setLineWrap(true);
27
28 JScrollPane scroller = new JScrollPane(text);
29 scroller.setVerticalScrollBarPolicy(
30 ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
31 scroller.setHorizontalScrollBarPolicy(
32 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
33 frame.add(scroller);
34
35 frame.setSize(350, 300);
36 frame.setVisible(true);
37 }
38
39 public void actionPerformed(ActionEvent event) {
40 text.append("Menu item selected\n");
41 }
42}
static void main(String[] args)
void actionPerformed(ActionEvent event)