Chapter 14. More Swing
|
|
- Shanon Butler
- 6 years ago
- Views:
Transcription
1 Chapter 14 More Swing Menus Making GUIs Pretty (and More Functional) Box Containers and Box Layout Managers More on Events and Listeners Another Look at the Swing Class Hierarchy Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 1
2 Menus Three Swing classes used to put a menu in a program: AbstractButton» JMenuBar» JMenu» JMenuItem JButton JMenuItem JMenu Menu items behave in the same way as buttons Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 2
3 A GUI with a Menu JMenu memomenu = new JMenu("Memos"); JMenuItem m; m = new JMenuItem("Save Memo 1"); m.addactionlistener(this); memomenu.add(m); m = new JMenuItem("Save Memo 2"); m.addactionlistener(this); memomenu.add(m);... JMenuBar mbar = new JMenuBar(); mbar.add(memomenu); setjmenubar(mbar); Create a menu Create a menu item A menu item uses an action listener the same way a button does. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 3
4 A GUI with a Menu JMenu memomenu = new JMenu("Memos"); JMenuItem m; m = new JMenuItem("Save Memo 1"); m.addactionlistener(this); memomenu.add(m); m = new JMenuItem("Save Memo 2"); m.addactionlistener(this); memomenu.add(m);... JMenuBar mbar = new JMenuBar(); mbar.add(memomenu); setjmenubar(mbar); Each menu item is added to the menu. The menu is added to the menu bar. One way to add a menu bar to a JFrame Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 4
5 Nested Menus JMenu is a descendant of JMenuItem Every JMenu object is also a JMenuItem A JMenu can be a menu item in another menu This allows nested menus Clicking on a nested menu shows the items in the nested menu and allows them to be selected. AbstractButton JMenuItem JButton JMenu Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 5
6 Making GUIs Pretty (and More Functional) Adding Icons The JScrollPane Class for Scroll Bars Adding Borders Changing the Look and Feel Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 6
7 Using Icons Icons are (small) pictures Icons may be added to labels, buttons, and menu items. The ImageIcon class can be used to convert a picture to an icon: ImageIcon SmileyFaceIcon = new ImageIcon( smiley.gif ); The seticon method can be used to add an icon to a component: JLabel hellolabel = new JLabel( Hello ); ImageIcon dukewavingicon = new ImageIcon( duke_waving.gif ); hellolabel.seticon(dukewavingicon); Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 7
8 The JScrollPane Class for Scroll Bars A view port is used when not all information can be displayed on screen at once. Scroll bars move a view port around to show different parts of the information. JScrollPane is a class that can provide a view port with scroll bars. An example using JScrollPane with a JTextArea called thetext and a JPanel called textpanel: JScrollPane scrolledtext = new JScrollPane(theText); textpanel.add(scrolledtext); Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 8
9 Adding Borders A border is an area that frames a component. Swing provides several different types of borders:» BevelBorder makes component look raised or lowered» EtchedBorder similar to BevelBorder but can t set size» EmptyBorder extra space around the component» LineBorder colored border of a given thickness» MatteBorder similar to LineBorder but can adjust thickness on each side of the component An example of adding a bevel border to a button: testbutton.setborder(new BevelBorder(BevelBorder.LOWERED)); Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 9
10 Box Layout Manager Useful for a single column or single row of components Specify X_AXIS (horizontal) or Y_AXIS (vertical) layout as second parameter to constructor for layout manager Provides a means of separating components in a row or column» Strut allocates a fixed amount of space between two components» Glue allocates a variable amount of space between two components A Box container is a container that is automatically given a BoxLayout manager. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 10
11 Box Layout Versus Other Layouts Horizontal box layout is similar to flow layout. Vertical box layout is similar to grid layout with only one column. Big advantage of box layout is control over spacing using struts and glue. Note that it is possible to use struts and glue with other layout managers but they will probably not work as intended. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 11
12 Box Layout Demo Program Specifies a horizontal layout JPanel horizontalpanel = new JPanel(); horizontalpanel.setlayout( new BoxLayout(horizontalPanel, BoxLayout.X_AXIS)); Component horizontalstrut = Box.createHorizontalStrut(HORIZONTAL_STRUT_SIZE); horizontalpanel.add(horizontalstrut); JButton hstopbutton = new JButton("Red"); hstopbutton.addactionlistener(this); horizontalpanel.add(hstopbutton); Static method in Box class used to create a strut of a particular size for spacing Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 12
13 Struts and Glue invisible components used to add space between visible components horizontal strut:» programmer specifies width, which layout manager does not change vertical strut:» programmer specifies height, which layout manager does not change glue:» no specified size» can be added to layout to specify where extra space should go when container grows Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 13
14 Setting the Spacing Between Components To control spacing with layouts other than the Box layout, use sethgap and setvgap: public void sethgap(int hgap)» sets the horizontal gap between components» argument is size of gap in pixels public void setvgap(int vgap)» sets the vertical gap between components» argument is size of gap in pixels Can also use EmptyBorder in any layout manager which will add space as part of a component Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 14
15 The Box Container Class A Box object works like a panel with a BoxLayout manager. Created using static methods: Box horizontalbox = Box.createHorizontalBox(); Box verticalbox = Box.createVerticalBox(); Automatically given a BoxLayout manager when created» You should not use setlayout method with a box object. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 15
16 The CardLayout Manager Allows a set of views (components) to choose among» Only one view is visible at a time.» Can go through views in order or jump to any view.» Often the components added to a CardLayout will be panels. Each component added to a CardLayout has a string associated with it that works like a name: deckpanel.add("start", startcardpanel);» The string can be used later to display that component (or view): dealer.show(deckpanel, "start"); Need reference to layout manager to change views, so do not use anonymous object: deckpanel.add(new CardLayout()); legal but useless Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 16
17 CardLayoutDemo deckpanel = new JPanel(); dealer = new CardLayout(); deckpanel.setlayout(dealer);... deckpanel.add("start", startcardpanel);... deckpanel.add("green", greencardpanel);... deckpanel.add("red", redcardpanel);... dealer.show(deckpanel, "red");... dealer.next(deckpanel); Only one of these three panels will be visible at a time. will show redcardpanel if redcardpanel is currently displayed, will show startcardpanel Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 17
18 Inner Classes An inner class is a class defined within another class. Advantages: They make the outer class more self contained.» If WindowDestroyer is used, must make sure that class is available.» If InnerDestroyer (inner class version of WindowDestroyer) is used, it will always be available. Inner class has access to all instance variables and methods of outer class, including private ones. Avoid name conflicts.» You could have another (outer) class called InnerDestroyer and there would not be a conflict. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 18
19 The WindowListener Interface For a class to be a listener for window events, it must implement the WindowListener interface. By implementing the WindowListener interface, a window can be its own listener. The advantage of making a window its own listener is that it is easy to call methods from the listener since they are in the same object. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 19
20 The WindowListener Interface Implementation of the WindowListener interface requires these seven methods to be defined:» public void windowopened(windowevent e)» public void windowclosing(windowevent e)» public void windowclosed(windowevent e)» public void windowiconified(windowevent e)» public void windowdeiconified(windowevent e)» public void windowactivated(windowevent e)» public void windowdeactivated(windowevent e) If a method will be not be used, it should be defined with an empty body WindowAdapter is a class that implements all seven methods of the WindowListener with empty bodies. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 20
21 Programming the Close-Window Button The WindowListener interface can be used to program the close-window button. If the close-window button is not programmed, by default it will close the window but not exit the program. For a window that does not close when the close-window button is clicked, use a method call like this: setdefaultcloseoperation( WindowConstants.DO_NOTHING_ON_CLOSE); The CloseWindowDemo uses this method call When the close-window button is clicked, the program displays a confirmation dialog instead of closing the window. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 21
22 CloseWindowDemo Program public CloseWindowDemo() { setsize(width, HEIGHT); } setdefaultcloseoperation( WindowConstants.DO_NOTHING_ON_CLOSE); addwindowlistener(new InnerDestroyer()); settitle("close Window Demo"); Container contentpane = getcontentpane(); contentpane.setlayout(new BorderLayout());... Prevents window from closing so that user can confirm or cancel before window is closed. Constructor for the CloseWindowDemo class, which inherits from JFrame. Defined on next slide Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 22
23 CloseWindowDemo Program Definition of inner class used as listener for the CloseWindowDemo class. Inherits from WindowAdapter so it does not have to define all seven window event methods. private class InnerDestroyer extends WindowAdapter { public void windowclosing(windowevent e) } { } ConfirmWindow askwindow = new ConfirmWindow(); askwindow.setvisible(true); ConfirmWindow closes window and exits program if user confirms close. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 23
24 CloseWindowDemo Program public void actionperformed(actionevent e) { if (e.getactioncommand().equals("yes")) } actionperformed method from the ConfirmWindow inner class The main window will only be closed if the user clicks the Yes button in the ConfirmWindow System.exit(0); else if (e.getactioncommand().equals("no")) dispose(); //Destroys only the ConfirmWindow. else System.out.println("Error in Confirm Window."); Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 24
25 Changing Components A program can add or remove components after a GUI has been displayed, but that is beyond the scope of the book. Making components visible or not visible gives a similar effect. The setvisible method is used in the VisibleDemo program to make only one of the red and green labels visible at a time. (code on next slide) Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 25
26 Changing Components The actionperformed method from the VisibleDemo program public void actionperformed(actionevent e) { if (e.getactioncommand().equals( Red )) { colorpanel.setbackground(color.red); stoplabel.setvisible(false); golabel.setvisible(true); validate(); } Visibility changes won t... occur until the validate method is called. } There is similar code for when the Green button is pressed, which turns the background green and hides the go label. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 26
27 Another Look at the Swing Class Hierarchy JComponent Swing AbstractButton JLabel JMenuBar JButton JMenuItem JMenu Abstract Class Class All of the basic properties of JButton and JMenuItem are inherited from AbstractButton. JButton and JMenuItem are similar because they are derived from the same abstract class. Since AbstractButton is an abstract class, no objects of that class can be made. The purpose of the AbstractButton class is to provide a place for code that is common to JButton and JMenuItem and avoid repeated code. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 27
28 Another Look at the Swing Class Hierarchy JComponent Swing AbstractButton JLabel JMenuBar JMenuItem Abstract Class JButton Class JMenu JLabel and JButton inherit from a common ancestor, namely JComponent, so they have some similarities. Notice, however, that JLabel and JButton are not derived from the same class, even though they have a common ancestor. The hierarchy reflects the fact that JButton and JMenuItem are more similar than JLabel and JButton. Also notice that JMenu inherits from JMenuItem, so it can be used anywhere a JMenuItem can. This allows nested menus. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 28
29 Summary You can add icons to JButtons, JLabels, and JMenuItems. A JMenuBar can be added to a JFrame with the method setjmenubar or with the usual add method. Both buttons and menu items fire action events and so should have an ActionListener registered with them. You can use the class JScrollPane to add scroll bars to a text area. You can define a window listener class by having it implement the WindowListener interface. If you want a close-button to do something other than close the window, you must use SetDefaultCloseOperation. If you change the visibility of a component you should use the validate method to update the GUI. Chapter 14 Java: an Introduction to Computer Science & Programming - Walter Savitch 29
More Swing. Chapter 14. Chapter 14 1
More Swing Chapter 14 Chapter 14 1 Objectives learn to add menus, icons, borders, and scroll bars to GUIs learn to use the BoxLayout manager and the Box class learn about inner classes learn about the
More informationChapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus
Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationChapter 13 Lab Advanced GUI Applications
Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationMore Swing. CS180 Recitation 12/(04,05)/08
More Swing CS180 Recitation 12/(04,05)/08 Announcements No lecture/labs next week Recitations and evening consulting hours will be held as usual. Debbie's study group on tuesday and office hours on thursday
More informationOverview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling
Overview Building Graphical User Interfaces Constructing GUIs Interface components GUI layout Event handling 4.1 GUI Principles AWT and Swing Components: GUI building blocks. Buttons, menus, sliders, etc.
More informationBuilding Graphical User Interfaces. GUI Principles
Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting
More informationPIC 20A GUI with swing
PIC 20A GUI with swing Ernest Ryu UCLA Mathematics Last edited: November 22, 2017 Hello swing Let s create a JFrame. import javax. swing.*; public class Test { public static void main ( String [] args
More informationControl Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User
CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by
More informationBuilding Graphical User Interfaces. Overview
Building Graphical User Interfaces 4.1 Overview Constructing GUIs Interface components GUI layout Event handling 2 1 GUI Principles Components: GUI building blocks. Buttons, menus, sliders, etc. Layout:
More informationCSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing
CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic
More informationCS 251 Intermediate Programming GUIs: Components and Layout
CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()
More informationStarting Out with Java: From Control Structures Through Objects Sixth Edition
Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes
More informationTool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT
INSTITUTIONEN FÖR Tool Kits, Swing SMD158 Interactive Systems Spring 2005 Jan-28-05 2002-2005 by David A. Carr 1 L Overview Tool kits in the abstract An overview of Swing/AWT Jan-28-05 2002-2005 by David
More informationCSE 8B Intro to CS: Java
CSE 8B Intro to CS: Java Winter, 2006 February 23 (Day 14) Menus Swing Event Handling Inner classes Instructor: Neil Rhodes JMenuBar container for menus Menus associated with a JFrame via JFrame.setMenuBar
More informationPROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7
PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,
More informationGraphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)
Graphics programming COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Overview Aims To provide an overview of Swing and the AWT To show how to build
More informationFrames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling
Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)
More informationProgramming Languages and Techniques (CIS120e)
Programming Languages and Techniques (CIS120e) Lecture 29 Nov. 19, 2010 Swing I Event- driven programming Passive: ApplicaHon waits for an event to happen in the environment When an event occurs, the applicahon
More informationLayout. Dynamic layout, Swing and general layout strategies
Layout Dynamic layout, Swing and general layout strategies Two Interface Layout Tasks Designing a spatial layout of widgets in a container Adjusting that spatial layout when container is resized Both
More informationPrototyping a Swing Interface with the Netbeans IDE GUI Editor
Prototyping a Swing Interface with the Netbeans IDE GUI Editor Netbeans provides an environment for creating Java applications including a module for GUI design. Here we assume that we have some existing
More informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationGUI Design. Overview of Part 1 of the Course. Overview of Java GUI Programming
GUI Design Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu /~spring Overview of Part 1 of the Course Demystifying
More informationJAVA NOTES GRAPHICAL USER INTERFACES
1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the
More informationWhat is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs
What is Widget Layout? Laying Out Components Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position Main problem: what if
More informationGUI Programming: Swing and Event Handling
GUI Programming: Swing and Event Handling Sara Sprenkle 1 Announcements No class next Tuesday My Fourth of July present to you: No quiz! Assignment 3 due today Review Collections: List, Set, Map Inner
More informationCourse Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski
CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University March 10, 2008 / Lecture 8 Outline Course Status Course Information & Schedule
More informationBasicsof. JavaGUI and SWING
Basicsof programming3 JavaGUI and SWING GUI basics Basics of programming 3 BME IIT, Goldschmidt Balázs 2 GUI basics Mostly window-based applications Typically based on widgets small parts (buttons, scrollbars,
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More informationChapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.
Chapter 8 Java continued CS3283 - Hugh Anderson s notes. Page number: 263 ALERT MCQ test next week This time This place Closed book CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Assignment #2
More informationJava continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3
Chapter 8 Java continued MCQ test next week This time This place Closed book ALERT CS3283 - Hugh Anderson s notes. Page number: 263 CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Last week Assignment
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) Layout Managment 1 Hello World Often have a static method: createandshowgui() Invoked by main calling invokelater private static void createandshowgui() { } JFrame frame
More informationGraphical User Interface (Part-3) Supplementary Material for CPSC 233
Graphical User Interface (Part-3) Supplementary Material for CPSC 233 Menu Bars, Menus, and Menu Items A menu is an object of the class JMenu A choice on a menu is called a menu item, and is an object
More informationSwing II CHAPTER WINDOW LISTENERS 1034 Example: A Window Listener Inner Class 1036 The dispose Method 1040 The WindowAdapter Class 1041
CHAPTER 19 Swing II 19.1 WINDOW LISTENERS 1034 Example: A Window Listener Inner Class 1036 The dispose Method 1040 The WindowAdapter Class 1041 19.2 ICONS AND SCROLL BARS 1042 Icons 1042 Scroll Bars 1049
More informationSwing II Window Listeners Icons and Scroll Bars The Graphics Class Colors 1044
18.1 Window Listeners 1002 Example: A Window Listener Inner Class 1004 The dispose Method 1008 The WindowAdapter Class 1009 18.2 Icons and Scroll Bars 1010 Icons 1010 Scroll Bars 1017 Example: Components
More informationExample Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.
COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization
More informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationGUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline
Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example
More informationChapter 1 GUI Applications
Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations
More informationJava Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University
Java Swing Recitation 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University Announcements Project 8 is out Milestone due on Dec 3rd, 10:00 pm Final due on Dec 10th, 10:00 pm No classes,
More informationGUI Basics. Object Orientated Programming in Java. Benjamin Kenwright
GUI Basics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Graphical User Interface (GUI) Concepts Libraries, Implementation, Mechanics,.. Abstract Windowing Toolkit (AWT) Java
More informationImplementing Graphical User Interfaces
Chapter 6 Implementing Graphical User Interfaces 6.1 Introduction To see aggregation and inheritance in action, we implement a graphical user interface (GUI for short). This chapter is not about GUIs,
More informationAP CS Unit 11: Graphics and Events
AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two
More informationLaying Out Components. What is Widget Layout?
Laying Out Components Interior Design for GUIs What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position
More informationGraphical User Interface (Part-1) Supplementary Material for CPSC 233
Graphical User Interface (Part-1) Supplementary Material for CPSC 233 Introduction to Swing A GUI (graphical user interface) is a windowing system that interacts with the user The Java AWT (Abstract Window
More informationJava Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1
Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes
More informationOutline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics
Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming
More informationEvent Driven Programming
Event Driven Programming Part 1 Introduction Chapter 12 CS 2334 University of Oklahoma Brian F. Veale 1 Graphical User Interfaces So far, we have only dealt with console-based programs Run from the console
More informationChapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1
Chapter 13 Applets and HTML HTML Applets Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Overview Applets: Java programs designed to run from a document on the Internet
More information1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static
18 7 17 1 1.1 GUI ( ) GUI ( ) JFrame public class XXX extends JFrame { public XXX() { // XXX // init()... // ( )... init() main() public static public class XXX extends JFrame { public XXX() { // setsize(,
More informationGraphical Interfaces
Weeks 11&12 Graphical Interfaces All the programs that you have created until now used a simple command line interface, which is not user friendly, so a Graphical User Interface (GUI) should be used. The
More informationHandout 14 Graphical User Interface (GUI) with Swing, Event Handling
Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement
More information1005ICT Object Oriented Programming Lecture Notes
1005ICT Object Oriented Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 20 GUI Components and Events This section develops a program
More informationProgramming graphics
Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it
More informationWindow Interfaces Using Swing. Chapter 12
Window Interfaces Using Swing 1 Reminders Project 7 due Nov 17 @ 10:30 pm Project 6 grades released: regrades due by next Friday (11-18-2005) at midnight 2 GUIs - Graphical User Interfaces Windowing systems
More informationCS 2113 Software Engineering
CS 2113 Software Engineering Java 5 - GUIs Import the code to intellij https://github.com/cs2113f18/template-j-5.git Professor Tim Wood - The George Washington University Class Hierarchies Abstract Classes
More informationSwing from A to Z Some Simple Components. Preface
By Richard G. Baldwin baldwin.richard@iname.com Java Programming, Lecture Notes # 1005 July 31, 2000 Swing from A to Z Some Simple Components Preface Introduction Sample Program Interesting Code Fragments
More informationJava Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing
Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/
More informationLayout. Dynamic layout Layout design pattern Layout strategies
Layout Dynamic layout Layout design pattern Layout strategies 2.6 Layout 2 https://www.bostonglobe.com/ 2.6 Layout 3 Responsive vs. Adaptive Responsive: universal design reflows spatial layout to fit width
More information11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS
Objec&ves RouleQe Assign 8: Refactoring for Extensibility Programming Paradigms Introduc&on to GUIs in Java Ø Event handling Nov 6, 2015 Sprenkle - CSCI209 1 Nov 6, 2015 Sprenkle - CSCI209 2 Assign 8:
More informationLayout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2
Layout Dynamic layout Layout design pattern Layout strategies 2.6 Layout 2 Two Interface Layout Tasks 1. Designing a spatial layout of widgets in a container 2. Adjusting that spatial layout when container
More informationPart I: Learn Common Graphics Components
OOP GUI Components and Event Handling Page 1 Objectives 1. Practice creating and using graphical components. 2. Practice adding Event Listeners to handle the events and do something. 3. Learn how to connect
More informationPart 3: Graphical User Interface (GUI) & Java Applets
1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ
More informationGraphic User Interfaces. - GUI concepts - Swing - AWT
Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations
More informationFORMAS DE IMPLEMENTAR LOS OYENTES. A).- El oyente en una clase independiente con el constructor con un argumento y usando el método getactioncommand.
FORMAS DE IMPLEMENTAR LOS OYENTES A).- El oyente en una clase independiente con el constructor con un argumento y usando el método getactioncommand. public class VentanaOyente extends Frame{ private Oyente
More informationSummary Chapter 25 GUI Components: Part 2
1040 Chapter 25 GUI Components: Part 2 ponent on the line. TheJTextField is added to the content pane with a call to our utility method addcomponent (declared at lines 79 83). MethodaddComponent takes
More informationSystems Programming Graphical User Interfaces
Systems Programming Graphical User Interfaces Julio Villena Román (LECTURER) CONTENTS ARE MOSTLY BASED ON THE WORK BY: José Jesús García Rueda Systems Programming GUIs based on Java
More informationCommand-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.
1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is
More informationClass 16: The Swing Event Model
Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present
More information17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau
List of Slides 1 Title 2 Chapter 13: Graphical user interfaces 3 Chapter aims 4 Section 2: Example:Hello world with a GUI 5 Aim 6 Hello world with a GUI 7 Hello world with a GUI 8 Package: java.awt and
More informationJonathan Aldrich Charlie Garrod
Principles of Software Construction: Objects, Design, and Concurrency (Part 3: Design Case Studies) Introduction to GUIs Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework
More informationGUI Components Continued EECS 448
GUI Components Continued EECS 448 Lab Assignment In this lab you will create a simple text editor application in order to learn new GUI design concepts This text editor will be able to load and save text
More informationCOSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build
More informationDr. Hikmat A. M. AbdelJaber
Dr. Hikmat A. M. AbdelJaber JWindow: is a window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame.
More informationGraphical User Interfaces. Swing. Jose Jesus García Rueda
Graphical User Interfaces. Swing Jose Jesus García Rueda Introduction What are the GUIs? Well known examples Basic concepts Graphical application. Containers. Actions. Events. Graphical elements: Menu
More informationAll the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.
Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space
More informationGraphical Interfaces
Weeks 9&11 Graphical Interfaces All the programs that you have created until now used a simple command line interface, which is not user friendly, so a Graphical User Interface (GUI) should be used. The
More informationBASICS OF GRAPHICAL APPS
CSC 2014 Java Bootcamp Lecture 7 GUI Design BASICS OF GRAPHICAL APPS 2 Graphical Applications So far we ve focused on command-line applications, which interact with the user using simple text prompts In
More informationThe JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class
CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical
More informationJava Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers
Course Name: Advanced Java Lecture 19 Topics to be covered Java Swing Lists Trees Tables Styled Text Components Progress Indicators Component Organizers AWT to Swing AWT: Abstract Windowing Toolkit import
More informationGraphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI
CBOP3203 Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI components like button, text input, scroll bar and others.
More informationObject Oriented Programming
Object Oriented Programming 1. Graphical User Interfaces OOP10 - M. Joldoş - T.U. Cluj 1 GUI A Graphical User Interface (GUI pronounced "goo-ee") presents a userfriendly mechanism for interacting with
More informationEclipsing Your IDE. Figure 1 The first Eclipse screen.
Eclipsing Your IDE James W. Cooper I have been hearing about the Eclipse project for some months, and decided I had to take some time to play around with it. Eclipse is a development project (www.eclipse.org)
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) Layout Managment 1 Hello World Often have a run method to create and show a GUI Invoked by main calling invokelater private void run() { } JFrame frame = new JFrame("HelloWorldSwing");
More informationCSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationToday. cisc3120-fall2012-parsons-lectiii.3 2
MORE GUI COMPONENTS Today Last time we looked at some of the components that the: AWT Swing libraries provide for building GUIs in Java. This time we will look at several more GUI component topics. We
More informationCPS122 Lecture: Graphical User Interfaces and Event-Driven Programming
CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised March 2, 2017 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField,
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware
More informationGraphical User Interfaces in Java
COMP16121 Graphical User Interfaces in Java COMP16121 Sean Bechhofer sean.bechhofer@manchester.ac.uk Why? With the dominance of windows-based systems, Graphical User Interfaces (GUIs) are everywhere. They
More informationGraphical User Interfaces. Comp 152
Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from
More informationKF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation
KF5008 Program Design & Development Lecture 1 Usability GUI Design and Implementation Types of Requirements Functional Requirements What the system does or is expected to do Non-functional Requirements
More informationInterfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics
Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics 1 Collections (from the Java tutorial)* A collection (sometimes called a container) is simply an object that
More information11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events
Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes
More informationYouTube Break. https://www.youtube.com/watch?v=lvtfd_rj2he
Layout Jeff Avery YouTube Break https://www.youtube.com/watch?v=lvtfd_rj2he Positioning Visual Components Previously, we learned about event handling and model-view-control architecture. Next, we need
More informationCS 251 Intermediate Programming GUIs: Event Listeners
CS 251 Intermediate Programming GUIs: Event Listeners Brooke Chenoweth University of New Mexico Fall 2017 What is an Event Listener? A small class that implements a particular listener interface. Listener
More informationFinal Exam CS 251, Intermediate Programming December 13, 2017
Final Exam CS 251, Intermediate Programming December 13, 2017 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationDatenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1
Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text
More informationJLayeredPane. Depth Constants in JLayeredPane
JLayeredPane Continuing on Swing Components A layered pane is a Swing container that provides a third dimension for positioning components depth or Z order. The class for the layered pane is JLayeredPane.
More information