Graphical User Interface IST 311 MIS 307 GUI
- Slides: 21
Graphical User Interface IST 311 / MIS 307
GUI Feature Tool tip – text displayed on a component when mouse over the item. – May be used to describe the function JButton right. Button = new Jbutton(“Right”); right. Button. set. Tool. Tip. Text(“This is the Right button”);
GUI Feature Create borders around some objects – Titled border – creates a border that includes a title – Line border – creates a border around an object import javax. swing. border. *; panel 1. set. Border(new Titled. Border(“Three Buttons”);
JPanel Divide a window into subcontainers, create JPanel’s Jpanel’s may each contain their own layout JPanel main. Panel = new JPanel( ); main. Panel. set. Layout(new Grid. Layout(4, 3));
Item. Events
Basic GUI Item. Events – Menus, JCheckboxes, JRadio. Buttons, and other types of menus – Item events are handled by Item. Listener interface which has one method item. State. Changed( )
Basic GUI JCheckboxes – A button that can be selected and deselected – Always displays it current state – Generate Item. Events instead of Action. Events – Must have a corresponding Item. Listener – Objects which must be instantiated – Have corresponding labels
Basic GUI private JCheck. Box packages[ ] = new JCheck. Box[NTITLES]; private String package. Labels[ ] = {"Package A 12 - $42", "Package B 12 - $39", "Package C 12 - $34"}; for(int i = 0; i < packages. length; i++) { packages[i] = new JCheck. Box(package. Labels[i]); packages[i]. add. Item. Listener(this); choice. Panel. add(packages[i]); }
Basic GUI JRadio. Button – A button that belongs to a group of mutually exclusive alternatives; only one button may be selected at a time – Generate Item. Events and must have an Item. Listener – Set the first button “on” as the default option – Radio buttons must be added to a Button. Group to enforce mutual exclusion
Basic GUI private Button. Group opt. Group = new Button. Group(); private JRadio. Button options[ ] = new JRadio. Button[NOPTIONS]; private String option. Labels[ ] = {"Credit Card", "Check", "Cash"}; for(int i = 0; i < options. length; i++) { options[i] = new JRadio. Button(option. Labels[i]); options[i]. add. Item. Listener(this); option. Panel. add(options[i]); opt. Group. add(options[i]); } options[0]. set. Selected(true);
Basic GUI public void item. State. Changed(Item. Event e) { display. set. Text("Your order so far (Payment by: "); for(int i = 0; i < options. length; i++) { if (options[i]. is. Selected()) display. append(options[i]. get. Text() + ")n"); } for(int i = 0; i < packages. length; i++) { if (packages[i]. is. Selected()) display. append("t" + packages[i]. get. Text() + "n"); } }
Basic GUI Box. Layout Manager – Can be used with any container – One-dimensional grid layout – Multiple components can be arranged vertically or horizontally in a row – This layout will not wrap around – Does not force all components to be the same size – Uses set. Layout( ) method
Basic GUI option. Panel. set. Layout(new Box. Layout(option. Panel, Box. Layout. Y_AXIS)); Box. Layout( ) constructor has 2 parameters – First reference to container being managed – Second is constant to determine whether horizontal (X_AXIS) or vertical (Y_AXIS) alignment is used
Basic GUI Swing Borders – Border and Border. Factory classes – Used to put borders around GUI elements – Have titles, range of styles and colors – Attach a border to a component like a JPanel choice. Panel. set. Border (Border. Factory. create. Titled. Border("Packages")); – set. Border( ) method is defined in JComponent and inherited by all Swing components
Scrollbars on Text Area JText. Area display = new JText. Area(10, 20 ); get. Content. Pane( ). add(new JScroll. Pane(display));
Menus
Menus Three steps to create a menu: – Create the individual JMenu. Items – Create a JMenu and add the JMenu. Items to it – Create a JMenu. Bar and add the JMenu to it
Menus JMenu. Bar is a horizontal list of names that appears at the top of a window JMenu. Bar menu. Bar = new JMenu. Bar( ); JMenu is a clickable area on a menu bar that pops up and display the choices JMenu file. Menu = new JMenu(“File”);
Menus JMenu. Item is each item on a menu JMenu. Item clear. Menu = new JMenu. Item(“Clear”); JSeparators may be used to draw a horizontal line between items on a menu for groupings
Menus Mnemonic key may be created for each menu – Shortcut to opening a menu – Appears underlined as part of the menu caption – Press mnemonic key and Alt key simultaneously file. Menu. set. Mnemonic(‘F’);
Menus Menu item click events require an Action. Listener just like buttons use clear. Menu. add. Action. Listener(this); if(e. get. Source( ) == clear. Menu) …. .
- Components of graphical user interface
- Introduction of gui
- Graphical user interface testing
- Graphical user interface testing
- [web user interface]
- Java graphical user interface
- Characteristics of graphical user interface
- Guidelines for data entry screen design
- Graphical user interface history
- Interface history
- Graphical user interface in data structures
- Principles of user interface design
- Graphical user interface advantages and disadvantages
- Mis 307
- College of information sciences and technology
- Ist 311
- Ist 311
- Ist 311
- Ge gi gue gui güe güi
- Snort front end
- Graphics device interface
- Meterpreter gui