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();
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 |