1 / 6

Creating Graphical User Interfaces

Creating Graphical User Interfaces. The JFrame class is the fundamental “window” class. It contains rudimentary functionalities to support features found in any frame window . A JFrame object serves as the “host” for containing other components,. JTextField. JLabel. JFrame. JButton.

fpettitt
Télécharger la présentation

Creating Graphical User Interfaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating Graphical User Interfaces SE-1020 Dr. Mark L. Hornick

  2. The JFrame class is the fundamental “window” class • It contains rudimentary functionalities to support features found in any frame window. • A JFrame object serves as the “host” for containing other components, JTextField JLabel JFrame JButton SE-1020 Dr. Mark L. Hornick

  3. Placing GUI components on a JFrame There are two ways to put GUI components on the content pane of a JFrame: • Absolute positioning • You explicitly specify the position and size of GUI objects within the content pane • Use a Layout manager • A class that controls automatic placement of components • There are many different Layout manager classes available SE-1020 Dr. Mark L. Hornick

  4. To place components within a JFrame window… • First, access the JFrame’s Container object (called the content pane) • the area of the frame excluding the title and menu bars and the border • this is the drawable area you can modify • The Container is accessed via the JFrame’s getContentPane() method: Container contentPane = jf.getContentPane(); • The Container has various properties (attributes) • background color can be changed by calling the Container’s setBackground() method. SE-1020 Dr. Mark L. Hornick

  5. Using Absolute Positioning • Set the layout manager of a JFrame’s Container to “none” by passing null to the setLayout() method: contentPane.setLayout(null); • Create a button (or other GUI component) and place it at the desired position and size by calling the button’s setBounds() method:JButton button = new JButton(); button.setBounds( 75, 125, 80, 30); // window coords • The first two arguments specify the button’s position in the JFrame • The last two arguments specify the width and height of the button. • To make a button appear on the JFrame, add it to the Container by calling the add() method.contentPane.add(okButton); SE-1020 Dr. Mark L. Hornick

  6. Exercise • Replicate the following UI using absolute positioning. JTextField JLabel JFrame JButton SE-1020 Dr. Mark L. Hornick

More Related