Advanced Java Programming
|
|
- Audrey Watson
- 5 years ago
- Views:
Transcription
1 Advanced Java Programming Shmulik London Lecture #5 GUI Programming Part I AWT & Basics Advanced Java Programming / Shmulik London 2006 Interdisciplinary Center Herzeliza Israel 1
2 Agenda AWT & Swing AWT components Containers Layout Managers Event Handling Painting Advanced Java Programming / Shmulik London
3 AWT & Swing Originally Java came with the AWT (Abstract Window Toolkit) AWT was very basic. Developers wanted more. Swing is a much richer API for GUI. They are built around different design concept AWT and Swing co-exist now, but you normally use Swing. Advanced Java Programming / Shmulik London
4 AWT AWT meant to be small and simple Allow easy porting to many platforms Developing GUI platform is a lot of effort JDK1.1 AWT 141 files, lines of code JDK1.5 AWT+Swing 1017 files, 209,908 lines!! JDK1.1 was light 8Mb compared to 55Mb today It was built around the concept that the GUI should have the look & feel of underlying platform A problematic concept for complex thing as GUI Advanced Java Programming / Shmulik London
5 Concept behind AWT Use underlying widgets of platform Each component in AWT is just a wrapper for an underlying native widget (its peer) The component request the windowing system to create the underlying widget and customize it according to its properties Can support only lowest common denominator of all platforms Good performance Easy to port JDK Native look & feel Too elementary Heavy weight components Difficult to write apps that will look good on different platforms Advanced Java Programming / Shmulik London
6 Some AWT components Button Frame TextField Label Scrollbar Choice others... Advanced Java Programming / Shmulik London
7 Class component All components are derived from the class java.awt.component Component Button TextComponent... TextArea TextField Advanced Java Programming / Shmulik London
8 Class Component Class component defines the properties common to all components: location, size, background color, foreground color, visibility,... public Dimension getsize() public void setsize(dimension d) public void setsize(int x, int y) public Point getlocation() public void setlocation(point p) public void setlocation(int x, int y) public Color getbackground() public void setbackground(color c)... Advanced Java Programming / Shmulik London
9 Container Container is a subclass of Component that is a superclass for all Components that can contain other components. It adds to Component the functionality of adding/removing components public void add(component c) public void remove(component c) public Component[] getcomponents() public int getcomponentcount() public void setlayout(...)... Advanced Java Programming / Shmulik London
10 Opening a Frame // A sample program that opens a yellow frame class FrameExample { public static void main(string[] args) { Frame frame = new Frame( Example ); frame.setsize(400,300); frame.setbackground(color.yellow); frame.setvisible(true); Advanced Java Programming / Shmulik London
11 Opening a Frame // A sample program that opens a yellow frame class FrameExample { public static void main(string[] args) { new SampleFrame().setVisible(true); class SampleFrame extends Frame { public SampleFrame() { super( Example ); setsize(400,300); setbackground(color.yellow); Advanced Java Programming / Shmulik London
12 Adding components // A sample program that opens a frame with // a button on it class FrameExample extends Frame{ public FrameExample () { setsize(400,300); Button okbutton = new Button( OK ); add(okbutton); public static void main(string[] args) { new FrameExample().setVisible(true); Advanced Java Programming / Shmulik London
13 Layout Managers Were are the components added? There are two ways to layout components on a container: Set the exact size and location of every component Use a LayoutManager Every container has its own LayoutManager object The LayoutManager is responsible for the the layout of the component inside the container The LayoutManager is consulted whenever there is a need to rearrange the components inside the container (container size changed, component added.. ) Advanced Java Programming / Shmulik London
14 Layout Managers add(new Button( Ok )) Frame layoutcontainer(this) FlowLayout Advanced Java Programming / Shmulik London
15 Layout Managers There a various types of Layout Managers. Each has its strategy for arranging the components. Layout managers given with java.awt: FlowLayout, BorderLayout, GridLayout, CardLayout, GridBagLayout You can define your own layout managers by implementing the interface java.awt.layoutmanager LayoutManager is an example of the Strategy pattern Advanced Java Programming / Shmulik London
16 FlowLayout setlayout(new FlowLayout()); add(new Label( Name: )); add(new TextField(10)); add(new Button( Ok )); Advanced Java Programming / Shmulik London
17 GridLayout setlayout(new GridLayout(2,2)); add(new Button( A )); add(new Button( B )); add(new Button( C )); add(new Button( D )); Advanced Java Programming / Shmulik London
18 GridLayout setlayout(new BorderLaout()); add(new Button( North ), BorderLayout.NORTH); add(new Button( East ), BorderLayout.EAST); add(new Button( South ), BorderLayout.SOUTH); add(new Button( West ), BorderLayout.WEST); add(new Button( Center ), BorderLayout.CENTER); Advanced Java Programming / Shmulik London
19 Combination of layouts Frame with BorderLayout Panel with setlayout(new BorderLaout()); GridLayout TextField display = new TextField(); add(display, BorderLayout.NORTH); Panel buttonspanel = new Panel(); buttonspanel.setlayout(new GridLayout(4,4)); String[] labels = { 7, 8, 9, +, 4, 5,... ; for (int i=0; i<labels.length; i++) { buttonspanel.add(new Button(labels[i])); Advanced Java Programming / Shmulik London
20 Graphics Every component can serve as a graphical context In order to draw on a component, you override its paint method to define the drawing. You don t call the paint method, it is called automatically by the windowing system whenever there is a need to display the component paint receives as parameter a Graphics object which has methods for drawing on the component Graphics is another example for the Strategy pattern Advanced Java Programming / Shmulik London
21 Graphics import java.awt.*; // A frame that displays some graphics on it class GraphicsExample extends Frame { public void paint(graphics painter) { painter.setcolor(color.black); painter.drawline(20,20,400,300); painter.setcolor(color.blue); painter.drawrect(50,50,150,100); painter.setcolor(color.yellow); painter.filloval(250,100,80,80); painter.setcolor(color.green); painter.fillrect(100,200,150,100); Advanced Java Programming / Shmulik London
22 Graphics Advanced Java Programming / Shmulik London
23 Graphics In order to display a drawing that is not fixed, the implementation of paint should depend on the state of the object Whenever the state changes, we need to call the repaint() method in order to refresh the display of the component. repaint() asks the windowing system to call the paint() method with the suitable graphics object. Actually, the windowing system calls the method update() which clear the display and then call the method paint(). Advanced Java Programming / Shmulik London
24 Graphics /** * A figure of a LED */ public class LEDFigure extends Component { // The state of the LED on/off private boolean ison; /** * Draws this LED. */ public void paint(graphics g) { g.setcolor(ison? Color.red.brighter() : Color.red.darker()); g.filloval(0,0,getsize().width,getsize().height); g.setcolor(color.black); g.drawoval(0,0,getsize().width,getsize().height); Advanced Java Programming / Shmulik London
25 Graphics /** * Sets the state of the LED. */ public void seton(boolean state) { ison = state; repaint(); /** * Returns the state of the LED. */ public boolean ison() { return ison; Advanced Java Programming / Shmulik London
26 Graphics LED seton() Please update my display clear display repaint() update() Windowing System paint display paint() Graphics Advanced Java Programming / Shmulik London
27 AWT event handling All components of the AWT are written as JavaBeans. You handle events fired by AWT components by registering listeners to the events they fire. The various events fired by AWT components and the interfaces of the corresponding listeners are defined in package java.awt.event You can find out which events are supported by a component by searching its API for addxxxlistener() and removexxxlistener() pairs. Advanced Java Programming / Shmulik London
28 AWT events ActionEvent ActionListener actionperformed(actionevent) TextEvent TextListener textvaluechanged(textevent) MouseEvent MouseListener mouseclicked(mouseevent) mouseentered(mouseevent) mouseexited(mouseevent) mousepressed(mouseevent) mousereleased(mouseevent) MouseMotionListener mousedragged(mouseevent) mousemoved(mouseevent) Advanced Java Programming / Shmulik London
29 ActionEvent import java.awt.*; import java.awt.event.actionevent; // A simple ActionListener that prints clicked // whenever it is notified for an ActionEvent class SimpleListener implements ActionListener { /** * Called to notify this object that some * action occured. */ public void actionperformed(actionevent event) { System.out.println( clicked ); Advanced Java Programming / Shmulik London
30 ActionEvent // An example for listening for pressing of a button class ListeningExample extends Frame { public ListeningExample() { Button okbutton = new Button( OK ); add(okbutton); pack(); ActionListener listener = new SimpleListener(); okbutton.addactionlistener(listener); public static void main(string[] args) { new ListeningExample().setVisible(true); Advanced Java Programming / Shmulik London
31 MouseEvent import java.awt.*; import java.awt.event.*; // A teasing game in which the user is encouraged // to catch a figure on the screen, but whenever // the mouse cursor gets near the figure it runs away class CatchMeGame extends Panel { // The figure the user need to catch private Component figure; // The distance beyond which the figure runs away private static final int MINIMAL_DISTANCE = 50; Advanced Java Programming / Shmulik London
32 MouseEvent public CatchMeGame() { setlayout(null); figure = new Smily(); //.. set location & dimension of figure add(figure); addmouselistener(new RunAwayAdapter(figure); public static void main(string[] args) { Frame f = new Frame( Catch me! ); f.setsize(400,300); f.add(new CatchMeGate()); f.setvisible(true); Advanced Java Programming / Shmulik London
33 MouseEvent // An adapter that listen to the movements of the mouse // and keeps the figure from being caught class RunAwayAdapter implements MouseMotionListener { private Component figure; public RunAwayAdapter(Component figure) { this.figure = figure; public void mousemoved(mouseevent event) { runaway(event.getpoint()); public void mousedragged(mouseevent event) { runaway(event.getpoint()); Advanced Java Programming / Shmulik London
34 MouseEvent private void runaway(point mouse) { //... compute the center of the figure xm,ym // if mouse if far away stay in place if (Math.abs(mouse.x-xm)>MINIMAL_DISTANCE Math.abs(mouse.y-ym)>MINIMAL_DISTANCE) { return; //.. decide for the direction of the movement figure.setlocation( figure.getlocation().x+dx, figure.getlocation().y+dy); repaint(); Advanced Java Programming / Shmulik London
35 Adapters (the need) import java.awt.*; import java.awt.event.*; /** * A panel that lets the user draw freehand lines */ public class DrawingPanel extends Panel { // The points composing the path drawn by the user java.util.list path; public DrawingPanel() { addmouselistener(new StartDrawingAdapter(this)); addmousemotionlistener(new DrawingAdapter(this)); Advanced Java Programming / Shmulik London
36 Adapters (the need) /** * Paints this component */ public void paint(graphics g) { if (path==null) { return; for (int i=0; i<path.size()-1; i++) { Point p1 = (Point)path.get(i); Point p2 = (Point)path.get(i+1); g.drawline(p1.x, p1.y, p2.x, p2.y); repaint(); Advanced Java Programming / Shmulik London
37 Adapters (the need) // Cleans the path at the beginning of the dragging class StartDrawingAdapter implements MouseListener() { private DrawingPanel target; public StartDrawingAdapter(DrawingPanel target) { this.target = target; public void mousepressed(mouseevent e) { target.path = new ArrayList(); public void mousereleased(mouseevent e) { public void mouseexited(mouseevent e) {... Advanced Java Programming / Shmulik London
38 Adapters (the need) // Adds the points to the path during the dragging class DrawingAdapter implements MouseMotionListener { private DrawingPanel target; public DrawingAdapter(DrawingPanel target) { this.target = target; public void mousedragged(mouseevent e) { target.path.add (e.getpoint()); target.repaint(); public void mousemoved(mouseevent e) { Advanced Java Programming / Shmulik London
39 Adapters In the previous example the listener classes need to implement all the method defined in the interface even though they are interested only in implementing part of them. This is a bit elaborating To avoid this, the API include for every listener interface that defines more than a single method, an adapter class that implement the interface in a trivial way. Advanced Java Programming / Shmulik London
40 Adapters package java.awt.event; /** * Adapter for MouseEvents... */ public abstract class MouseAdapter implements MouseListener{ public void mousepressed(mouseevent e) { public void mousereleased(mouseevent e) { public void mouseentered(mouseevent e) { //... mouseexited, mouseclicked as well Advanced Java Programming / Shmulik London
41 Adapters // Cleans the path at the beginning of the dragging class StartDrawingAdapter extends MouseAdapter { private DrawingPanel target; public StartDrawingAdapter(DrawingPanel target) { this.target = target; public void mousepressed(mouseevent e) { target.path = new ArrayList(); Advanced Java Programming / Shmulik London
42 Inner classes In both previous examples the main classes created adapters to act upon itself This is a common case This adds to the complexity of the code: the main object has to pass a reference of itself to the adapters the adapters has to define a field and a suitable constructor to record the target object in the adapter we make frequent use of the target reference Advanced Java Programming / Shmulik London
43 Inner classes To make the code more compact (less error prone) Java let you define inner classes Inner classes are classes defined inside the body of another class. Instance of inner-classes has automatic access to fields defined in the enclosing class, with no need to denote the reference to the enclosing object. There are several other details of inner-classes that we skip. You can read about them in the documentation of the JDK. Advanced Java Programming / Shmulik London
44 import java.awt.*; import java.awt.event.*; Inner classes /** * A panel that lets the user draw freehand lines */ public class DrawingPanel extends Panel { // The points composing the path java.util.list path; public DrawingPanel() { addmouselistener( new StartDrawingAdapter(this)); addmousemotionlistener( new DrawingAdapter(this)); Advanced Java Programming / Shmulik London
45 Inner classes /** * Paints this component */ public void paint(graphics g) { if (path==null) { return; for (int i=0; i<path.size()-1; i++) { Point p1 = (Point)path.elementAt(i); Point p2 = (Point)path.elementAt(i+1); g.drawline(p1.x, p1.y, p2.x, p2.y); repaint(); Advanced Java Programming / Shmulik London
46 Inner classes // Cleans the path at the beginning of the drag class StartDrawingAdapter extends MouseAdapter { public void mousepressed(mouseevent e) { path = new java.util.arraylist(); // Adds the points to the path during the drag class DrawingAdapter extends MouseAdapter { public void mousedragged(mouseevent e) { path.add(e.getpoint()); repaint(); Advanced Java Programming / Shmulik London
47 Anonymous classes If an inner class is needed only for a single use and its constructor gets no parameters you can define it as an anonymous class Anonymous class are defined in the place in the code were they are needed, and you immediately create an instance of the anonymous class Use anonymous classes with care - they should be used only where the code of the class is very compact 1-3 lines. Advanced Java Programming / Shmulik London
48 Anonymous classes //.. as before public class DrawingPanel extends Panel { //.. public DrawingPanel() { addmouselistener(new MouseAdapter() { public void mousepressed(mouseevent e) { path = new ArrayList(); ); addmousemotionlistener(new MouseMotionAdapter() { public void mousedragged(mouseevent e) { path.add(e.getpoint()); repaint(); ); Advanced Java Programming / Shmulik London
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. 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 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 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 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 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 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 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 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 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 informationComputer Science 210: Data Structures. Intro to Java Graphics
Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes
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 informationMethod Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is
INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in
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 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 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 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 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 informationCS11 Java. Fall Lecture 3
CS11 Java Fall 2014-2015 Lecture 3 Today s Topics! Class inheritance! Abstract classes! Polymorphism! Introduction to Swing API and event-handling! Nested and inner classes Class Inheritance! A third of
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 informationLecture 5: Java Graphics
Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,
More 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 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 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 informationKF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation
KF5008 Program Design & Development Lecture 1 Usability GUI Design and Implementation Types of Requirements Functional Requirements What the system does or is expected to do Non-functional Requirements
More 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 informationLecture 3: Java Graphics & Events
Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new
More 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 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 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 informationGraphical User Interfaces (GUIs)
CMSC 132: Object-Oriented Programming II Graphical User Interfaces (GUIs) Department of Computer Science University of Maryland, College Park Model-View-Controller (MVC) Model for GUI programming (Xerox
More informationOOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:
OOP Assignment V If we don t use multithreading, or a timer, and update the contents of the applet continuously by calling the repaint() method, the processor has to update frames at a blinding rate. Too
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 informationCOMPSCI 230. Software Design and Construction. Swing
COMPSCI 230 Software Design and Construction Swing 1 2013-04-17 Recap: SWING DESIGN PRINCIPLES 1. GUI is built as containment hierarchy of widgets (i.e. the parent-child nesting relation between them)
More 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 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 informationFirstSwingFrame.java Page 1 of 1
FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import
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 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 (CIS120)
Programming Languages and Techniques (CIS120) Lecture 35 April 15, 2013 Swing III: OO Design, Mouse InteracGon Announcements HW10: Game Project is out, due Tuesday, April 23 rd at midnight If you want
More informationCS11 Java. Fall Lecture 4
CS11 Java Fall 2006-2007 Lecture 4 Today s Topics Interfaces The Swing API Event Handlers Inner Classes Arrays Java Interfaces Classes can only have one parent class No multiple inheritance in Java! By
More informationCS 2113 Software Engineering
CS 2113 Software Engineering Java 5 - GUIs Import the code to intellij https://github.com/cs2113f18/template-j-5.git Professor Tim Wood - The George Washington University Class Hierarchies Abstract Classes
More informationPreviously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components
CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how
More informationBuilding Java Programs Bonus Slides
Building Java Programs Bonus Slides Graphical User Interfaces Copyright (c) Pearson 2013. All rights reserved. Graphical input and output with JOptionPane JOptionPane An option pane is a simple dialog
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 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 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 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 information(Incomplete) History of GUIs
CMSC 433 Programming Language Technologies and Paradigms Spring 2004 Graphical User Interfaces April 20, 2004 (Incomplete) History of GUIs 1973: Xerox Alto 3-button mouse, bit-mapped display, windows 1981:
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 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 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 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 informationLecture 19 GUI Events
CSE 331 Software Design and Implementation Lecture 19 GUI Events The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous inner classes Proper interaction
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 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 informationOBJECT ORIENTED PROGRAMMING. Java GUI part 1 Loredana STANCIU Room B616
OBJECT ORIENTED PROGRAMMING Java GUI part 1 Loredana STANCIU loredana.stanciu@upt.ro Room B616 What is a user interface That part of a program that interacts with the user of the program: simple command-line
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 informationCSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN
CSSE 220 Event Based Programming Check out EventBasedProgramming from SVN Interfaces are contracts Interfaces - Review Any class that implements an interface MUST provide an implementation for all methods
More informationCSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 35 April 21, 2014 Swing III: Paint demo, Mouse InteracFon HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your
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 informationCS 3331 Advanced Object-Oriented Programming Final Exam
Fall 2015 (Thursday, December 3) Name: CS 3331 Advanced Object-Oriented Programming Final Exam This test has 5 questions and pages numbered 1 through 10. Reminders This test is closed-notes and closed-book.
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 Event Handlers (Part I)
GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event
More 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 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 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 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 informationProgrammierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications
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 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 informationCSE 331 Software Design and Implementation. Lecture 19 GUI Events
CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing
More informationInheritance. One class inherits from another if it describes a specialized subset of objects Terminology:
Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited
More informationUnit 7: Event driven programming
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 7: Event driven programming 1 1. Introduction 2.
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 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 informationWindows and Events. created originally by Brian Bailey
Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating
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 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 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 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 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 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 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 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 informationHW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.
HW#1: Pencil Me In Status!? CS193J: Programming in Java Summer Quarter 2003 Lecture 6 Inner Classes, Listeners, Repaint Manu Kumar sneaker@stanford.edu How was Homework #1? Comments please? SITN students
More information7. Program Frameworks
7. Program Frameworks Overview: 7.1 Introduction to program frameworks 7.2 Program frameworks for User Interfaces: - Architectural properties of GUIs - Abstract Window Toolkit of Java Many software systems
More 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 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 informationLab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in
Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the
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 informationHandout 14 Graphical User Interface (GUI) with Swing, Event Handling
Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement
More informationPESIT Bangalore South Campus
INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)
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 informationMarcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science
Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm } Abstract Window Toolkit Delegates creation and
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 informationBM214E Object Oriented Programming Lecture 12
BM214E Object Oriented Programming Lecture 12 Graphical User Interfaces -- overview -- essential elements Agenda Containers -- overview -- composition vs. inheritance Components -- examples Layout Managers
More information