It places five components in the five possible areas

This preview shows page 1 - 2 out of 2 pages.

It places five components in the five possible areas: (1) a JButton in the east, (2) a JLabel in the west, (3) a JLabel in the south, (4) a JTextField in the north, and (5) a JTextArea in the center. */ public class ComponentExample extends JFrame { /** Constructor: a window with title t and 5 components */ public ComponentExample(String t) { super (t); Container cp= getContentPane(); cp.add( new JButton("click me"), BorderLayout.EAST); cp.add( new JTextField("type here", 22), BorderLayout.NORTH); cp.add( new JCheckBox("I voted today"), BorderLayout.SOUTH); cp.add( new JLabel("label 2"), BorderLayout.WEST); cp.add( new JTextArea("type\nhere", 4, 10), BorderLayout.CENTER); pack(); } 4 What components can go in a JFrame Packages that contain classes that deal with GUIs: java.awt: Old package. javax.swing: New package. Javax.swing has a better way of listening to buttons, text fields, etc. Its components are more flexible. JButton , Button : Clickable button JLabel , Label : Line of text JTextField , TextField : Field into which the user can type: JTextArea , TextArea : Many-row field into which user can type JPanel , Panel : Used for graphics; to contain other components JCheckBox : Checkable box with a title JComboBox : Menu of items, one of which can be checked JRadioButton : Same functionality as JCheckBox Container : Can contain other components Box: Can contain other components Component : Something that can be placed in a GUI window. They are instances of certain classes, e.g. 5 Basic Components Component Button, Canvas Checkbox, Choice Label, List, Scrollbar TextComponent TextField, TextArea Container JComponent AbstractButton JButton JToggleButton JCheckBox RadioButton JLabel, JList JOptionPane, JPanel JPopupMenu, JScrollBar, JSlider JTextComponent JTextField, JTextArea Component : Something that can be placed in a GUI window. These are the basic ones that one uses in a GUI Note the use of subclasses to provide structure and efficiency. For example, there are two kinds of JToggleButtons, so that class has two subclasses.
Image of page 1

Subscribe to view the full document.

Image of page 2
You've reached the end of this preview.
  • Spring '07
  • DAVIDGRIES

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern