OBJECT ORIENTED PROGRAMMING. Java GUI part 1 Loredana STANCIU Room B616
|
|
- Derrick Bishop
- 5 years ago
- Views:
Transcription
1 OBJECT ORIENTED PROGRAMMING Java GUI part 1 Loredana STANCIU loredana.stanciu@upt.ro Room B616
2 What is a user interface That part of a program that interacts with the user of the program: simple command-line interfaces point-and-click graphical user interfaces A common set of tools for graphical user interface design that work on a variety of platforms A user interface toolkit called the Abstract Windowing Toolkit, or the AWT
3 Components and containers A graphical user interface is built of graphical elements called components: buttons, scrollbars, and text fields Components do not stand alone, but rather are found within containers. Contain and control the layout of components
4 Components and containers Components must fit completely within the container Creates a tree of elements, starting with the container at the root of the tree and expanding out to the leaves
5 GUI Graphical User interface
6 Types of components
7 Types of components
8 Button Button() Creates a button Button(String label) Creates a labeled button void addactionlistener(actionlistener l) Adds the specified action listener to receive action events from this button.
9 Button String getlabel() Gets the label of the current button. void setlabel(string label) Sets the button's label to be the specified string.
10 Button example You can create a button by creating an instance of the Button class: Button buttonone = new Button(); Button buttonone = new Button("This is a button"); You can add a button to a frame by using the add() method: aframe.add(buttonone);
11 CheckBox A graphical component that can be in either an "on" (true) or "off" (false) state. setlayout(new GridLayout(3, 1)); add(new Checkbox("one", null, true)); add(new Checkbox("two")); add(new Checkbox("three"));
12 CheckBox Checkbox() Creates a check box with no label Checkbox(String label) Creates a check box with the specified label Checkbox(String label, boolean state) Creates a check box with the specified label and sets the specified state Checkbox(String label, CheckboxGroup group, boolean state,) Creates a check box with the label, set to the state, and in the check box group
13 CheckBox void additemlistener (ItemListener l) Adds the specified item listener to receive item events from this check box. String getlabel() Gets the label of this check box. Boolean getstate() Determines whether this check box is in the "on" or "off" state
14 CheckBox void setcheckboxgroup(checkboxgroup g) Sets this check box's group to be the specified check box group. void setlabel(string label) Sets this check box's label to be the string argument. void setstate(boolean state) Sets the state of this check box to the specified state.
15 CheckboxGroup Used to group together a set of Checkbox buttons. Exactly one check box button in a CheckboxGroup can be in the "on" state at any given time Pushing any button sets its state to "on" and forces any other button that is in the "on" state into the "off" state
16 CheckboxGroup Example setlayout(new GridLayout(3, 1)); CheckboxGroup cbg = new CheckboxGroup(); add(new Checkbox("one", cbg, true)); add(new Checkbox("two", cbg, false)); add(new Checkbox("three", cbg, false));
17 Chioce A pop-up menu of choices. The current choice is displayed as the title of the menu. Choice ColorChooser = new Choice(); ColorChooser.add("Green"); ColorChooser.add("Red"); ColorChooser.add("Blue");
18 Chioce Choice() Creates a new choice menu. void add(string item) Adds an item to this Choice menu. void additemlistener(itemlistener l) Adds the specified item listener to receive item events from this Choice menu. String getitem(int Index) Gets the string at the specified index in this Choice menu.
19 Chioce int getitemcount() Returns the number of items in this Choice menu. int getselectedindex() Returns the index of the currently selected item. String getselecteditem() Gets a representation of the current choice as a string.
20 Chioce void insert(string item, int index) Inserts the item into this choice at the specified position. void remove(int position) Removes an item from the choice menu at the specified position. void remove(string item) Removes the first occurrence of item from the Choice menu.
21 Chioce void removeall() Removes all items from the choice menu. void select(int position) Sets the selected item in this Choice menu to be the item at the specified position. void select(string str) Sets the selected item in this Choice menu to be the item whose name is equal to the specified string.
22 Label A component for placing text in a container. Displays a single line of read-only text. setlayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); add(new Label("Hi There!")); add(new Label("Another Label"));
23 Label Label(String text); Creates a new instance of Label String gettext(); Returns a label s text void settext(string text); Sets a label s text to the specified text
24 Scrollbar Provides a convenient means for allowing a user to select from a range of values. redslider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255); add(redslider); ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300); add(ranger);
25 Scrollbar Scrollbar() Constructs a new vertical scroll bar. Scrollbar(int orientation) Constructs a new scroll bar with the specified orientation.
26 Scrollbar Scrollbar(int orientation, int value, int visible, int minimum, int maximum) Constructs a new scroll bar with the specified orientation, initial value, visible amount, and minimum and maximum values. void addadjunstmentlistener(adjust mentlistener l) Adds the specified adjustment listener to receive instances of AdjustmentEvent from this scroll bar.
27 TextField A text component that allows for the editing of a single line of text. TextField tf1, tf2, tf3, tf4; tf1 = new TextField(); tf2 = new TextField("", 20); tf3 = new TextField("Hello!"); tf4 = new TextField("Hello", 30);
28 TextField TextField() Creates a new instance of TextField TextField(String text) Creates a new instance of TextField with the specified text void setcolumns(int columns) Sets the number of columns in a textbox void settext(string text) Sets a textfield text to the specified text
29 List A scrolling list of text items. The list can be set up so that the user can choose either one item or multiple items. List lst = new List(4, false); lst.add("mercury"); lst.add("venus"); lst.add("earth"); lst.add("javasoft"); lst.add("mars"); lst.add("jupiter"); lst.add("saturn"); lst.add("uranus"); lst.add("neptune"); lst.add("pluto");
30 List List() Creates a new scrolling list. List(int row) Creates a new scrolling list initialized with the specified number of visible lines. List(int rows, boolean multiplemode) Creates a new scrolling list initialized to display the specified number of rows.
31 List void add(string item) Adds the specified item to the end of scrolling list. void add(string item, int index) Adds the specified item to the the scrolling list at the position indicated by the index. void addactionlistener(actionlistener l) Adds the specified action listener to receive action events from this list.
32 List void remove( int position) Removes the item at the specified position from this scrolling list. void remove( String item) Removes the first occurrence of an item from the list. void removeall() Removes all items from this list.
33 List void replaceitem(string value, int index) Replaces the item at the specified index in the scrolling list with the new string. void select(int index) Selects the item at the specified index in the scrolling list.
34 TextArea A multi-line region that displays text. It can be set to allow editing or to be read-only. new TextArea("Hello", 5, 40);
35 TextArea TextArea(int rows, int columns) Constructs a new text area with the specified number of rows and columns and the empty string as text. TextArea(String text) Constructs a new text area with the specified text. TextArea(String text, int rows, int columns) Constructs a new text area with the specified text, and with the specified number of rows and columns.
36 TextArea TextArea(String text, int rows, int columns, int scrollbars) Constructs a new text area with the specified text, and with the rows, columns, and scroll bar visibility as specified. void append(string str) Appends the given text to the text area's current text. void insert(string str, int position) Inserts the specified text at the specified position in this text area.
37 Types of containers Window A top-level display surface (a window) An instance of the Window class has no border and no title Frame A top-level display surface (a window) with a border and title An instance of the Frame class may have a menu bar
38 Types of containers Dialog A top-level display surface (a window) with a border and title An instance of the Dialog class cannot exist without an associated instance of the Frame class. Panel A generic container for holding components. An instance of the Panel class provides a container to which to add components.
39 FRAMES A top-level window with a title and a border. It has minimize, maximize, and close buttons in its top right corner and can be moved and resized (by default) Frames are created using the Frame class
40 FRAMES Frame() Creates a new instance of Frame that is initially invisible Frame(String title) Creates a new instance of Frame that is initially invisible with the specified title NOTE: Initially, a frame will not be visible. You have to set it to be visible using the setvisible() method
41 FRAMES boolean isresizable() Returns a boolean value indicating whether a frame is resizable or not void setresizable(boolean resizable) Sets whether or not a frame is resizable void isvisible(boolean isvisible) Sets whether or not a frame is visible
42 FRAMES String gettitle() Returns the title of a frame void settitle(string title) Sets the title of a frame void setsize(int width, int height) Sets the size of a frame void setlocation(int xcoord, int ycoord) Sets the location of the window
43 Frames Frames are capable of generating the following types of WindowEvents: WINDOW_OPENED WINDOW_CLOSING WINDOW_CLOSED WINDOW_ICONIFIED WINDOW_DEICONIFIED WINDOW_ACTIVATED WINDOW_DEACTIVATED WINDOW_GAINED_FOCUS WINDOW_LOST_FOCUS WINDOW_STATE_CHANGED
44 Frames Example You can create a frame creating an instance of class Frame: import java.awt.*; class MyFrame { public static void main(){ Frame frame = new Frame("My title"); frame.setsize(200, 200); frame.setvisible(true); }}
45 Dialog A top-level window with a title and a border that is typically used to take some form of input from the user. The size of the dialog includes any area designated for the border. A dialog must have either a frame or another dialog defined as its owner when it's constructed.
46 Dialog Dialog(Dialog owner) Constructs an initially invisible, non-modal Dialog with an empty title and the specified owner dialog. Dialog(Dialog owner, String title) Constructs an initially invisible, non-modal Dialog with the specified owner dialog and title. Dialog(Frame owner) Constructs an initially invisible, non-modal Dialog with an empty title and the specified owner frame.
47 Dialog Dialog(Frame owner, String title) Constructs an initially invisible, non-modal Dialog with the specified owner frame and title. String gettitle() Gets the title of the dialog. void hide() Hides the Dialog and then causes show() to return if it is currently blocked.
48 Dialog void show() Makes the Dialog visible. void setresizable(boolean resizable) Sets whether this dialog is resizable by the user. void settitle(string title) Sets the title of the Dialog.
49 Panel The simplest container class Provides space in which an application can attach any other component, including other panels. The default layout manager for a panel is the FlowLayout layout manager.
50 Panel Panel() Creates a new panel using the default layout manager. Panel(LayoutManager layout) Creates a new panel with the specified layout manager. void add( ) Add a component to the panel void remove( ) Remove a component from the panel
51 Creating a container When building an application, the programmer must first create an instance of class Window or class Frame import java.awt.*; public class Example1 { public static void main(string [] args) { } } Frame f = new Frame("Example 1"); f.show();
52 Java GUI Layout Creating a graphical user interface and elements for it alone is not enough, you have to know where and how to place these graphical elements There are classes called layout managers, which decide where and how components will be placed Layout manager classes are located in the java.awt package
53 Flowlayout Arranges components in a left-to-right flow, much like lines of text in a paragraph. Flow layouts are typically used to arrange buttons in a panel. It will arrange buttons left to right until no more buttons fit on the same line. Each line is centered.
54 Flowlayout FlowLayout() Creates a new instance of FlowLayout FlowLayout(int align) Creates a new instance of FlowLayout with the specified alignment. Possible values: CENTER LEADING LEFT WRITE
55 Flowlayout FlowLayout(int align, int hgap, int vgap) Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps. You can set a frame to use FlowLayout by using the setlayout() method: frame.setlayout(new FlowLayout());
56 Flowlayout Example
57 GridLayout Is used to arrange components in a grid of equally sized rectangular cells GridLayout() Creates a new GridLayout which has one row by default GridLayout(int rows, int columns) Creates a new GridLayout with the specified number of rows and columns
58 GridLayout You can set a frame to use GridLayout by using the setlayout() method: frame.setlayout(new GridLayout(2,2);
59 Borderlayout Lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER Components start at their preferred size, but are expanded as needed to fill the region they are in
60 Borderlayout BorderLayout() The default constructor (no space between regions) BorderLayout(int hnp, int vnp) A constructor which specifies the number of pixels between regions You can set a frame to use BorderLayout by using the setlayout() method: frame.setlayout(new BorderLayout(5,5);
61 Borderlayout When an element is added, the location of that element must be specified: frame.add( North,buttonOne);
62 Java event handling Event handling in Java refers to executing some code when specific actions occur such as a window being minimized or a button being clicked There are special interfaces for this purpose and they are located in the java.awt.event package
63 Handling window events To handle window events, the WindowListener interface is used The class that handle window events must implement this interface The WindowListener interface has various methods to handle window events These methods are presented on the following slides
64 Methods of the WindowListener interface windowopened(windowevent e) Called when a window first becomes visible windowactivated(windowevent e) Called when a window has become active (meaning it is able to accept input events) windowdeactivated(windowevent e) Called when a window is deactivated (meaning it has lost input focus)
65 Methods of the WindowListener interface windowiconified(windowevent e) Called when a window is iconified (minimized) windowdeiconified(windowevent e) Called when a window has been restored from a minimized state windowclosing(windowevent e) Called when a user attempts to close a frame windowclosed(windowevent e) Called when a window is closed
66 Handling action events To handle action events (such as the clicking of a button), the ActionListener interface is used Method of the ActionListener interface: actionperformed(actionevent e) Called when an action has occurred
67 Handling focus events To handle focus events (such as when an object such as a textbox is awaiting user input), the FocusListener interface is used Methods of the FocusListener interface: focusgained(focusevent e) Called when an object gains focus focuslost(focusevent e) Called when an object loses focus
68 Handling item events Item events are triggered by components that allow for a selection of items such as Checkboxes To handle item events, the ItemListener interface is used Method of the ItemListener interface: itemstatechanged(itemevent e) Called when the state of an item has changed
69 Handling text events Text events are triggered by components whose fields are editable such as textboxes To handle text events, the TextListener interface is used Method of the TextListener interface: textvaluechanged(textevent e) Called when the data in a field of a component has changed
70 Handling mouse events Mouse events are triggered by the computers mouse Mouse events are actually handled by two interfaces: MouseListener: used to detect the clicking of mouse buttons or the moving of a mouse into or out of a listener's area MouseMotionListener: used to detect the movement of the mouse
71 Methods of the MouseListener interface mouseclicked(mouseevent e) Called when a mouse button is clicked mouseentered(mouseevent e) Called when the mouse enters a source components area
72 Methods of the MouseMotionListener interface mousemoved(mouseevent e) Called when the mouse is moved while in a components area mousedragged(mouseevent e) Called when the mouse moves while a mouse button is down while within a components area
73 Handling key events Key events are triggered by keyboard actions Key events are handled by the KeyListener interface Methods of the KeyListener interface: keypressed(keyevent e) Called when a key is pressed down keyreleased(keyevent e) Called when a key is released keytyped(keyevent e) Called when a key is typed
74 Making objects listen for events Once you implement the necessary interfaces, and define the implementation of their methods, you need to make objects listen for events Example: if you implement the ActionListener interface, and you define what its actionperformed() method does, and you want the method to be called every time a certain button is clicked, you need to make that button listen for the event
75 Listen for action events For action events use the addactionlistener() method Example: //create a button Button abutton = new Button("This is a button"); //specify that this button listens for action events abutton.addactionlistener(this);
76 Listen for action events The class that contains the previous button must implement the interface ActionListener, so it will have a function actionperformed(actionevent e) You can find the source of this event calling the function e.getsource() This function will return an element of type Object
77 Listen for focus events For focus events use the addfocuslistener() method Example: //create a textbox TextField atextfield = new TextField("This is a textbox"); /*specify that this textbox listens for focus events*/ atextfield.addfocuslistener(this);
78 Listen for item events For item events use the additemlistener() method Example: //create a checkbox CheckBox chkbox1 = new CheckBox("This is a checkbox", false); /*specify that this checkbox listens for item events*/ chkbox1.additemlistener(this);
79 Listen for text events For text events use the addtextlistener() method Example: //create a textbox TextField atextfield = new TextField("This is a textbox"); /*specify that this textbox listens for text events*/ atextfield.addtextlistener(this);
80 Listen for mouse events For mouse events use the addmouselistener() method Example: //create a frame Frame aframe = new Frame(); /*specify that this frame listens for mouse events*/ aframe.addmouselistener(this);
81 Listen for mouse motion events For mouse motion events use the addmousemotionlistener() method Example: //create a frame Frame aframe = new Frame(); /*specify that this frame listens for mouse motion events*/ aframe.addmousemotionlistener(this);
82 Listen for key events For key events use the addkeylistener() method Example: //create a textbox TextField atextfield = new TextField("This is a textbox"); /*specify that this textbox listens for key events*/ atextfield.addkeylistener(this);
83 Problem Create a GUI in Java containing a TextField, a TextArea and a Choice. Clicking the button Save from text field, save the content of the TextField into the TextArea and clear the TextField. This operation can be done only if the button is enabled using a Checkbox. Clicking the button Save from choice save the current selection into the TextArea. If the content of the TextField is e stop the application.
84 Solution
85 Solution import java.awt.*; import java.awt.event.*; class MyFrame extends WindowAdapter implements KeyListener, ActionListener, ItemListener{ Frame frame; TextField atextfield; TextArea atextarea; Checkbox be; Button b1,b2; Choice c1;
86 Solution public static void main(string []args){ MyFrame f = new MyFrame(); f.init(); } public void init(){ frame = new Frame( Problem C8"); frame.setsize(500, 350); frame.setvisible(true); frame.addwindowlistener(this); frame.setlayout(new BorderLayout(5,5));...
87 Solution... Panel p1 = new Panel(); p1.setlayout(new GridLayout(2,2,10,10)); Panel p2 = new Panel(); p2.setlayout(new FlowLayout()); b1 = new Button("Save from text field"); b1.setenabled(false); p1.add(b1); b1.addactionlistener(this); p1.add(be = new Checkbox("Button enable", null, false)); be.additemlistener(this);...
88 Solution... b2 = new Button("Save from choice"); b2.addactionlistener(this); p1.add(b2); Label l = new Label("Enter text"); p2.add(l); atextfield = new TextField("",20); p2.add(atextfield); Label l2 = new Label("Select"); p2.add(l2);...
89 Solution... c1 = new Choice(); c1.add("object"); c1.add("oriented"); c1.add("programming"); p2.add(c1); frame.add("north",p2); Label l3 = new Label("Save resuls here"); frame.add("west",l3); frame.add("east",new Label(" ")); atextarea = new TextArea("",10,20); frame.add("center",atextarea); atextfield.addkeylistener(this); frame.add("south",p1);}...
90 Solution... public void actionperformed(actionevent e){ if(e.getsource()==b1) { else atextarea.append(string.format("%s\n", atextfield.gettext())); atextfield.settext("");} TextArea.append(String.format("%s\n",c1. getselecteditem()))}...
91 Solution... public void itemstatechanged(itemevent e){ if(e.getstatechange()==1) b1.setenabled(true); else b1.setenabled(false);} public void keytyped(keyevent e){ if(e.getkeychar()=='e'&& b1.isenabled()) System.exit(0);} public void keyreleased(keyevent e){} public void keypressed(keyevent e){} public void windowclosing(windowevent e) { System.exit(0); }}
92 References Todd Sundsted, Introduction to the AWT. A description of Java s user interface toolkit,
GUI 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 informationJava AWT Windows, Text, & Graphics
2 AWT Java AWT Windows, Text, & Graphics The Abstract Windows Toolkit (AWT) contains numerous classes and methods that allow you to create and manage applet windows and standard windows that run in a GUI
More informationChapter 1 GUI Applications
Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations
More informationAdvanced Java Programming (17625) Event Handling. 20 Marks
Advanced Java Programming (17625) Event Handling 20 Marks Specific Objectives To write event driven programs using the delegation event model. To write programs using adapter classes & the inner classes.
More informationHandling Mouse and Keyboard Events
Handling Mouse and Keyboard Events 605.481 1 Java Event Delegation Model EventListener handleevent(eventobject handleevent(eventobject e); e); EventListenerObject source.addlistener(this);
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 informationThe AWT Event Model 9
The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow
More informationGraphical Interfaces
Weeks 11&12 Graphical Interfaces All the programs that you have created until now used a simple command line interface, which is not user friendly, so a Graphical User Interface (GUI) should be used. The
More informationExample Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.
COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization
More informationGUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline
Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example
More 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 informationBM214E Object Oriented Programming Lecture 13
BM214E Object Oriented Programming Lecture 13 Events To understand how events work in Java, we have to look closely at how we use GUIs. When you interact with a GUI, there are many events taking place
More informationกล ม API ท ใช. Programming Graphical User Interface (GUI) Containers and Components 22/05/60
กล ม API ท ใช Programming Graphical User Interface (GUI) AWT (Abstract Windowing Toolkit) และ Swing. AWT ม ต งต งแต JDK 1.0. ส วนมากจะเล กใช และแทนท โดยr Swing components. Swing API ปร บปร งความสามารถเพ
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 informationGraphical Interfaces
Weeks 9&11 Graphical Interfaces All the programs that you have created until now used a simple command line interface, which is not user friendly, so a Graphical User Interface (GUI) should be used. The
More 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 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 informationThe Abstract Window Toolkit
Chapter 12 The Abstract Window Toolkit 1 12.1 Overview Java s Abstract Window Toolkit provides classes and other tools for building programs that have a graphical user interface. The term Abstract refers
More informationCHAPTER 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 informationJava - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.
Java - Applications C&G Criteria: 5.3.2, 5.5.2, 5.5.3 Java applets require a web browser to run independently of the Java IDE. The Dos based console applications will run outside the IDE but have no access
More informationUnit - 2 Abstract Window Toolkit
Abstract Window Toolkit: (AWT) Java AWT is an API to develop GUI or window-based application in java. Java AWT provides many of user interface objects are called Components of the Java AWT. Java AWT components
More informationGUI Programming: Swing and Event Handling
GUI Programming: Swing and Event Handling Sara Sprenkle 1 Announcements No class next Tuesday My Fourth of July present to you: No quiz! Assignment 3 due today Review Collections: List, Set, Map Inner
More informationThe Java Programming Language Basics. Identifiers, Keywords, and Types. Expressions and Flow Control. Object-Oriented Programming. Objects and Classes
Building GUIs 8 Course Map This module covers setup and layout of graphical user interfaces. It introduces the Abstract Windowing Toolkit, a package of classes from which GUIs are built. Getting Started
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 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 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 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 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 informationH212 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 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 information11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events
Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes
More informationInteracción con GUIs
Interacción con GUIs Delegation Event Model Fuente EVENTO Oyente suscripción Fuente Oyente suscripción EVENTO Adaptador EVENTO java.lang.object java.util.eventobject java.awt.awtevent java.awt.event. ActionEvent
More informationOverloading Example. Overloading. When to Overload. Overloading Example (cont'd) (class Point continued.)
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String tostring() () void move(int dx,int dy) (int,int) void paint(graphicsg) (Graphics)
More information10/11/18. Introduction Panel Class Window Class Dialog class FileDialog class Menu, MenuItem class
A.Prof. Tran Van Lang, PhD Vietnam Academy of Science and Technology (VAST) Introduction Panel Class Window Class Dialog class FileDialog class Menu, MenuItem class Components A container is a component
More informationSri Vidya College of Engineering & Technology
UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language
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 informationSD Module-1 Advanced JAVA
Assignment No. 4 SD Module-1 Advanced JAVA R C (4) V T Total (10) Dated Sign Title: Transform the above system from command line system to GUI based application Problem Definition: Write a Java program
More informationSD Module-1 Advanced JAVA. Assignment No. 4
SD Module-1 Advanced JAVA Assignment No. 4 Title :- Transform the above system from command line system to GUI based application Problem Definition: Write a Java program with the help of GUI based Application
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 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 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 informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationGUI 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 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 AWT Component Library 10
The AWT Component Library 10 Course Map The JDK offers many components from which GUIs an be built. This module examines these AWT Components, and covers noncomponent AWT classes such as Color and Font,
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 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 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 informationJava Applets / Flash
Java Applets / Flash Java Applet vs. Flash political problems with Microsoft highly portable more difficult development not a problem less so excellent visual development tool Applet / Flash good for:
More informationProgramming Languages and Techniques (CIS120e)
Programming Languages and Techniques (CIS120e) Lecture 29 Nov. 19, 2010 Swing I Event- driven programming Passive: ApplicaHon waits for an event to happen in the environment When an event occurs, the applicahon
More informationGUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1)
Objectives Write code to handle events that occur in a GUI 11 GUI Event Handling Describe the concept of adapter classes, including how and when to use them Determine the user action that originated the
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 informationAWT DIALOG CLASS. Dialog control represents a top-level window with a title and a border used to take some form of input from the user.
http://www.tutorialspoint.com/awt/awt_dialog.htm AWT DIALOG CLASS Copyright tutorialspoint.com Introduction Dialog control represents a top-level window with a title and a border used to take some form
More informationComputer Programming Java AWT Lab 18
Computer Programming Java AWT Lab 18 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2015 DCSLab. All Rights Reserved Overview AWT Basic Use AWT AWT
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 informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview
More informationJava Control Fundamentals
Java Control Fundamentals This article continues our exploration of the Abstract Window Toolkit (AWT). It examines the standard controls defined by Java. Controls are components that allow a user to interact
More informationAdvanced Java Programming
Advanced Java Programming Shmulik London Lecture #5 GUI Programming Part I AWT & Basics Advanced Java Programming / Shmulik London 2006 Interdisciplinary Center Herzeliza Israel 1 Agenda AWT & Swing AWT
More informationAWT LIST CLASS. The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items.
http://www.tutorialspoint.com/awt/awt_list.htm AWT LIST CLASS Copyright tutorialspoint.com Introduction The List represents a list of text items. The list can be configured to that user can choose either
More informationUser interfaces and Swing
User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends
More informationGUI. Overview: JFC - Java Foundation Classes. JFC: Java Foundation Classes. Graphical User Interfaces. GUI-based Applications. containment hierarchy:
GUI Graphical User Interfaces Reference: A Programmer s Guide to Java Certification: A Comprehensive Primer Chapters 12, 13, 14, and 17 CS211, Spring 2000. KAM GUI.fm 1/64 GUI-based Applications Developing
More informationLaying Out Components. What is Widget Layout?
Laying Out Components Interior Design for GUIs What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position
More informationChapter 14. More Swing
Chapter 14 More Swing Menus Making GUIs Pretty (and More Functional) Box Containers and Box Layout Managers More on Events and Listeners Another Look at the Swing Class Hierarchy Chapter 14 Java: an Introduction
More informationAn Introduction To Graphical User Interfaces
An Introduction To Graphical User Interfaces The event-driven model Building simple graphical interfaces in Java Components They are all types of graphical controls and displays available: Button, Canvas,
More informationG51PRG: Introduction to Programming Second semester Applets and graphics
G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting
More informationWhat is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs
What is Widget Layout? Laying Out Components Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position Main problem: what if
More informationJava - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,
Java - Applets C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows
More informationUnit 2 Topic: Window Fundamentals Unit 2/Lecture 1
1 Unit 2 Topic: Window Fundamentals Unit 2/Lecture 1 Window Fundamentals In this Unit, you will learn how to create and manage windows, manage fonts, output text, and utilize graphics. It also describes
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 informationUNIT - 6 AWT SWINGS [ABSTARCT WINDOW TOOLKIT]
UNIT - 6 AWT [ABSTARCT WINDOW TOOLKIT] SWINGS Introduction to AWT AWT (Abstract Window Toolkit) was Java s first GUI framework, which was introduced in Java 1.0. It is used to create GUIs (Graphical User
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 information(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI
51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface
More informationAWT CHOICE CLASS. Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the menu.
http://www.tutorialspoint.com/awt/awt_choice.htm AWT CHOICE CLASS Copyright tutorialspoint.com Introduction Choice control is used to show pop up menu of choices. Selected choice is shown on the top of
More informationJAVA NOTES GRAPHICAL USER INTERFACES
1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the
More informationDr. Hikmat A. M. AbdelJaber
Dr. Hikmat A. M. AbdelJaber GUI are event driven (i.e. when user interacts with a GUI component, the interaction (event) derives the program to perform a task). Event: click button, type in text field,
More informationAim: Write a java program to demonstrate the use of following layouts. 1.FlowLayout 2.BorderLayout 3.GridLayout 4.GridBagLayout 5.
DEMONSTRATION OF LAYOUT MANAGERS DATE:09.07.11 Aim: Write a java program to demonstrate the use of following layouts. 1.FlowLayout 2.BorderLayout 3.GridLayout 4.GridBagLayout 5.CardLayout Hardware requirements:
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 2011 Extending JFrame Dialog boxes Overview Ge
More informationAWT CHECKBOX CLASS. Creates a check box with the specified label and sets the specified state.
http://www.tutorialspoint.com/awt/awt_checkbox.htm AWT CHECKBOX CLASS Copyright tutorialspoint.com Introduction Checkbox control is used to turn an option ontrue or offfalse. There is label for each checkbox
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 informationProgramming Mobile Devices J2SE GUI
Programming Mobile Devices J2SE GUI University of Innsbruck WS 2009/2010 thomas.strang@sti2.at Graphical User Interface (GUI) Why is there more than one Java GUI toolkit? AWT write once, test everywhere
More informationGUI DYNAMICS Lecture July 26 CS2110 Summer 2011
GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain
More informationencompass 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 informationTYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill
TYPES OF INTERACTORS Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill dewan@cs.unc.edu Code available at: https://github.com/pdewan/colabteaching PRE-REQUISITES Model-
More informationJava - Applets. public class Buttons extends Applet implements ActionListener
Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;
More informationCSE 8B Intro to CS: Java
CSE 8B Intro to CS: Java Winter, 2006 February 23 (Day 14) Menus Swing Event Handling Inner classes Instructor: Neil Rhodes JMenuBar container for menus Menus associated with a JFrame via JFrame.setMenuBar
More 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 informationCSA 1019 Imperative and OO Programming
CSA 1019 Imperative and OO Programming GUI and Event Handling Mr. Charlie Abela Dept. of of Artificial Intelligence Objectives Getting familiar with UI UI features MVC view swing package layout managers
More informationIndex SELF-STUDY. Symbols
SELF-STUDY 393 Index Symbols -... 239 "Event-to-property"... 144 "Faux" variables... 70 %... 239 ( )... 239 (Pme) paradigm... 14 *... 239 +... 239 /... 239 =... 239 = Null... 46 A A project... 24-25, 35
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for
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 informationJava Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,
Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also
More informationBuilding Graphical User Interfaces. GUI Principles
Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting
More informationMr. Nilesh Vishwasrao Patil. Advanced Java Programming: (17625)
Advanced Java Programming: (17625) 1 Teaching and Examination Scheme 2 AJP: Chapter Chapter # Chapter Name Marks (As per Syllabus) 01 Introduction to Abstract Windowing Toolkit(AWT) & Swings 24 02 Event
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 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 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 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 informationResizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.
COSC 3461: Module 5B Resizing a Window Widgets II What has changed? scrollbar added menu has wrapped toolbar modified (buttons lost) 2 What is Widget Layout? Size State Transitions Recall: each widget
More informationG51PGP 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