Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced GUIs II CS 102-02 Lecture 9-1 1.

Similar presentations


Presentation on theme: "Advanced GUIs II CS 102-02 Lecture 9-1 1."— Presentation transcript:

1 Advanced GUIs II CS Lecture 9-1 1

2 Agenda Scrollbars Frames and applications Popup menus Layout managers
CardLayout GridBagLayout

3 Scrollbars Use Scrollbars two ways:
Add scrollbars to components Use standalone as "sliders" Scrollbar objects are Components which implement Adjustable interface For objects with adjustable numeric value contained within a bounded range

4 What Scrollbars Need to Know
Minimum value Maximum Horizontal or vertical orientation Delta for blocks and units Proportion viewed at one time

5 Scrollbar Tips Visible amount scroll bar is portion of total visible at one time Scrollbar's value can't exceed max minus scroll box size: minimum <= adjustableValue <= maximum - visible

6 Frames Applets run within a host application Other Containers
Host provides the window Applets are Panels, which are Containers\ Other Containers ScrollPane Window Frame IS-A Window Frame = Window title + border

7 Frames are Handy to Have
Use Frames to build standalone GUI applications Applets can use Frames too (pops up a new window)

8 Frame Tips Frames don't display by default
Call the Frame object's setVisible() method with a true argument Frames don't have a default size Better call setSize() on the Frame object Default layout is BorderLayout Windows have events, which Frames inherit

9 Window Events Windows implement WindowListener
windowActivated(WindowEvent) Invoked when a window is activated. windowClosed(WindowEvent) Invoked when a window has been closed. windowClosing(WindowEvent) Invoked when a window is in the process of being closed. windowDeactivated(WindowEvent) Invoked when a window is de-activated. windowDeiconified(WindowEvent) Invoked when a window is de-iconified. windowIconified(WindowEvent) Invoked when a window is iconified. windowOpened(WindowEvent) Invoked when a window has been opened.

10 Double-Duty: Applets and Applications
Applications are similar to Applets, but have a main() method (like C & C++) Applications don't have a host window, so create one

11 Building Your Own Browser
Write an applet which has a main() main() creates a host window (a Frame) Invokes the Applet inside the newly created Frame

12 Example of Appletication
// Allow this applet to run as an application also public static void main( String args[] ) { // create application Frame and resize Frame app = new Frame( "Application" ); app.setSize( 300, 100 ); // register window handler to terminate application app.addWindowListener( new CloseWindowAndExit() ); // create applet instance MyFrame m = new MyFrame(); // initialize and start the applet m.init(); m.start(); // add applet to center of Frame app.add( m, BorderLayout.CENTER ); // display the frame (everything attached is painted) app.setVisible( true ); }

13 What's on the Menu? Applets don't have menus, because they don't have menu bars Frames can have menu bars Menus are: Good because they "clean up" the interface and unclutter it Bad because they often hide much functionality

14 Menus in Java Menu bar is the thingie that menus drop down from
Menu item is a string inside a menu that causes an action to be performed when selected Action or another menu

15 Frames and Menus in Action
Title bar MenuItem Menu Menubar

16 ScratchPad Application
Lets users type text and change font and color Prevent typing by choosing read-only

17 Dialogs Dialogs are Windows with titles
Common for passing information to user Two kinds Modal: Can't escape Non-modal (or modeless): Can be ignored

18 Popup Menus Popup menus can be attached to any Component (works for applets too!) Different platforms have different popup menu gestures When the AWT detects that a mouse event is the popup trigger event, it tags the event (remember MouseEvent.isPopupTrigger()?)

19 Layout Managers More layout managers
CardLayout: "Stacks" several layouts on top of one another GridBagLayout: Like GridLayout, but more flexible (read more complex)


Download ppt "Advanced GUIs II CS 102-02 Lecture 9-1 1."

Similar presentations


Ads by Google