Swing |
As indicated in the textbook, adding graphic user interface (GUI) items to the screen is pretty easy. Here are the steps:
figureMenu = new JComboBox(); figureMenu.addItem("FramedSquare"); figureMenu.addItem("FramedCircle"); figureMenu.addItem("FilledSquare");
Container contentPane = getContentPane(); contentPane.add(figureMenu, BorderLayout.SOUTH); contentPane.add(colorMenu, BorderLayout.NORTH); contentPane.validate();
In Java 5 you may add the components directly to the WindowController rather than first getting the content pane and adding to it. Thus in Java 5 you can write:
this.add(figureMenu, BorderLayout.SOUTH); this.add(colorMenu, BorderLayout.NORTH); this.validate();or even omit the this altogether.
A simple example is the program ComboBoxDrawing, which is a variant of the drawing program from last time where the buttons created by drawing rectangles on the screen have been replaced by menus, which are objects from class JComboBox, from the package javax.swing.
Swing |