·  Chapter 29 Menus.

Slides:



Advertisements
Similar presentations
Gui Programming - II Teguh Sutanto, M.Kom.
Advertisements

Chapter 11 Creating User Interfaces F What is JavaBean? F JComponent F JButton  ImageIcon  JLabel  JTextField  JTextArea  JComboBox  JList  JCheckBox.
Graphical User Interfaces (Part IV)
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
1 lecture 14 GUI PROGRAMMING IVLecture 15 Graphical User Interfaces (cont.) Overview  GUI Programming (cont.)  Example 1: Creating Multi-layout GUIs.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Menus, Toolbars,
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
1 Chapter 23 Menus, Toolbars, Dialogs, and Internal Frames.
1 lecture 12Lecture 15 Graphical User Interfaces (cont.) Overview  GUI Programming (cont.)  Example 1: Creating Multi-layout GUIs with Tooltips.  Example.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
1 L47 Advanced GUI Component (2). 2 OBJECTIVES  To create and manipulate pop-up menus and windows.  To change the look-and-feel of a GUI, using Swing's.
1 L46 Advanced GUI Component (1). 2 OBJECTIVES  To create and manipulate sliders, and menus,
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Creating User Interfaces F JComponent F JButton F JLabel F JTextField F JTextArea F JComboBox F JList F JCheckBox F JRadioButton F Dialogs.
3-1 Composite Design Pattern Rick Mercer. 2 Composite Pattern Context : –Often complex structures are built with container and primitive objects. Container.
CS377A: A Programming Approach to HCI Jan Borchers Spring Swing Refresher David Merrill 5/14/2002
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved
CSE 219 Patterns in Programming More Design Patterns.
Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea.
Chapter 13 Creating User Interfaces F What is JavaBeans?  Component and JComponent F JButton  ImageIcon  JLabel  JTextField  JTextArea  JComboBox.
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent Jbutton Jbutton ImageIcon ImageIcon JLabel JLabel JTextField.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Next week: »No Lectures »No Labs »Recitation.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 34 Menus, Toolbars,
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
OOP (Java): GUI Intro/ OOP Objectives – –use an image viewer application to introduce Java's GUI features Semester 2,
IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.
AGDER COLLEGEFACULTY OF ENGINEERING & SCIENCE GUI Components ikt403 – Object-Oriented Software Development.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Y. Daniel Liang 1 Graphical User Interfaces Chapter 12.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
5-Jan-16 R Ramesh Swing. 5-Jan-16 R Ramesh An Introduction to Java Foundation Classes (JFC) A suite of libraries to assist programmers create enterprise.
The Swing GUI Components Chapter 29 An enhanced alternative to AWT The PC does not need an appletviewer or browser Swing overcomes some AWT drawbacks.
Software 3 See Edmodo for images Group name: topcat Group code: i4qf9a 11/03/11.
Chapter 11 Creating User Interfaces
Software Construction LAB 08 Java Programming with SWING GUI Builder.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
Lecture 08 Abstract Windows Toolkit (AWT) and Swing Jaeki Song.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Menus and Toolbars CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Jaeki Song JAVA Lecture 08 Abstract Windows Toolkit (AWT) and Swing Components.
Menus Pull-downs and popups. Tooltips –a ToolTip is a context-sensitive text string that is displayed in a popup window when the mouse rests over a particular.
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
제 14 장 고급 스윙 컴포넌트.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Chapter 9: Graphical User Interfaces
A First Look at GUI Applications Radio Buttons and Check Boxes
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Advanced User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interface
Zhen Jiang West Chester University
Advanced GUIs and Graphics
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

·  Chapter 29 Menus

Program MenuDemo GUI

Objectives · To create menus (§29.2). ·  To learn the menu components JMenuBar, JMenu, JPopupMenu, JMenuItem, JCheckBoxMenuItem, and JRadioButtonMenuItem (§29.2). ·  To create popup menus (§29.3). · 

Menus Java provides several classes—JMenuBar, JMenu, JMenuItem, JCheckBoxMenuItem, and JRadioButtonMenuItem —to implement menus in a frame. A JFrame or JApplet can hold a menu bar to which the pull-down menus are attached. Menus consist of menu items that the user can select (or toggle on or off). Menu bars can be viewed as a structure to support menus.

