Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Size: px
Start display at page:

Download "Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling"

Transcription

1 Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

2 Introduction to Swing The Java AWT (Abstract Window Toolkit) package is the original Java package for doing GUIs A GUI (graphical user interface) is a windowing system that interacts with the user The Swing package is an improved version of the AWT However, it does not completely replace the AWT Some AWT classes are replaced by Swing classes, but other AWT classes are needed when using Swing Swing GUIs are designed using a form of object-oriented programming known as event-driven programming Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-2

3 What is a frame? Frame object is a window with a title bar that provides the basic attributes of a window such as buttons to minimize, maximize and close.

4 Resizing windows Frame with less width Width reduced further

5 My mental picture of a frame Visualize Graphical User interfaces as pictures to be mounted on this picture frame.

6 Some Methods in the Class JFrame (Part 1 of 3) Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-6

7 Some Methods in the Class JFrame (Part 2 of 3) Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-7

8 Some Methods in the Class JFrame (Part 3 of 3) Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-8

9 The Container Class Any class that is a descendent class of the class Container is considered to be a container class The Container class is found in the java.awt package, not in the Swing library Any object that belongs to a class derived from the Container class (or its descendents) can have components added to it The class JFrame is a descendent class of the class Container Therefore they and any of their descendents can serve as a container Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-9

10 The JComponent Class Any subclass of the class JComponent is called a component class Any JComponent object or component can be added to any container class object We will study a few subclasses of JComponent. Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-10

11 Objects in a Typical GUI Almost every GUI built using Swing container classes will be made up of three kinds of objects: 1. The container itself, probably a panel or window-like object 2. The components added to the container such as labels, buttons, and text areas 3. A layout manager to position the components inside the container Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-11

12 The GUI objects we need to know JLabel class to display messages JTextField class for single line two way communication JTextArea for multiple line displays JButton for buttons that may be pressed.

13 Labels For the problem we are studying we need a GUI to display a message. A label is an object of the class JLabel Text can be added to a JFrame using a label The text for the label is given as an argument when the JLabel is created The label can then be added to a JFrame JLabel greeting = new JLabel("Hello"); add(greeting); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-13

14 Some Methods in the Class JTextComponent (Part 1 of 2) Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-14

15 Some Methods in the Class JTextComponent (Part 2 of 2) Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-15

16 JTextField class Objects of the JTextField class used for two way communication - either to display an object of the String class on say an object of the JFrame class or to allow the user to type in an object of the String class in an object of the JTextField class for retrieval and manipulation. This class is very useful for interacting with lines of text.

17 Useful methods of this class Constructor - JTextField(n) where n gives how many characters are to be displayed. settext(astring) defines the string to be stored in the object. N characters of this string are also displayed. gettext() returns the object of the String class saved in the object.

18 Text Fields A text field is an object of the class JTextField It is displayed as a field that allows the user to enter a single line of text private JTextField name;... name = new JTextField(NUMBER_OF_CHAR); In the text field above, at least NUMBER_OF_CHAR characters can be visible Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-18

19 Text Fields There is also a constructor with one additional String parameter for displaying an initial String in the text field JTextField name = new JTextField( "Enter name here.", 30); A Swing GUI can read the text in a text field using the gettext method String inputstring = name.gettext(); The method settext can be used to display a new text string in a text field name.settext("this is some output"); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-19

20 Text Areas A text area is an object of the class JTextArea It is the same as a text field, except that it allows multiple lines Two parameters to the JTextArea constructor specify the minimum number of lines, and the minimum number of characters per line that are guaranteed to be visible JTextArea thetext = new JTextArea(5,20); Another constructor has one addition String parameter for the string initially displayed in the text area JTextArea thetext = new JTextArea( "Enter\ntext here." 5, 20); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-20

21 Text Areas The line-wrapping policy for a JTextArea can be set using the method setlinewrap The method takes one boolean type argument If the argument is true, then any additional characters at the end of a line will appear on the following line of the text area If the argument is false, the extra characters will remain on the same line and not be visible thetext.setlinewrap(true); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-21

22 Text Fields and Text Areas A JTextField or JTextArea can be set so that it can not be changed by the user thetext.seteditable(false); This will set thetext so that it can only be edited by the GUI program, not the user To reverse this, use true instead (this is the default) thetext.seteditable(true); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-22

