Handout 14 Graphical User Interface (GUI) with Swing, Event Handling
|
|
- Hester Brooks
- 5 years ago
- Views:
Transcription
1 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 User Interface components Buttons, radio buttons, text fields, etc Extends an earlier library: AWT Dimension Font LayoutManager 1 Classes in the java.awt package Heavyweight FontMetrics Object Color Panel Applet JApplet Graphics Component Container Window Frame JFrame * Dialog JDialog JComponent Swing Components in the javax.swing package JComponent and its subclasses: AbstractButton JMenuItem JButton JCheckBoxMenuItem JMenu JRadioButtonMenuItem JToggleButton JCheckBox JComponent JEditorPane JRadioButton JTextComponent JTextField JPasswordField JTextArea JLabel JList JComboBox JPanel JOptionPane JScrollBar JSlider JTabbedPane JSplitPane JLayeredPane JSeparator JScrollPane JRootPane JToolBar JMenuBar JPopupMenu JFileChooser JColorChooser JToolTip JTree JTable JTableHeader JInternalFrame JProgressBar JSpinner
2 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 2 of 12 Need a Container object in which to place UI components - will use JFrame. JFrame a window that cannot be put inside another window components can be added to a frame s content pane (getcontentpane() instance method) using method add First, a simple example: Create a window with a Label, TextField and 2 buttons, Hi and Exit. /** * Simple Java program displaying a window. */ import java.awt.container; import java.awt.flowlayout; import javax.swing.*; public class SimpleFrame extends JFrame { private JButton hi = new JButton("Hi"); private JButton exit = new JButton("Exit"); private JTextField tf = new JTextField(10); public SimpleFrame (){ // recall, the no arg constructor of superclas, // i.e. JFrame gets called here. this.setsize(450, 100); this.settitle("simple Frame example"); this.setlocation(300, 300); this.setdefaultcloseoperation(exit_on_close); // tell it how to lay out components this.setlayout(new FlowLayout()); // add components this.add(new JLabel("Enter your name")); this.add(tf); this.add(hi); this.add(exit); this.setvisible(true); public static void main(string[] args) { // instantiate the class, will display a window new SimpleFrame(); Common pitfalls: Don t forget to set a layout Don t forget to make the frame visible Otherwise the window will not show all components or may not show at all! - 2 -
3 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 3 of 12 Examples: some things that are commonly done: JLabel: JLabel l = new JLabel( Put text here ); l.settext( Change it here ); JTextFields: JTextField t1 = new JTextField(25); JTextField t2 = new JTextField( Balance, 20); t1.settext( Deposit ); // set content String s = t2.gettext(); // retrieve content t1.seteditable(false); // user can t change contents JTextArea: JTextArea a1 = new JTextArea(10, 25); // rows, cols JTextArea a2 = new JTextArea( list accounts:, 10, 25); a1.settext( account 1 ); // replace content a1.append( account 2 ); // append to content a2.append( account 1 ); // append to content a1.seteditable(false); // user can t change contents JList: Object [] oarray = ; JList l = new JList(oArray); Object o = l. getselectedvalue(); JRadioButton and ButtonGroups: JRadioButton add = new JRadioButton("Addition", true); JRadioButton subtract=new JRadioButton("Subtraction", false); The isselected() method returns true if the RadioButton is selected, and false otherwise. Add a component of type ButtonGroup to ensure to groups radio buttons so only 1 can be selected at any given time: ButtonGroup operations = new ButtonGroup(); operations.add(add); operations.add(subtract); A Visual Guide to Swing Components:
4 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 4 of 12 Event Handling An event can be defined as a type of signal to the program that something has happened. The event is generated by external user actions such as mouse movements, mouse clicks, and keystrokes, or by the operating system, e.g. a timer event. Source Event Type User Action Object Generated Click a button JButton ActionEvent Click a check box JCheckBox ItemEvent, ActionEvent Click a radio button JRadioButton ItemEvent, ActionEvent Press return on a text field JTextField ActionEvent Select a new item JComboBox ItemEvent, ActionEvent Window opened, closed, etc. Window WindowEvent Mouse pressed, released, etc. Component MouseEvent Mouse moved, dragged. Component MouseMotionEvent Key released, pressed, etc. Component KeyEvent User input through UI Components is processed via event-handling mechanism: Program waits for events to occur and then responds Firing an event when a source object generates an event Listener object that receives a notification of an event occurring. Event handler method that gets called in response to an event Listener Object must implement the appropriate Event handler method, specified by an in an appropriate listener interface (e.g. ActionListener, ItemListener, MouseEventListener, etc..) An event object contains whatever properties are pertinent to the event (the source component that fired the event, the time, etc ) You can identify the source object of the event using the getsource() instance method in the EventObject class Handling ActionEvents (generated by button-clicks, presses of Enter in TextArea, etc..) Register receiver (e.g. MathQuiz) as the listener object for the Button (or other source object). source.addactionlistener(receiver); The listener object (e.g.mathquiz ) must implement the ActionListener interface, i.e. provide definition of method public void actionperformed(actionevent e) Simple example: extending the SimpleFrame to react to ActionEvents - 4 -
5 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 5 of 12 /** * Simple Java program displaying a window.reacts to ActionEvents */ import java.awt.*; import javax.swing.*; public class SimpleFrame extends JFrame implements ActionListener { private JButton hi = new JButton("Hi"); private JButton exit = new JButton("Exit"); private JTextField tf = new JTextField(10); public SimpleFrame (){ // recall, the no arg constructor of superclas, // i.e. JFrame gets called here. this.setsize(450, 100); this.settitle("simple Action Listener"); this.setlocation(300, 300); this.setdefaultcloseoperation(exit_on_close); // tell it how to lay out components this.setlayout(new FlowLayout()); // add components this.add(new JLabel("Enter your name")); this.add(tf);this.add(hi); this.add(exit); // register this as a listener to action events // from the following components tf.addactionlistener(this); hi.addactionlistener(this); exit.addactionlistener(this); this.setvisible(true); /** Method required by the ActionListener interface * Is passed in an event as a parameter. * Performs an action based on the source of event. */ public void actionperformed(actionevent event) { if (event.getsource() == hi){ // hi button was pressed System.out.println("Hi, " + tf.gettext() + "!"); else if (event.getsource() == exit) { // exit button was pressed System.out.println("Bye, " + tf.gettext() + "!"); System.exit(0); else if (event.getsource() == tf) { // user pressed enter in the text field System.out.println("Nice to meet you, " + tf.gettext() + "!"); public static void main(string[] args) { // instantiate the class, will display a window new SimpleFrame(); - 5 -
6 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 6 of 12 Problem: create a simple graphical MathQuiz program that displays random problems, allows user to enter their answer, checks correctness. JRadioButton JLabel JButton JTextBox JTextArea /** MathQuizWindow.java The class implements a window with GUI components Shows how to add components to a frame. */ import java.awt.*; // helper classes like Color, LayoutManager, etc. import javax.swing.*; // library of components public class MathQuizWindow extends JFrame { // Define instance vars, simultaneously initializing them // by calling an appropriate constructor private JLabel label = new JLabel("Enter answer"); private JLabel lquestion = new JLabel(" a problem "); // to let user enter answer private JTextField tfanswer = new JTextField(15); cols //to show if correct or not, and correct answer if wrong private JTextArea answers = new JTextArea(2,20); //2 rows, 20 private JButton question = new JButton("Get question"); private JButton answer = new JButton("Submit"); private JButton exit = new JButton("Exit"); private JRadioButton add = new JRadioButton("Addition", true); private JRadioButton subtract = new JRadioButton("Subtraction", false); - 6 -
7 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 7 of 12 /** Constructor */ public MathQuizWindow (){ // recall: default superclass no-args // constructor is called here (i.e. JFrame ()) // creates a frame, initially invisible // set a few properties of the frame window this.setsize(250, 270); this.settitle("simple Math Quiz"); this.setdefaultcloseoperation(exit_on_close); //TO add the components to the container pane of the frame // 2. tell the frame how to arrange components: // using FlowLayout, componentes arranged around the center // by default this.setlayout(new FlowLayout()); // add radio buttons this.add(add); this.add(subtract); // Group radio buttons together in a group // to ensure *single* selection at any time: ButtonGroup operations = new ButtonGroup(); operations.add(add); operations.add(subtract); // add other components this.add(question); this.add(lquestion); lquestion.setforeground(color.blue); this.add(label); this.add(tfanswer);this.add(answer); this.add(answers); this.add(exit); this.setvisible(true); public static void main(string[] args) { // Create an instance of the Math Quiz new MathQuizWindow (); Result: A frame that contains GUI components, but doesn t do anything in response - 7 -
8 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 8 of 12 If window is resized, components may be repositions relatively to each other because FlowLayout was used. To ensure relative positioning is the same use LayoutManager objects. Example: add functionality to the MathQuiz class on pages 4-5 to 1. Display a problem (see class Problem) in the TextField tfquestion when the Get Question button is pressed, according to the operation selected with the radio buttons. At the same time clear tfanswer and set cursor there. 2. Read contents of TextField tfanswer when the answer button is pressed, at the same time, display if answer was correct in the text area answers. /** Class Problem. Creates an arithmetical problem */ public class Problem { private int op1; private int op2; private char operator; // generate random operators public Problem(char operator){ this.op1 = 1+(int)(20 * Math.random()); //between 1 and 20 this.op2 = 1+(int)(20 * Math.random()); //between 1 and 20 this.operator = operator; // generate math problem public int getanswer(){ int answer; if (this.operator == '+') answer = op1 + op2; else if (this.operator == '-') answer = op1 - op2; else - 8 -
9 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 9 of 12 answer = op1 * op2; return answer; public String tostring(){ return op1 + " " + operator + " " + op2 + " =??"; public static void main (String [] args){ Problem p1 = new Problem('+'); System.out.println (p1); System.out.println (p1.getanswer()); Layout Managers Every container (JFrame, JPanel, JDialog) contains a LayoutManager object that determines relative positioning and size of components inside a container. Layout managers are assigned to a container using the setlayout(layoutmanager) method of a container. E.g. of LayoutManagers are FlowLayout, BorderLayout, GridLayout, GridBagLayout, and more classes. Useful tutoorilal on which to use and how: BorderLayout manager arranges components into five areas: East, South, West, North, and Center. Components are added to a BorderLayout by using the add method with an appropriate constraint add(component, constraint), where constraint is BorderLayout.EAST, BorderLayout.SOUTH, BorderLayout.WEST, BorderLayout.NORTH, or BorderLayout.CENTER. GridLayout manager arranges components in a grid (matrix) formation with the number of rows and columns defined by the constructor. Cosntructors: public GridLayout(int rows, int columns) - 9 -
10 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 10 of 12 Useful technique: Constructs a new GridLayout with the specified number of rows and columns. public GridLayout(int rows, int columns, int hgap, int vgap) Constructs a new GridLayout with the specified number of rows and columns, along with specified horizontal and vertical gaps between components. The components are placed in the grid from left to right starting with the first row, then the second, and so on. Can place components to panels (objects of type JPanel).You can also place panels in a panel. Then add those panels to the frame s (JFrame) content pane. Frame s contentpane Has BorderLayout questionpanel with 2 by 2 GridLayout answerpanel with FlowLayout, centered
11 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 11 of 12 /** The class implements a window with GUI components Shows how to add components in panels, using different layout managers. */ import java.awt.*; import javax.swing.*; // library of components public class MathQuizWindowWithPanels extends JFrame{ // Define instance vars, simultaneously initializing them private JLabel label = new JLabel("Enter answer"); private JLabel lquestion = new JLabel(" a problem "); // to let user enter answer private JTextField tfanswer = new JTextField(15); //to show if correct or not, and correct answer if wrong private JTextArea answers = new JTextArea (2, 20); private JButton question = new JButton("Get question"); private JButton answer = new JButton("Submit"); private JButton exit = new JButton("Exit"); private JRadioButton add = new JRadioButton("Addition", true); private JRadioButton subtract=new JRadioButton("Subtraction", false); /** Constructor */ public MathQuizWindowWithPanels (){ // recall: default superclass no-args // constructor is called here // creates a frame, initially invisible // set a few properties of the window this.setsize(350, 200); this.settitle("simple Math Quiz"); //TO add the components to the container pane of the frame // 1. get the content pane of the JFrame Container contentpane = this.getcontentpane(); // 2. tell the pane how to arrange components: //using BorderLayout with specified horiz. and vert.spacing contentpane.setlayout(new BorderLayout(5, 10)); JPanel questionpanel = createquestionpanel(); contentpane.add(questionpanel, BorderLayout.NORTH); JPanel answerpanel = createanswerpanel(); contentpane.add(answerpanel, BorderLayout.CENTER); contentpane.add(exit, BorderLayout.SOUTH); this.setvisible(true);
12 Handout 12 CS603 Object-Oriented Programming Fall 15 Page 12 of 12 /** Creates a panel with question-related componenets */ private JPanel createquestionpanel(){ // create a panel JPanel qpanel = new JPanel(); // tell it to arrange components in 2 by 2 grid qpanel.setlayout(new GridLayout(2,2, 10, 10)); // add components to the panel in order left->right // top -> bottom // add radio buttons qpanel.add(add); qpanel.add(subtract); qpanel.add(question); lquestion.setforeground(color.blue); qpanel.add(lquestion); // Group radio buttons together in a group // to ensure *single* selection at any time: ButtonGroup operations = new ButtonGroup(); operations.add(add); operations.add(subtract); return qpanel; /** Creates a panel with answer-related componenets */ private JPanel createanswerpanel(){ // create a panel JPanel apanel = new JPanel(); apanel.setlayout(new FlowLayout()); apanel.add(label); apanel.add(tfanswer); apanel.add(answer); apanel.add (answers); return apanel; public static void main(string[] args) { // Create an instance of the Math Quiz new MathQuizWindowWithPanels ();
Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff
Swing UI by Vlad Costel Ungureanu for Learn Stuff User Interface Command Line Graphical User Interface (GUI) Tactile User Interface (TUI) Multimedia (voice) Intelligent (gesture recognition) 2 Making the
More informationChapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.
Chapter 13 GUI Basics 1 Motivations The design of the API for Java GUI programming is an excellent example of how the object-oriented principle is applied. In the chapters that follow, you will learn the
More informationChapter 12 GUI Basics. Motivations. The design of the API for Java GUI programming
Chapter 12 GUI Basics 1 Motivations The design of the API for Java GUI programming is an excellent example of how the object-orientedoriented principle is applied. In the chapters that follow, you will
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 informationLearn Java Programming, Dr.Hashamdar. Getting Started with GUI Programming
Learn Java Programming, Dr.Hashamdar Getting Started with GUI Programming 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your
More informationChapter 12 GUI Basics
Chapter 12 GUI Basics 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblname = new JLabel("Enter your
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 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 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 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 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 informationuser-friendly and easy to use.
Java Graphic User Interface GUI Basic Dr. Umaporn Supasitthimethee Computer Programming II -2- Java GUI A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires
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 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 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 Lecturer: Michael Hotan slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,
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 6: Graphical User Interfaces
Chapter 6: Graphical User Interfaces CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 6: Graphical User Interfaces CS 121 1 / 36 Chapter 6 Topics
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 information2110: GUIS: Graphical User Interfaces
2110: GUIS: Graphical User Interfaces Their mouse had a mean time between failure of a week it would jam up irreparably, or... jam up on the table--... It had a flimsy cord whose wires would break. Steve
More informationJava IDE Programming-I
Java IDE Programming-I Graphical User Interface : is an interface that uses pictures and other graphic entities along with text, to interact with user. User can interact with GUI using mouse click/ or
More informationSwing. By Iqtidar Ali
Swing By Iqtidar Ali Background of Swing We have been looking at AWT (Abstract Window ToolKit) components up till now. Programmers were not comfortable when doing programming with AWT. Bcoz AWT is limited
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 informationIntroduction 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 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 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 informationIntroduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p.
Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p. 17 MVC Architecture p. 19 The MVC Architecture p. 20 Combined
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 informationChina Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert
Java Programming in Java Java Swing Programming Java Swing Design Goals The overall goal for the Swing project was: To build a set of extensible GUI components to enable developers to more rapidly develop
More informationChapter 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 informationGraphical User Interfaces in Java - SWING
Graphical User Interfaces in Java - SWING Graphical User Interfaces (GUI) Each graphical component that the user can see on the screen corresponds to an object of a class Component: Window Button Menu...
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 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 informationPackages: 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 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 informationIntroduction. 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 informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 10(b): Working with Controls Agenda 2 Case study: TextFields and Labels Combo Boxes buttons List manipulation Radio buttons and checkboxes
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 informationGraphics. Lecture 18 COP 3252 Summer June 6, 2017
Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple
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 informationJava. 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 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 informationThe Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).
The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT) was part of the JDK form the beginning,
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 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 informationJava 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 information2010 가을학기부산대학교정보컴퓨터공학부 OVERVIEW OF GUI PROGRAMMING
2010 가을학기부산대학교정보컴퓨터공학부 OVERVIEW OF GUI PROGRAMMING Outline Graphic User Interface (GUI) Introduction AWT and Swing Graphics Programming Event Handling User Interface Components with Swing 2 Graphic User
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 informationGUI in Java TalentHome Solutions
GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator
More informationLecture 18 Java Graphics and GUIs
CSE 331 Software Design and Implementation The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction Lecture 18 Java Graphics and GUIs None
More informationJava: 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 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 informationUnit 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 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 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 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 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 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 informationJava Graphical User Interfaces
Java Graphical User Interfaces 1 The Abstract Windowing Toolkit (AWT) Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT)
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 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 informationTop-Level Containers
1. Swing Containers Swing containers can be classified into three main categories: Top-level containers: JFrame, JWindow, and JDialog General-purpose containers: JPanel, JScrollPane,JToolBar,JSplitPane,
More informationParts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.
Parts of a Contract Syntax - Method signature Method name Parameter list Return type Semantics - Comments Preconditions: requirements placed on the caller Postconditions: what the method modifies and/or
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 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 informationCSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Java Graphics and GUIs 1 The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction
More informationChapter 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 informationJava & 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 informationIntroduction to Graphical Interface Programming in Java. Introduction to AWT and Swing
Introduction to Graphical Interface Programming in Java Introduction to AWT and Swing GUI versus Graphics Programming Graphical User Interface (GUI) Graphics Programming Purpose is to display info and
More informationINTRODUCTION TO (GUIS)
INTRODUCTION TO GRAPHICAL USER INTERFACES (GUIS) Lecture 10 CS2110 Fall 2009 Announcements 2 A3 will be posted shortly, please start early Prelim 1: Thursday October 14, Uris Hall G01 We do NOT have any
More informationJava 11 Swing with Eclipse Index
One Introduction to Java 1 Usage of Java 2 Structure of Java 4 Flexibility of Java Programming 5 Swing and AWT in Java 7 Using Eclipse 9 Two Dialog Boxes 10 Using Dialog Boxes 11 Using Message Dialogs
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded
More informationAgenda. 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 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 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 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 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 informationBuilding 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 informationTogether, the appearance and how user interacts with the program are known as the program look and feel.
Lecture 10 Graphical User Interfaces A graphical user interface is a visual interface to a program. GUIs are built from GUI components (buttons, menus, labels etc). A GUI component is an object with which
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 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 informationJava 1.9 Swing Index
One Introduction to Java 2 Usage of Java 3 Structure of Java 4 Flexibility of Java Programming 5 Swing and AWT in Java 6 Two Using Java in DOS 9 Using the DOS window 10 DOS Operating System Commands 11
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
Graphical User Interfaces CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Overview Command line versus GUI apps
More informationObject-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III
Electrical and Computer Engineering Object-Oriented Topic : User Interface Components with Swing GUI Part III Maj Joel Young Joel.Young@afit.edu 17-Sep-03 Maj Joel Young Creating GUI Apps The Process Overview
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 informationJava 11 Swing Index. Section Title Page
One Introduction to Java 2 Usage of Java 3 Structure of Java 4 Flexibility of Java Programming 5 Swing and AWT in Java 6 Two Using Java in DOS 9 Using the DOS window 10 DOS Operating System Commands 11
More informationMIT 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 informationGoals. 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 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 informationJava 1.8 Swing with Eclipse Oxygen Index
One Introduction to Java 1 Usage of Java 2 Structure of Java 4 Flexibility of Java Programming 5 Using the Eclipse software 6 Swing and AWT in Java 7 Two Running Java in Eclipse 10 Introduction 11 Using
More informationJava 1.8 Swing with Eclipse Mars Index
One Introduction to Java 1 Usage of Java 2 Structure of Java 4 Flexibility of Java Programming 5 Using the Eclipse software 6 Swing and AWT in Java 7 Two Running Java in Eclipse 10 Introduction 11 Using
More informationJava 1.8 Swing with Eclipse Neon Index
One Introduction to Java 1 Usage of Java 2 Structure of Java 4 Flexibility of Java Programming 5 Using the Eclipse software 6 Swing and AWT in Java 7 Two Running Java in Eclipse 10 Introduction 11 Using
More informationGraphical 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 informationContents Chapter 1 Introduction to Programming and the Java Language
Chapter 1 Introduction to Programming and the Java Language 1.1 Basic Computer Concepts 5 1.1.1 Hardware 5 1.1.2 Operating Systems 8 1.1.3 Application Software 9 1.1.4 Computer Networks and the Internet
More informationCPS122 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 informationSwing Programming Example Number 2
1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon
More informationCompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons
CompSci 125 Lecture 17 GUI: Graphics, Check Boxes, Radio Buttons Announcements GUI Review Review: Inheritance Subclass is a Parent class Includes parent s features May Extend May Modify extends! Parent
More informationAnnouncements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation
CSE 331 Software Design and Implementation Lecture 18 Java Graphics and GUIs Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 6 due Thursday 8/2 Homework 7 due Thursday 8/2 Regression testing
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 information