June 2017
Beginner
1296 pages
69h 23m
English
... colors = { "Blue", "Yellow", "Red" };
27
28 ButtonGroup colorGroup = new ButtonGroup(); // manages color items
29 popupMenu = new JPopupMenu(); // create pop-up menu
30 items = new JRadioButtonMenuItem[colors.length];
31
32 // construct menu item, add to pop-up menu, enable event handling
33 for (int count = 0 ; count < items.length; count++)
34 {
35 items[count] = new JRadioButtonMenuItem(colors[count]);
36 popupMenu.add(items[count]); // add item to pop-up menu
37 colorGroup.add(items[count]); // add item to button group
38 items[count].addActionListener(handler); // add handler
39 }
40
41 setBackground(Color.WHITE);
42
43 // declare a MouseListener for the window to display pop-up menu
44 addMouseListener(
45 new MouseAdapter() ...