The JMenuBar Class Step 1: JFrame f = new JFrame(); A menu bar holds menus; the menu bar can only be added to a frame. Following is the code to create and add a JMenuBar to a frame: Step 1: JFrame f = new JFrame(); f.setSize(300, 200); f.setVisible(true); JMenuBar mb = new JMenuBar(); f.setJMenuBar(mb);//attach a menu bar to a //frame

The JMenu Class Step 2: You attach menus onto a JMenuBar. The following code creates two menus, File and Help, and adds JMenu fileMenu = new JMenu("File", false); JMenu helpMenu = new JMenu("Help", true); mb.add(fileMenu); mb.add(helpMenu);

The JMenuItem Class Step3: You add menu items on a menu. The following code adds menu items and item separators in menu fileMenu: fileMenu.add(new JMenuItem("new")); fileMenu.add(new JMenuItem("open")); fileMenu.addSeparator(); fileMenu.add(new JMenuItem("print")); fileMenu.add(new JMenuItem("exit"));

Submenus Step 3.1:You can add submenus into menu items. The following code adds the submenus “Unix,” “NT,” and “Win95” into the menu item “Software.” JMenu softwareHelpSubMenu = new JMenu("Software"); JMenu hardwareHelpSubMenu = new JMenu("Hardware"); helpMenu.add(softwareHelpSubMenu); helpMenu.add(hardwareHelpSubMenu); softwareHelpSubMenu.add(new JMenuItem("Unix")); softwareHelpSubMenu.add(new JMenuItem("NT")); softwareHelpSubMenu.add(new JMenuItem("Win95"));

Check Box Menu Items Step 3.2 helpMenu.add(new JCheckBoxMenuItem("Check it"));

Radio Button Menu Items Step 3.3: JMenu colorHelpSubMenu = new JMenu("Color"); helpMenu.add(colorHelpSubMenu);   JRadioButtonMenuItem jrbmiBlue, jrbmiYellow, jrbmiRed; colorHelpSubMenu.add(jrbmiBlue = new JRadioButtonMenuItem("Blue")); colorHelpSubMenu.add(jrbmiYellow = new JRadioButtonMenuItem("Yellow")); colorHelpSubMenu.add(jrbmiRed = new JRadioButtonMenuItem("Red")); ButtonGroup btg = new ButtonGroup(); btg.add(jrbmiBlue); btg.add(jrbmiYellow); btg.add(jrbmiRed);

Radio Button Menu Items JMenu colorHelpSubMenu = new JMenu("Color"); helpMenu.add(colorHelpSubMenu);   JRadioButtonMenuItem jrbmiBlue, jrbmiYellow, jrbmiRed; colorHelpSubMenu.add(jrbmiBlue = new JRadioButtonMenuItem("Blue")); colorHelpSubMenu.add(jrbmiYellow = new JRadioButtonMenuItem("Yellow")); colorHelpSubMenu.add(jrbmiRed = new JRadioButtonMenuItem("Red")); ButtonGroup btg = new ButtonGroup(); btg.add(jrbmiBlue); btg.add(jrbmiYellow); btg.add(jrbmiRed);

29.2.2Image Icons, Keyboard Mnemonics, and Keyboard Accelerators JMenuItem jmiNew, jmiOpen; fileMenu.add(jmiNew = new JMenuItem("New")); fileMenu.add(jmiOpen = new JMenuItem("Open")); jmiNew.setIcon(new ImageIcon("image/new.gif")); jmiOpen.setIcon(new ImageIcon("image/open.gif")); helpMenu.setMnemonic('H'); fileMenu.setMnemonic('F'); jmiNew.setMnemonic('N'); jmiOpen.setMnemonic('O'); jmiOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

29.2.3 Example: Using Menus Objective: Create a user interface that performs arithmetic. The interface contains labels and text fields for Number 1, Number 2, and Result. The Result box displays the result of the arithmetic operation between Number 1 and Number 2.

Example: Using Menus Problem: Create a user interface that performs arithmetic. The interface contains labels and text fields for Number 1, Number 2, and Result. The Result box displays the result of the arithmetic operation between Number 1 and Number 2. MenuDemo Run