23 Numbers of Characters Per Line The number of characters per line for a JTextField or JTextArea object is the number of em spaces An em space is the space needed to hold one uppercase letter M The letter M is the widest letter in the alphabet A line specified to hold 20 M 's will almost always be able to hold more than 20 characters Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-23

24 Buttons A button object is created from the class JButton and can be added to a JFrame The argument to the JButton constructor is the string that appears on the button when it is displayed JButton endbutton = new JButton("Click to end program."); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-24

25 How to show a GUI object? Create the object Attach the object to the frame. Question - Where to attach the object? Decided by the layout manager. The simplest layout manager - the flow layout manager

26 Containers and Layout Managers Multiple components can be added to the content pane of a JFrame using the add method However, the add method does not specify how these components are to be arranged To describe how multiple components are to be arranged, a layout manager is used There are a number of layout manager classes such as BorderLayout, FlowLayout, and GridLayout Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-26

27 Flow Layout Managers The FlowLayout manager is the simplest layout manager setlayout(new FlowLayout()); It arranges components one after the other, going from left to right Components are arranged in the order in which they are added Since a location is not specified, the add method has only one argument when using the FlowLayoutManager add.(label1); Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-27

28 How does a flow layout manager work? It works by placing the GUI objects left to right top to bottom. Example of picture frame Suppose we have 3 pictures to mount. How do we proceed? Take the first picture Put it on. Take the second picture. Put it on. etc

29 Where does the next picture go? Look for space - place from left to right, top to bottom. There is enough space for the first 2 pictures in the top row.

30 Where will the last picture go? Since there is no place in the top row, it goes to the next row.

31 What if the window is resized? The layout manager automatically moves the position of the GUI objects, moving them from row to row as needed.

32 Problem 1 Show a window with two messages on it.

33 General form of a frame based program import javax.swing.*; import java.awt.*; import java.awt.event.*; public class your_application_name extends JFrame implements an interface // Optional not needed now { Variables needed for your application Constructor method other methods as needed methods needed for the interface // not needed now main method }

34 import java.awt.*; // import the java.awt package import javax.swing.*; public class MyFirstFrame extends JFrame{ JLabel myquestion, yourresponse; public MyFirstFrame(){ super("an example of a Frame"); //Define the label on the titlebar setlayout( new FlowLayout() ); // Define what layout manager // will be used. myquestion = new JLabel("How are you?"); // Create a GUI object. // My mental image - get hold of a picture add(myquestion); //Add it to the frame. // My mental image - mount the picture in the next available place yourresponse = new JLabel("I am fine"); add(yourresponse); }

35 Net result : two GUI objects of JLabel class are displayed on the frame

36 The main method public static void main(string args[]) { MyFirstFrame aframe = new MyFirstFrame(); aframe.setsize(250, 100); aframe.setvisible(true); } // Define a variable of the class I just defined // Create an object of this class //Define the size of the frame to be displayed // Display the frame

37 What does the frame look like? We have already seen this before

38 What is an event? An event is something that happens in the outside world that our program should be aware of. Examples : pressing the Carriage Return (CR) pressing a Java button clicking or dragging a mouse button (not to be covered in this course)

39 Events Event-driven programming is a programming style that uses a signal-and-response approach to programming An event is an object that acts as a signal to another object know as a listener The sending of an event is called firing the event The object that fires the event is often a GUI component, such as a button that has been clicked Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-39

40 Listeners A listener object performs some action in response to the event A given component may have any number of listeners Each listener may respond to a different kind of event, or multiple listeners might may respond to the same events Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-40

41 Event Handlers A listener object has methods that specify what will happen when events of various kinds are received by it These methods are called event handlers The programmer using the listener object will define or redefine these event-handler methods Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-41

42 Event Firing and an Event Listener Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-42

43 Event-Driven Programming Event-driven programming is very different from most programming seen up until now So far, programs have consisted of a list of statements executed in order When that order changed, whether or not to perform certain actions (such as repeat statements in a loop, branch to another statement, or invoke a method) was controlled by the logic of the program Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-43

44 Event-Driven Programming In event-driven programming, objects are created that can fire events, and listener objects are created that can react to the events The program itself no longer determines the order in which things can happen Instead, the events determine the order Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-44

45 Event-Driven Programming In an event-driven program, the next thing that happens depends on the next event In particular, methods are defined that will never be explicitly invoked in any program Instead, methods are invoked automatically when an event signals that the method needs to be called Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-45

