Swing Components III Chapter 12 - Student JFrame, Component Methods.

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

Swing! Components and Images. Example Swing Components (also called “widgets”) Graphic from sun.com.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
F27SB2 Programming Languages
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Lecture 16: GUI programming JFrame windows (p.247) Containers and layout managers (p.290) Inheriting GUI components (p.330) Chapter 12: GUI programming.
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
Swinging Into Swing Leo S. Primero III. Understanding what Swing Is Swing is a package that lets you create applications that use a flashy Graphical User.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Chapter 8: Graphical User Interfaces Objectives - by the end of this chapter, you should be able to do the following: –write a simple graphical user interface.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Programming With Java ICS201 University Of Ha’il1 Chapter 17 Graphical User Interfaces Swing I.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Introduction to Java Applet Programs Section 1.3Intro. to Java Applet Programs: a Greeter Applet Section 3.7Graphical/Internet Java: Applet: An Einstein.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
(c)2009 by E.S. Boese. All Rights Reserved. Classes Chapter 13 – Lecture Slides 1 Got class?
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Programming with Java’s Swing API February 4, 2003 CMPS Advanced Programming Graphical User Interfaces.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Graphical User Interfaces. Graphical input and output with JOptionPane.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
TCU CoSc Programming with Java The JFrame Class.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Dale Roberts GUI Programming using Java - Windowing Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
Graphical User Interfaces
Graphical User Interfaces -- GUIs
Java Swing.
Graphical User Interface (pronounced "gooey")
Chapter 11 JTabbedPane, ToolTips, Borders, Audio, JFrame, MediaTracker
Chapter 13: Advanced GUIs and Graphics
GUIS: Graphical User Interfaces
AWT Components and Containers
IFS410: Advanced Analysis and Design
Steps to Creating a GUI Interface
Advanced GUIs and Graphics
13 April 2010 GUIS: Graphical User Interfaces
Graphical User Interface
Presentation transcript:

Swing Components III Chapter 12 - Student JFrame, Component Methods

JFrame windows

(c) 2005 by Elizabeth Sugar Boese Window Mostly used for ____________ Generic type that _______ and Dialog inherit 3 important methods :  dispose() – eliminate ___________ when done  pack() – __________ to fit added components  setVisible(boolean) – make the window appear

(c) 2005 by Elizabeth Sugar Boese JFrame Uses ____________ by default Possible ornaments:  Title  ____________  Menu  ____________  Widgets to hide/minimize/grow Methods:  Constructors: JFrame() JFrame( String title)  setBounds( w, h )  setSize( w, h )

(c) 2005 by Elizabeth Sugar Boese JFrame Create a JFrame window JFrame frame; frame = new JFrame( text ); Set the ____________ on the screen (optional) frame.setLocation( 500, 600 ); Major Steps 1. ______________________. JFrame frame;frame = new JFrame("FrameDemo"); 2. Set ________________ frame.setLayout( new BorderLayout( ) ); 3. Create components and _________________________ JButton go = new JButton( "Go for it!" ); frame.add(universe, BorderLayout.SOUTH); 4. _________ the frame. frame.pack(); ORframe.setSize( 200, 500 ); 5. Show it. frame.setVisible(true); text is the title on the JFrame Calling the.pack( ) method will size the frame based on the minimum size to fit all the components added to the frame.

(c) 2005 by Elizabeth Sugar Boese JFrame – Simple Example import javax.swing.*; public class JFrameDefault extends JApplet { JFrame frame; public void init( ) { frame = new JFrame( "Testing JFrame stuff" ); frame.setSize( 200,100 ); frame.setVisible( true ); }

(c) 2005 by Elizabeth Sugar Boese JFrame – Example with components import java.awt.*; import javax.swing.*; public class JFrameStuff extends JApplet { JFrame frame; JLabel myname, universe; JButton go, skiing; public void init( ) { //1. Create the frame. frame = new JFrame("FrameDemo"); //2. Set layout manager frame.setLayout( new BorderLayout( ) ); //3. Create components and put them in the frame. myname = new JLabel( " My Stuff", JLabel.CENTER ); go = new JButton( "Go for it!" ); skiing = new JButton( "Do you like skiing too?" ); universe = new JLabel( "I live at the borders of the universe where fact and fiction collide" ); frame.add(myname, BorderLayout.NORTH); frame.add(go, BorderLayout.WEST); frame.add(skiing, BorderLayout.EAST); frame.add(universe, BorderLayout.SOUTH); //4. Size the frame. frame.pack( ); //5. Show it. frame.setVisible(true); }

(c) 2005 by Elizabeth Sugar Boese JFrame Closing Behaviors When user selects window manager Close option for JFrame, has default behavior  JFrame did nothing  JFrame hides itself setDefaultCloseOperation (operation)  DO_NOTHING_ON_CLOSE  HIDE_ON_CLOSE  DISPOSE_ON_CLOSE  No EXIT_ON_CLOSE operation

(c) 2005 by Elizabeth Sugar Boese JFrame - Events usually want to pop open a JFrame based on an event (e.g. a button click) Example

Dialogs (extra material)

(c) 2005 by Elizabeth Sugar Boese JOptionPane Examples

(c) 2005 by Elizabeth Sugar Boese Dialog For simple _______________ with user Uses _______________ by default Are _____ by default (can change to modeless setModal(false) Constructors:  Dialog( Frame parent )  Dialog( Frame parent, String title )  Dialog( Frame parent, boolean isModal ) Call to super( )

(c) 2005 by Elizabeth Sugar Boese Dialog Example Frame frame = new Frame( ); Dialog d = new Dialog( frame, “Hi there”, true ); JButton button = new JButton( “Okay?” ); JPanel panel = new JPanel(); p.add( button ); d.add( panel ); d.setSize( 400,100 ); d.setVisible( true );

Menu (extra material)

(c) 2005 by Elizabeth Sugar Boese Menu MenuBar  Collection of Menus  Associated with a Frame Menu  Collection of MenuItems and separators  Can be a MenuItem for hierarchical menus MenuItem  Enabled or disabled  May be checkable

Component Methods

(c) 2005 by Elizabeth Sugar Boese Component Methods Common methods works on most components (e.g. JLabel, JButton, JPanel, etc.)  setBackground ( Color )  setForeground ( Color )  setBorder ( Border )  setFont ( Font )  setToolTipText( String )  setVisible ( boolean )

(c) 2005 by Elizabeth Sugar Boese Component Methods - JButton JButton  addActionListener ( this )  setBorderPainted ( boolean )  setContentAreaFilled ( boolean )  setDisabledIcon ( ImageIcon )  setIcon ( ImageIcon )  setHorizontalAlignment ( int )  setHorizontalTextPosition ( int )  setRolloverIcon ( ImageIcon )  setText ( String ) Parameter int one of: JButton.LEFT JButton.CENTER JButton.RIGHT

(c) 2005 by Elizabeth Sugar Boese Component Methods – JCheckbox, JRadioButton JCheckbox and JRadioButton  addItemListener ( this )  isSelected ( ) Returns true if currently selected, false if not selected

(c) 2005 by Elizabeth Sugar Boese Component Methods - JLabel JLabel  setIcon ( ImageIcon )  setText ( String )

(c) 2005 by Elizabeth Sugar Boese Component Methods - text JTextField  getText ( )  setText ( ) JTextArea  append ( String )  getText ( )  setLineWrap ( boolean )  setText ( String )  setWrapStyleWord ( boolean )

(c) 2005 by Elizabeth Sugar Boese Summary JFrame Dialogs Menu Component methods