46 Action Listeners and Action Events Clicking a button fires an event The event object is "sent" to another object called a listener This means that a method in the listener object is invoked automatically Furthermore, it is invoked with the event object as its argument In order to set up this relationship, a GUI program must do two things 1. It must specify, for each button, what objects are its listeners, i.e., it must register the listeners 2. It must define the methods that will be invoked automatically when the event is sent to the listener Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-46

47 A diagram showing event handling

48 Tip: Inputting and Outputting Numbers When attempting to input numbers from any Swing GUI, input text must be converted to numbers If the user enters the number 42 in a JTextField, the program receives the string "42" and must convert it to the integer 42 The same thing is true when attempting to output a number In order to output the number 42, it must first be converted to the string "42" Copyright 2008 Pearson Addison-Wesley. All rights reserved 17-48

49 An interface already defined in Java that we will use here interface ActionListener { public void actionperformed(actionevent e); } Any concrete class C implementing ActionListener must include the abstract method actionperformed with exactly the specified signature and return type. When the action listener uses an object of class C, it is necessary to ensure that the object of class C can handle the event. This guarantee is available since C implements ActionListener.

50 Problem 2 Step 1) allow user to type in a line of text in an input area, followed by a CR indicating end of line. Step 2) display in an output area the line typed in and clear the input area. Step 3) go to step 1.

51 An example: type lines and it is displayed in another GUI object

52 What happens after another line is typed in

53 What GUI objects do we need? A label nother label A place to type a line A box to display results

54 The problem public class MySecondFrame { // GUI objects we need // Constructor // event handler // main method which will // display the JFrame object }

55 A Frame based program for event handling import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MySecondFrame extends JFrame implements ActionListener{ JLabel prompt, outputtitle; JTextField inputarea; // input value here JTextArea outputarea; // output displayed here

56 public MySecondFrame() { super("an example of a Frame"); //setup the gui components and setlayout(new FlowLayout()); // initialize variables prompt = new JLabel( "Type a line" ); // prompt user to input value add( prompt ); // attach prompt to frame inputarea = new JTextField( 10 ); inputarea.addactionlistener(this); // we want to listen for an // ActionEvent add( inputarea ); //attach input Area to frame outputtitle = new JLabel( "Output produced by program" ); add( outputtitle ); // attach outputtitle to frame } outputarea = new JTextArea(10, 20); // we initially allow 10 lines // each with 20 chars/line add( outputarea ); // attach outputarea to frame

57 // process user's action on the input text field public void actionperformed( ActionEvent event) { String userinput; userinput = inputarea.gettext();//extract the input typed by the user outputarea.append("you typed - " + userinput + " \n"); // display the inputarea.settext(""); // input on the outputarea and clear // the inputarea. }

58 public static void main(string args[]) { } MySecondFrame aframe = new MySecondFrame(); aframe.setsize(250, 300); aframe.setvisible(true); }

59 Problem 3 Same as problem 2 except that there is a button which, when pressed, clears the output area.

60 Initial appearance The user can type a line of text followed by CR

61 Appearance after typing two lines The user can press the button at any time to reset the output area.

62 Idea Add a button to the frame. When pressed, the button creates an event also of the same ActionEvent class. The event handler analyzes the event and if the event happened in the object of JTextField work as before If the event happened in the object of the JButton class, clear the output area. Note object of JButton class

63 import java.awt.event.*; import java.awt.*; import javax.swing.*; public class MyThirdFrame extends JFrame implements ActionListener { JLabel prompt, outputtitle; JTextField inputarea; JTextArea outputarea; JButton mybutton; /* A new object same idea

64 public MyThirdFrame() { super("use of buttons"); setlayout(new FlowLayout()); prompt = new JLabel( "Type a line" ); add( prompt ); inputarea = new JTextField( 10 ); inputarea.addactionlistener(this); add( inputarea ); outputtitle = new JLabel( "Output produced by program" ); add( outputtitle ); outputarea = new JTextArea(10, 20); add( outputarea ); mybutton = new JButton("Clear Output"); mybutton.addactionlistener(this); add( mybutton ); setsize(250, 300); // setsize and setvisible may appear in constructor setvisible(true); }

65 public void actionperformed( ActionEvent event){ String userinput; if (event.getsource() == inputarea) { outputarea.append("you typed - " + event. getactioncommand() + " \n"); // Notice use of getactioncommand() to extract the string // associated with the event inputarea.settext(""); } else outputarea.settext(""); } } public static void main(string args[]){ MyThirdFrame aframe = new MyThirdFrame(); }

66 Problem 4 Same as problem 3 except that we now use a different object to handle the event in the button. Question Why do we need to handle a different object in the first place? Answer If the same event handler deals with events occurring in various objects, its task becomes complex Solution is to let different objects deal with events from various sources. The task for each event handler becomes simpler.

67 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyFourthFrame extends JFrame implements ActionListener { JLabel prompt, outputtitle; JTextField inputarea; JTextArea outputarea; JButton mybutton;

68 public MyFourthFrame() { super("use of buttons"); setlayout(new FlowLayout()); prompt = new JLabel( "Type a line" ); add( prompt ); inputarea = new JTextField( 10 ); inputarea.addactionlistener(this); add( inputarea ); outputtitle = new JLabel( "Output produced by program" ); add( outputtitle ); outputarea = new JTextArea(10, 20); add( outputarea ); mybutton = new JButton("Clear Output"); mybutton.addactionlistener(new ButtonEventHandler(this)); add( mybutton ); setsize(250, 300); setvisible(true); }

69 public void actionperformed( ActionEvent event){ outputarea.append("you typed - " + event. getactioncommand() + " \n"); inputarea.settext(""); } } public static void main(string args[]) {MyFourthFrame aframe = new MyFourthFrame(); }

70 import javax.swing.*; import java.awt.*; import java.awt.event.*; class ButtonEventHandler implements ActionListener{ MyFourthFrame local_frame; public ButtonEventHandler(MyFourthFrame frame_sent){ local_frame = frame_sent; } } public void actionperformed( ActionEvent e ){ local_frame.outputarea.settext("");; }

71 Inner Class and anonymous class Until now, we have defined classes that were defined at file scope which can be used in any valid context. Inner classes, including anonymous classes, where a class is defined inside another class is another concept to remember.

72 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called the outer class There is no particular location where the definition of the inner class (or classes) must be place within the outer class Placing it first or last, however, will guarantee that it is easy to find Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-72

73 Simple Uses of Inner Classes An inner class definition is a member of the outer class in the same way that the instance variables and methods of the outer class are members An inner class is local to the outer class definition The name of an inner class may be reused for something else outside the outer class definition If the inner class is private, then the inner class cannot be accessed by name outside the definition of the outer class Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-73

74 Simple Uses of Inner Classes There are two main advantages to inner classes They can make the outer class more self-contained since they are defined inside a class Both of their methods have access to each other's private methods and instance variables Using an inner class as a helping class is one of the most useful applications of inner classes If used as a helping class, an inner class should be marked private Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-74

75 Tip: Inner and Outer Classes Have Access to Each Other's Private Members Within the definition of a method of an inner class: It is legal to reference a private instance variable of the outer class It is legal to invoke a private method of the outer class Within the definition of a method of the outer class It is legal to reference a private instance variable of the inner class on an object of the inner class It is legal to invoke a (nonstatic) method of the inner class as long as an object of the inner class is used as a calling object Within the definition of the inner or outer classes, the modifiers public and private are equivalent Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-75

76 Class with an Inner Class Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-76

77 Class with an Inner Class Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-77

78 Class with an Inner Class Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-78

79 A new version of an application you have see before using inner classes import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyFifthFrame extends JFrame implements ActionListener { JLabel prompt, outputtitle; JTextField inputarea; JTextArea outputarea; JButton mybutton;

80 public MyFifthFrame() { super("use of buttons"); setlayout(new FlowLayout()); prompt = new JLabel( "Type a line" ); add( prompt ); inputarea = new JTextField( 10 ); inputarea.addactionlistener(this); add( inputarea ); outputtitle = new JLabel( "Output produced by program" ); add( outputtitle ); outputarea = new JTextArea(10, 20); add( outputarea ); mybutton = new JButton("Clear Output"); mybutton.addactionlistener(new ButtonEventHandler()); add( mybutton ); setsize(250, 300); setvisible(true); }

81 } public void actionperformed( ActionEvent event){ outputarea.append("you typed - " + event. getactioncommand() + " \n"); inputarea.settext(""); } public static void main(string args[]){ MyFifthFrame aframe = new MyFifthFrame(); } class ButtonEventHandler implements ActionListener{ public void actionperformed( ActionEvent e ) { outputarea.settext("");; } }

82 Why use a separate class for different events? The original program had a complex actionperformed where we check where the event occurred and act accordingly. In this version, code for the inner class is simple since it inherits the JTextfield from the outer class. Next we will eliminate any named class from this all together!! Idea the class has a very limited role to play and we don t need to give the class a name.

83 Anonymous Classes If an object is to be created, but there is no need to name the object's class, then an anonymous class definition can be used The class definition is embedded inside the expression with the new operator Anonymous classes are sometimes used when they are to be assigned to a variable of another type The other type must be such that an object of the anonymous class is also an object of the other type The other type is usually a Java interface Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-83

84 Anonymous Classes Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-84

85 Anonymous Classes Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-85

86 Anonymous Classes Copyright 2008 Pearson Addison-Wesley. All rights reserved 13-86

87 Idea of using anonymous classes. You extend a built-in adapter class called ActionListener by adding just the methods you need the actionperformed method in this case. Similar adapter classes are available for handling other events.

88 Anonymous class In event handling, of the type described in this program, we don t need to care what is the class of the object that is actually handling the event. This is a simple method to specify only what is to be done to handle the type of event of interest to us. The adapater class has empty bodies for all methods required in the interface. ActionEvent is not a good example to illustrate the advantage of adapter classes.

89 Mouse Listener The MouseListener interface has 5 methods for the following events: Mouse pressed, mouse released, mouse clicked, mouse entered and mouse exited. Most of the time the user is interested in a few of these events. Using adapter classes you only specify what you are interested in.

90 Application showing use of anonymous class import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MySixthFrame extends JFrame implements ActionListener { JLabel prompt, outputtitle; JTextField inputarea; JTextArea outputarea; JButton mybutton;

91 public MySixthFrame() { super("use of buttons"); setlayout(new FlowLayout()); prompt = new JLabel( "Type a line" ); add( prompt ); inputarea = new JTextField( 10 ); inputarea.addactionlistener(this); add( inputarea ); outputtitle = new JLabel( "Output produced by program" ); add( outputtitle ); outputarea = new JTextArea(10, 20); add( outputarea );

92 mybutton = new JButton("Clear Output"); mybutton.addactionlistener(new ActionListener(){ public void actionperformed(actionevent e) { outputarea.settext(""); } } ); add( mybutton ); setsize(250, 300); setvisible(true); } public void actionperformed( ActionEvent event){ outputarea.append("you typed - " + event. getactioncommand() + " \n"); inputarea.settext(""); } } } public static void main(string args[]){ MySixthFrame aframe = new MySixthFrame();

93 Problem to discuss Design a teller for a grocery store.

Graphical User Interface (Part-3) Supplementary Material for CPSC 233

Graphical 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 information

Window Interfaces Using Swing Objects

Window 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 information

Window Interfaces Using Swing Objects

Window 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 information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 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 information

Topic 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!

Topic 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 information

Window Interfaces Using Swing. Chapter 12

Window 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 information

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

Graphical 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 information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. 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 information

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions Midterm Test II 60-212 Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours Answer all questions Name : Student Id # : Only an unmarked copy of a textbook

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING 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 information

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

CSEN401 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 information

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting 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 information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

KF5008 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 information

AP CS Unit 11: Graphics and Events

AP 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 information

Swing from A to Z Some Simple Components. Preface

Swing 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 information

CSE 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 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 information

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised 1/15/10 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField, JTextArea,

More information

Java 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 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 information

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

The 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 information

17 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

17 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 information

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Control 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 information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components

More information

Systems Programming Graphical User Interfaces

Systems 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 information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

GUI 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 information

Java 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 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 information

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction 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 information

Graphical User Interfaces. Comp 152

Graphical 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 information

GUI Forms and Events, Part II

GUI Forms and Events, Part II GUI Forms and Events, Part II Quick Start Compile step once always mkdir labs javac PropertyTax6.java cd labs Execute step mkdir 6 java PropertyTax6 cd 6 cp../5/propertytax5.java PropertyTax6.java Submit

More information

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Course 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 information

Introduction. Introduction

Introduction. Introduction Introduction Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the

More information

PIC 20A GUI with swing

PIC 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 information

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive

More information

Datenbank-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 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 information

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Command-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 information

Graphical interfaces & event-driven programming

Graphical interfaces & event-driven programming Graphical interfaces & event-driven programming Lecture 12 of TDA 540 (Objektorienterad Programmering) Carlo A. Furia Alex Gerdes Chalmers University of Technology Gothenburg University Fall 2017 Pop quiz!

More information

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014 Introduction to GUIs Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2014 Slides copyright 2014 by Jonathan Aldrich, Charlie Garrod, Christian

More information

RAIK 183H Examination 2 Solution. November 11, 2013

RAIK 183H Examination 2 Solution. November 11, 2013 RAIK 183H Examination 2 Solution November 11, 2013 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

To gain experience using GUI components and listeners.

To gain experience using GUI components and listeners. Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both

More information

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali GUI and its COmponent Textfield, Button & Label By Iqtidar Ali GUI (Graphical User Interface) GUI is a visual interface to a program. GUI are built from GUI components. A GUI component is an object with

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

Graphical User Interfaces (GUIs)

Graphical User Interfaces (GUIs) CMSC 132: Object-Oriented Programming II Graphical User Interfaces (GUIs) Department of Computer Science University of Maryland, College Park Model-View-Controller (MVC) Model for GUI programming (Xerox

More information

Java. GUI building with the AWT

Java. GUI building with the AWT Java GUI building with the AWT AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses the controls defined by your OS therefore

More information

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 Objectives 1 6.1 Methods 1 void or return 1 Parameters 1 Invocation 1 Pass by value 1 6.2 GUI 2 JButton 2 6.3 Patterns

More information

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts SE1021 Exam 2 Name: You may use a note-sheet for this exam. But all answers should be your own, not from slides or text. Review all questions before you get started. The exam is printed single-sided. Write

More information

Swing I CHAPTER EVENT-DRIVEN PROGRAMMING 921 Events and Listeners 921

Swing I CHAPTER EVENT-DRIVEN PROGRAMMING 921 Events and Listeners 921 CHAPTER 17 Swing I 17.1 EVENT-DRIVEN PROGRAMMING 921 Events and Listeners 921 17.2 BUTTONS, EVENTS, AND OTHER SWING BASICS 923 Example: A Simple Window 923 Buttons 930 Action Listeners and Action Events

More information

Swing I Event-Driven Programming Buttons, Events, and Other Swing Basics Containers and Layout Managers 946

Swing I Event-Driven Programming Buttons, Events, and Other Swing Basics Containers and Layout Managers 946 17.1 Event-Driven Programming 925 Events and Listeners 925 17.2 Buttons, Events, and Other Swing Basics 926 Example: A Simple Window 927 Buttons 933 Action Listeners and Action Events 934 Example: A Better

More information

Graphics User Defined Forms, Part I

Graphics User Defined Forms, Part I Graphics User Defined Forms, Part I Quick Start Compile step once always mkdir labs javac PropertyTax5.java cd labs mkdir 5 Execute step cd 5 java PropertyTax5 cp /samples/csc/156/labs/5/*. cp PropertyTax1.java

More information

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Interfaces & 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 information

RAIK 183H Examination 2 Solution. November 10, 2014

RAIK 183H Examination 2 Solution. November 10, 2014 RAIK 183H Examination 2 Solution November 10, 2014 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)

More information

Class 16: The Swing Event Model

Class 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 information

Graphics 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) 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 information

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Example 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 information

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

GUI 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 information

Programming Language Concepts: Lecture 8

Programming Language Concepts: Lecture 8 Programming Language Concepts: Lecture 8 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 8, 11 February 2009 GUIs and event

More information

CS108, Stanford Handout #22. Thread 3 GUI

CS108, Stanford Handout #22. Thread 3 GUI CS108, Stanford Handout #22 Winter, 2006-07 Nick Parlante Thread 3 GUI GUIs and Threading Problem: Swing vs. Threads How to integrate the Swing/GUI/drawing system with threads? Problem: The GUI system

More information

CS 251 Intermediate Programming GUIs: Components and Layout

CS 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 information

Part I: Learn Common Graphics Components

Part 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 information

Graphical Applications

Graphical Applications Graphical Applications The example programs we've explored thus far have been text-based They are called command-line applications, which interact with the user using simple text prompts Let's examine

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

Java: Graphical User Interfaces (GUI)

Java: Graphical User Interfaces (GUI) Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application

More information

GUI Event Handlers (Part I)

GUI Event Handlers (Part I) GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event

More information

Chapter 7: A First Look at GUI Applications

Chapter 7: A First Look at GUI Applications Chapter 7: A First Look at GUI Applications Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All

More information

COMPSCI 230. Software Design and Construction. Swing

COMPSCI 230. Software Design and Construction. Swing COMPSCI 230 Software Design and Construction Swing 1 2013-04-17 Recap: SWING DESIGN PRINCIPLES 1. GUI is built as containment hierarchy of widgets (i.e. the parent-child nesting relation between them)

More information

CS Exam 1 Review Suggestions

CS Exam 1 Review Suggestions CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;

More information

Unit 6: Graphical User Interface

Unit 6: Graphical User Interface Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 6: Graphical User Interface 1 1. Overview of the

More information

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup

More information

SINGLE EVENT HANDLING

SINGLE EVENT HANDLING SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which

More information

JAVA NOTES GRAPHICAL USER INTERFACES

JAVA 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 information

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) ) COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) ) Course Evaluations Please do these. -Fast to do -Used to

More information

Programming graphics

Programming 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 information

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS 550 Chapter 14 GUI Components: Part 1 14.1 Introduction 14.2 Java s New Nimbus Look-and-Feel 14.3 Simple GUI-Based Input/Output with JOptionPane 14.4 Overview of Swing Components 14.5 Displaying Text and

More information

CSE 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 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 information

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Handout 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 information

Jonathan Aldrich Charlie Garrod

Jonathan 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 information

7. Program Frameworks

7. Program Frameworks 7. Program Frameworks Overview: 7.1 Introduction to program frameworks 7.2 Program frameworks for User Interfaces: - Architectural properties of GUIs - Abstract Window Toolkit of Java Many software systems

More information

CS11 Java. Fall Lecture 4

CS11 Java. Fall Lecture 4 CS11 Java Fall 2006-2007 Lecture 4 Today s Topics Interfaces The Swing API Event Handlers Inner Classes Arrays Java Interfaces Classes can only have one parent class No multiple inheritance in Java! By

More information

Graphical User Interface (GUI)

Graphical 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 information

CHAPTER 2. Java Overview

CHAPTER 2. Java Overview Networks and Internet Programming (0907522) CHAPTER 2 Java Overview Instructor: Dr. Khalid A. Darabkh Objectives The objectives of this chapter are: To discuss the classes present in the java.awt package

More information

encompass a group of features for building Graphical User Interfaces (GUI).

encompass a group of features for building Graphical User Interfaces (GUI). Java GUI (intro) JFC Java Foundation Classes encompass a group of features for building Graphical User Interfaces (GUI). javax.swing.* used for building GUIs. Some basic functionality is already there

More information

Graphical User Interface (GUI)

Graphical 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 information

Graphical User Interface

Graphical User Interface Lecture 10 Graphical User Interface An introduction Sahand Sadjadee sahand.sadjadee@liu.se Programming Fundamentals 725G61 http://www.ida.liu.se/~725g61/ Department of Computer and Information Science

More information

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

JRadioButton account_type_radio_button2 = new JRadioButton(Current); ButtonGroup account_type_button_group = new ButtonGroup(); Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button

More information

CS 180 Final Exam Review 12/(11, 12)/08

CS 180 Final Exam Review 12/(11, 12)/08 CS 180 Final Exam Review 12/(11, 12)/08 Announcements Final Exam Thursday, 18 th December, 10:20 am 12:20 pm in PHYS 112 Format 30 multiple choice questions 5 programming questions More stress on topics

More information

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008 Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

More information

Java Help Files. by Peter Lavin. May 22, 2004

Java Help Files. by Peter Lavin. May 22, 2004 Java Help Files by Peter Lavin May 22, 2004 Overview Help screens are a necessity for making any application user-friendly. This article will show how the JEditorPane and JFrame classes, along with HTML

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic 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 information

CS 251 Intermediate Programming GUIs: Event Listeners

CS 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 information

Agenda. Container and Component

Agenda. Container and Component Agenda Types of GUI classes/objects Step-by-step guide to create a graphic user interface Step-by-step guide to event-handling PS5 Problem 1 PS5 Problem 2 Container and Component There are two types of

More information

CSE 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 CSE 331 Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT Lecturer: Michael Hotan slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,

More information

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CPS122 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 information

Implementing Graphical User Interfaces

Implementing 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 information

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

More information

Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

Example: CharCheck. That s It??! What do you imagine happens after main() finishes? Event-Driven Software Paradigm Today Finish Programming Unit: Discuss Graphics In the old days, computers did exactly what the programmer said Once started, it would run automagically until done Then you

More information