Event-Driven Programming CSCI 201 Principles of Software Development
|
|
- Benedict Warren
- 7 years ago
- Views:
Transcription
1 Event-Driven Programming CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D.
2 Outline Event-Driven Programming Overview Event-Driven Programming Example Adapter Classes Program USC CSCI 201L
3 Event-Driven Programming Overview The code we have written so far executed deterministically from top to bottom, calling methods and utilizing other classes We utilized user input to determine code that was executed in some cases, but we had prompted the user and waited for a response In GUI programming, the code that gets called is based on events, such as a user clicking or typing something We don t know the order in which users will perform the actions, so we need to associate a method to be called with an action that the user performs 3/22
4 Listeners Java uses a delegation-based model for event handling A source object fires an event An object interested in the event, called a listener, handles it A listener must be an instance of a listener interface and must be registered with a source component 4/22
5 Fired Events Source Object User Action Event Type Fired JButton Click the button ActionEvent JTextField Press enter key ActionEvent JComboBox Select an item ItemEvent, ActionEvent JList Select one or more items ListSelectionEvent JCheckBox Click a check box ItemEvent, ActionEvent JRadioButton Click a radio button ItemEvent, ActionEvent JMenuItem Select a menu item ActionEvent JScrollBar Move the scroll bar AdjustmentEvent JSlider Move the slider bar ChangeEvent Window Open, closing, closed, iconify, deiconify, activate, deactive the window WindowEvent Container Component added or removed from the container ContainerEvent Component Mouse pressed, released, clicked, entered, or exited Mouse moved or dragged Key pressed or released Component moved, resized, hidden, or shown Component gained or lost focus MouseEvent MouseEvent KeyEvent ComponentEvent FocusEvent Note: If a component can fire an event, any subclass of the component can fire the same type of event o Every Component can fire a MouseEvent, KeyEvent, FocusEvent, and ComponentEvent since Component is the superclass of GUI components 5/22
6 Listeners for Fired Events Event Class Listener Interface Listener Methods ActionEvent ActionListener actionperformed(actionevent) ItemEvent ItemListener itemstatechanged(itemevent) MouseEvent MouseListener mousepressed(mouseevent) mousereleased(mouseevent) mouseentered(mouseevent) mouseexited(mouseevent) mouseclicked(mouseevent) KeyEvent WindowEvent ContainerEvent ComponentEvent FocusEvent MouseMotionListener KeyListener WindowListener ContainerListener ComponentListener FocusListener mousedragged(mouseevent) mousemoved(mouseevent) keypressed(keyevent) keyreleased(keyevent) keytyped(keyevent) windowclosing(windowevent) windowopened(windowevent) windowiconified(windowevent) windowdeiconified(windowevent) windowclosed(windowevent) windowactivated(windowevent) windowdeactivated(windowevent) componentadded(containerevent) componentremoved(containerevent) componentmoved(componentevent) componenthidden(componentevent) componentresized(componentevent) componentshown(componentevent) focusgained(focusevent) focuslost(focusevent) AdjustmentEvent AdjustmentListener adjustmentvaluechanged(adjustmentevent) ChangeEvent ChangeListener statechanged(changeevent) ListSelectionEvent ListSelectionListener valuechanged(listselectionevent) 6/22
7 Outline Event-Driven Programming Overview Event-Driven Programming Example Adapter Classes Program
8 GUI with Events The following slides are based on this GUI. 8/22
9 Event-Driven Programming Example 1 import java.awt.event.actionevent; 2 import java.awt.event.actionlistener; 3 4 import javax.swing.boxlayout; 5 import javax.swing.jbutton; 6 import javax.swing.jframe; 7 import javax.swing.jlabel; 8 import javax.swing.jpanel; 9 import javax.swing.jtextfield; public class Test extends JFrame { 12 private JTextField num1tf, num2tf, totaltf; 13 private JLabel number1label, number2label; 14 private JButton concatenatebutton; 15 public Test() { 16 super("event-driven Programming Example"); 17 number1label = new JLabel("Number 1"); 18 num1tf = new JTextField("", 15); 19 number2label = new JLabel("Number 2"); 20 num2tf = new JTextField("", 15); 21 totaltf = new JTextField("", 20); 22 concatenatebutton = new JButton("Concatenate"); 23 concatenatebutton.addactionlistener( 24 new ConcatenateAdapter(num1TF, num2tf, totaltf)); JPanel row1panel = new JPanel(); 27 row1panel.add(number1label); 28 row1panel.add(num1tf); JPanel row2panel = new JPanel(); 31 row2panel.add(number2label); 32 row2panel.add(num2tf); JPanel row3panel = new JPanel(); 35 row3panel.add(concatenatebutton); JPanel row4panel = new JPanel(); 38 row4panel.add(totaltf); 39 JPanel verticalpanel = new JPanel(); 40 verticalpanel.setlayout(new BoxLayout(verticalPanel, BoxLayout.Y_AXIS)); 41 verticalpanel.add(row1panel); 42 verticalpanel.add(row2panel); 43 verticalpanel.add(row3panel); 44 verticalpanel.add(row4panel); add(verticalpanel); 47 setsize(250, 175); 48 setlocationrelativeto(null); 49 setdefaultcloseoperation(jframe.exit_on_close); 50 setvisible(true); 51 } public static void main(string args[]) { 54 Test t = new Test(); 55 } 56 } class ConcatenateAdapter implements ActionListener { 59 private JTextField num1tf, num2tf, totaltf; 60 public ConcatenateAdapter(JTextField num1tf, JTextField num2tf, JTextField totaltf) { 61 this.num1tf = num1tf; 62 this.num2tf = num2tf; 63 this.totaltf = totaltf; 64 } public void actionperformed(actionevent ae) { 67 totaltf.settext(num1tf.gettext() + num2tf.gettext()); 68 } 69 } The ConcatenateAdapter class is outside the Test class. Event-Driven Programming Example USC CSCI 201L 9/22
10 Event-Driven Programming Example 1 import java.awt.event.actionevent; 2 import java.awt.event.actionlistener; 3 4 import javax.swing.boxlayout; 5 import javax.swing.jbutton; 6 import javax.swing.jframe; 7 import javax.swing.jlabel; 8 import javax.swing.jpanel; 9 import javax.swing.jtextfield; public class Test extends JFrame { 12 private JTextField num1tf, num2tf, totaltf; 13 private JLabel number1label, number2label; 14 private JButton concatenatebutton; 15 public Test() { 16 super("event-driven Programming Example"); 17 number1label = new JLabel("Number 1"); 18 num1tf = new JTextField("", 15); 19 number2label = new JLabel("Number 2"); 20 num2tf = new JTextField("", 15); 21 totaltf = new JTextField("", 20); 22 concatenatebutton = new JButton("Concatenate"); 23 concatenatebutton.addactionlistener( 24 new ConcatenateAdapter(num1TF, num2tf, totaltf)); JPanel row1panel = new JPanel(); 27 row1panel.add(number1label); 28 row1panel.add(num1tf); JPanel row2panel = new JPanel(); 31 row2panel.add(number2label); 32 row2panel.add(num2tf); JPanel row3panel = new JPanel(); 35 row3panel.add(concatenatebutton); JPanel row4panel = new JPanel(); 38 row4panel.add(totaltf); 39 JPanel verticalpanel = new JPanel(); 40 verticalpanel.setlayout(new BoxLayout(verticalPanel, BoxLayout.Y_AXIS)); 41 verticalpanel.add(row1panel); 42 verticalpanel.add(row2panel); 43 verticalpanel.add(row3panel); 44 verticalpanel.add(row4panel); add(verticalpanel); 47 setsize(250, 175); 48 setlocationrelativeto(null); 49 setdefaultcloseoperation(jframe.exit_on_close); 50 setvisible(true); 51 } public static void main(string args[]) { 54 Test t = new Test(); 55 } class ConcatenateAdapter implements ActionListener { 58 private JTextField num1tf, num2tf, totaltf; 59 public ConcatenateAdapter(JTextField num1tf, JTextField num2tf, JTextField totaltf) { 60 this.num1tf = num1tf; 61 this.num2tf = num2tf; 62 this.totaltf = totaltf; 63 } public void actionperformed(actionevent ae) { 66 totaltf.settext(num1tf.gettext() + num2tf.gettext()); 67 } 68 } 69 } The ConcatenateAdapter class is inside the Test class. Event-Driven Programming Example USC CSCI 201L 10/22
11 Event-Driven Programming Example 1 import java.awt.event.actionevent; 2 import java.awt.event.actionlistener; 3 4 import javax.swing.boxlayout; 5 import javax.swing.jbutton; 6 import javax.swing.jframe; 7 import javax.swing.jlabel; 8 import javax.swing.jpanel; 9 import javax.swing.jtextfield; public class Test extends JFrame { 12 private JTextField num1tf, num2tf, totaltf; 13 private JLabel number1label, number2label; 14 private JButton concatenatebutton; 15 public Test() { 16 super("event-driven Programming Example"); 17 number1label = new JLabel("Number 1"); 18 num1tf = new JTextField("", 15); 19 number2label = new JLabel("Number 2"); 20 num2tf = new JTextField("", 15); 21 totaltf = new JTextField("", 20); 22 concatenatebutton = new JButton("Concatenate"); 23 concatenatebutton.addactionlistener( 24 new ConcatenateAdapter()); JPanel row1panel = new JPanel(); 27 row1panel.add(number1label); 28 row1panel.add(num1tf); JPanel row2panel = new JPanel(); 31 row2panel.add(number2label); 32 row2panel.add(num2tf); JPanel row3panel = new JPanel(); 35 row3panel.add(concatenatebutton); JPanel row4panel = new JPanel(); 38 row4panel.add(totaltf); 39 JPanel verticalpanel = new JPanel(); 40 verticalpanel.setlayout(new BoxLayout(verticalPanel, BoxLayout.Y_AXIS)); 41 verticalpanel.add(row1panel); 42 verticalpanel.add(row2panel); 43 verticalpanel.add(row3panel); 44 verticalpanel.add(row4panel); add(verticalpanel); 47 setsize(250, 175); 48 setlocationrelativeto(null); 49 setdefaultcloseoperation(jframe.exit_on_close); 50 setvisible(true); 51 } public static void main(string args[]) { 54 Test t = new Test(); 55 } class ConcatenateAdapter implements ActionListener { 58 public void actionperformed(actionevent ae) { 59 Test.this.totalTF.setText(Test.this.num1TF.getText() + Test.this.num2TF.getText()); 60 } 61 } 62 } The ConcatenateAdapter class can use member variables of the Test class. Event-Driven Programming Example USC CSCI 201L 11/22
12 Event-Driven Programming Example 1 import java.awt.event.actionevent; 2 import java.awt.event.actionlistener; 3 4 import javax.swing.boxlayout; 5 import javax.swing.jbutton; 6 import javax.swing.jframe; 7 import javax.swing.jlabel; 8 import javax.swing.jpanel; 9 import javax.swing.jtextfield; public class Test extends JFrame { 12 private JTextField num1tf, num2tf, totaltf; 13 private JLabel number1label, number2label; 14 private JButton concatenatebutton; 15 public Test() { 16 super("event-driven Programming Example"); 17 number1label = new JLabel("Number 1"); 18 num1tf = new JTextField("", 15); 19 number2label = new JLabel("Number 2"); 20 num2tf = new JTextField("", 15); 21 totaltf = new JTextField("", 20); 22 concatenatebutton = new JButton("Concatenate"); 23 concatenatebutton.addactionlistener( 24 new ConcatenateAdapter()); JPanel row1panel = new JPanel(); 27 row1panel.add(number1label); 28 row1panel.add(num1tf); JPanel row2panel = new JPanel(); 31 row2panel.add(number2label); 32 row2panel.add(num2tf); JPanel row3panel = new JPanel(); 35 row3panel.add(concatenatebutton); JPanel row4panel = new JPanel(); 38 row4panel.add(totaltf); 39 JPanel verticalpanel = new JPanel(); 40 verticalpanel.setlayout(new BoxLayout(verticalPanel, BoxLayout.Y_AXIS)); 41 verticalpanel.add(row1panel); 42 verticalpanel.add(row2panel); 43 verticalpanel.add(row3panel); 44 verticalpanel.add(row4panel); add(verticalpanel); 47 setsize(250, 175); 48 setlocationrelativeto(null); 49 setdefaultcloseoperation(jframe.exit_on_close); 50 setvisible(true); 51 } public static void main(string args[]) { 54 Test t = new Test(); 55 } class ConcatenateAdapter implements ActionListener { 58 public void actionperformed(actionevent ae) { 59 totaltf.settext(num1tf.gettext() + num2tf.gettext()); 60 } 61 } 62 } Since ConcatenateAdapter does not have variables with the same name as the member variables in the Test class, we can omit the outer class qualification. Event-Driven Programming Example USC CSCI 201L 12/22
13 Event-Driven Programming Example 1 import java.awt.event.actionevent; 2 import java.awt.event.actionlistener; 3 4 import javax.swing.boxlayout; 5 import javax.swing.jbutton; 6 import javax.swing.jframe; 7 import javax.swing.jlabel; 8 import javax.swing.jpanel; 9 import javax.swing.jtextfield; public class Test extends JFrame { 12 private JTextField num1tf, num2tf, totaltf; 13 private JLabel number1label, number2label; 14 private JButton concatenatebutton; 15 public Test() { 16 super("event-driven Programming Example"); 17 number1label = new JLabel("Number 1"); 18 num1tf = new JTextField("", 15); 19 number2label = new JLabel("Number 2"); 20 num2tf = new JTextField("", 15); 21 totaltf = new JTextField("", 20); 22 concatenatebutton = new JButton("Concatenate"); 23 class ConcatenateAdapter implements ActionListener { 24 public void actionperformed(actionevent ae) { 25 totaltf.settext(num1tf.gettext() + num2tf.gettext()); 26 } 27 } 28 concatenatebutton.addactionlistener( 29 new ConcatenateAdapter()); JPanel row1panel = new JPanel(); 32 row1panel.add(number1label); 33 row1panel.add(num1tf); JPanel row2panel = new JPanel(); 36 row2panel.add(number2label); 37 row2panel.add(num2tf); JPanel row3panel = new JPanel(); 40 row3panel.add(concatenatebutton); JPanel row4panel = new JPanel(); 43 row4panel.add(totaltf); 44 JPanel verticalpanel = new JPanel(); 45 verticalpanel.setlayout(new BoxLayout(verticalPanel, BoxLayout.Y_AXIS)); 46 verticalpanel.add(row1panel); 47 verticalpanel.add(row2panel); 48 verticalpanel.add(row3panel); 49 verticalpanel.add(row4panel); add(verticalpanel); 52 setsize(250, 175); 52 setlocationrelativeto(null); 53 setdefaultcloseoperation(jframe.exit_on_close); 54 setvisible(true); 55 } public static void main(string args[]) { 58 Test t = new Test(); 59 } 60 } The ConcatenateAdapter class is inside the constructor of the Test class. Event-Driven Programming Example USC CSCI 201L 13/22
14 Event-Driven Programming Example 1 import java.awt.event.actionevent; 2 import java.awt.event.actionlistener; 3 4 import javax.swing.boxlayout; 5 import javax.swing.jbutton; 6 import javax.swing.jframe; 7 import javax.swing.jlabel; 8 import javax.swing.jpanel; 9 import javax.swing.jtextfield; public class Test extends JFrame { 12 private JTextField num1tf, num2tf, totaltf; 13 private JLabel number1label, number2label; 14 private JButton concatenatebutton; 15 public Test() { 16 super("event-driven Programming Example"); 17 number1label = new JLabel("Number 1"); 18 num1tf = new JTextField("", 15); 19 number2label = new JLabel("Number 2"); 20 num2tf = new JTextField("", 15); 21 totaltf = new JTextField("", 20); 22 concatenatebutton = new JButton("Concatenate"); 23 concatenatebutton.addactionlistener(new ActionListener() { 24 public void actionperformed(actionevent ae) { 25 totaltf.settext(num1tf.gettext() + num2tf.gettext()); 26 } 27 }); JPanel row1panel = new JPanel(); 30 row1panel.add(number1label); 31 row1panel.add(num1tf); JPanel row2panel = new JPanel(); 34 row2panel.add(number2label); 35 row2panel.add(num2tf); JPanel row3panel = new JPanel(); 38 row3panel.add(concatenatebutton); JPanel row4panel = new JPanel(); 43 row4panel.add(totaltf); 44 JPanel verticalpanel = new JPanel(); 45 verticalpanel.setlayout(new BoxLayout(verticalPanel, BoxLayout.Y_AXIS)); 46 verticalpanel.add(row1panel); 47 verticalpanel.add(row2panel); 48 verticalpanel.add(row3panel); 49 verticalpanel.add(row4panel); add(verticalpanel); 52 setsize(250, 175); 52 setlocationrelativeto(null); 53 setdefaultcloseoperation(jframe.exit_on_close); 54 setvisible(true); 55 } public static void main(string args[]) { 58 Test t = new Test(); 59 } 60 } The ConcatenateAdapter class has become an anonymous inner class. Event-Driven Programming Example USC CSCI 201L 14/22
15 Outline Event-Driven Programming Overview Event-Driven Programming Example Adapter Classes Program USC CSCI 201L
16 Listeners Listeners are interfaces, which means all the methods in them are abstract Even if you only need one of the methods, you will still need to implement all of them, though methods you don t need would have empty bodies 1 public class Test extends JFrame { 2 public Test() { 3 super("event-driven Programming Example"); 4 5 addwindowlistener(new WindowListener() { 6 public void windowdeiconified(windowevent we) { 7 } 8 public void windowiconified(windowevent we) { 9 } 10 public void windowactivated(windowevent we) { 11 } 12 public void windowdeactivated(windowevent we) { 13 } 14 public void windowclosing(windowevent we) { 15 } 16 public void windowopened(windowevent we) { 17 System.out.println("opened"); 18 } 19 public void windowclosed(windowevent we) { 20 System.out.println("closed"); 21 System.exit(1); 22 } 23 }); 24 setdefaultcloseoperation(jframe.dispose_on_close); 25 setsize(250, 175); 26 setlocationrelativeto(null); 27 setvisible(true); 28 } public static void main(string args[]) { 31 Test t = new Test(); 32 } 33 } Since WindowListener has seven methods, we Needed to override all of them even though we Did not need to customize these five methods. Adapter Classes USC CSCI 201L 16/22
17 Adapters Java provides support classes, called adapters, which provide default implementations for all the methods in corresponding listener interfaces The default implementation of a method is an empty body with the method signature Adapters only exist for interfaces that have more than one method. Why? Adapter Classes USC CSCI 201L 17/22
18 Adapters Java provides support classes, called adapters, which provide default implementations for all the methods in corresponding listener interfaces The default implementation of a method is an empty body with the method signature Adapters only exist for interfaces that have more than one method. Why? If an interface has only one method, you would need to implement it or there would be no reason to use the interface Adapter Classes USC CSCI 201L 18/22
19 Adapter Classes Event Class Listener Interface Adapter Class Listener Methods ActionEvent ActionListener actionperformed(actionevent) ItemEvent ItemListener itemstatechanged(itemevent) MouseEvent MouseListener MouseAdapter mousepressed(mouseevent) mousereleased(mouseevent) mouseentered(mouseevent) mouseexited(mouseevent) mouseclicked(mouseevent) MouseMotionListener MouseMotionAdapter KeyEvent KeyListener KeyAdapter WindowEvent WindowListener WindowAdapter ContainerEvent ContainerListener ContainerAdapter ComponentEvent ComponentListener ComponentAdapter FocusEvent FocusListener FocusAdapter mousedragged(mouseevent) mousemoved(mouseevent) keypressed(keyevent) keyreleased(keyevent) keytyped(keyevent) windowclosing(windowevent) windowopened(windowevent) windowiconified(windowevent) windowdeiconified(windowevent) windowclosed(windowevent) windowactivated(windowevent) windowdeactivated(windowevent) componentadded(containerevent) componentremoved(containerevent) componentmoved(componentevent) componenthidden(componentevent) componentresized(componentevent) componentshown(componentevent) focusgained(focusevent) focuslost(focusevent) AdjustmentEvent AdjustmentListener adjustmentvaluechanged(adjustmentevent) ChangeEvent ChangeListener statechanged(changeevent) ListSelectionEvent ListSelectionListener valuechanged(listselectionevent) 19/22
20 Adapter Example With an adapter, we only need to override the methods that we want to use instead of all the methods in the listener 1 public class Test extends JFrame { 2 public Test() { 3 super("event-driven Programming Example"); 4 5 addwindowlistener(new WindowAdapter() { 6 public void windowopened(windowevent we) { 7 System.out.println("opened"); 8 } 9 public void windowclosed(windowevent we) { 10 System.out.println("closed"); 11 System.exit(1); 12 } 13 }); 14 setdefaultcloseoperation(jframe.exit_on_close); 15 setsize(250, 175); 16 setlocationrelativeto(null); 17 setvisible(true); 18 } public static void main(string args[]) { 21 Test t = new Test(); 22 } 23 } With WindowAdapter we only need to override the methods we want to customize since it has empty body implementations for all the methods in WindowListener. 20/22
21 Outline Event-Driven Programming Overview Event-Driven Programming Example Adapter Classes Program USC CSCI 201L
22 Program Write a program that has three text fields for reading the loan amount, annual interest rate, and number of years from the user. When the user clicks the Calculate button or hits the Enter key, calculate the amount of the loan after the number of years, assuming no money is paid to the principal. Display this value. KeyEvent has a method called getkeychar() KeyListener has a method called keytyped(keyevent) 22/22
core 2 Handling Mouse and Keyboard Events
core Web programming Handling Mouse and Keyboard Events 1 2001-2003 Marty Hall, Larry Brown http:// Agenda General event-handling strategy Handling events with separate listeners Handling events by implementing
More informationSwing. A Quick Tutorial on Programming Swing Applications
Swing A Quick Tutorial on Programming Swing Applications 1 MVC Model View Controller Swing is based on this design pattern It means separating the implementation of an application into layers or components:
More informationCS 335 Lecture 06 Java Programming GUI and Swing
CS 335 Lecture 06 Java Programming GUI and Swing Java: Basic GUI Components Swing component overview Event handling Inner classes and anonymous inner classes Examples and various components Layouts Panels
More informationGUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012
GUIs with Swing Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2012 Slides copyright 2012 by Jeffrey Eppinger, Jonathan Aldrich, William
More informationGUI Event-Driven Programming
GUI Event-Driven Programming CSE 331 Software Design & Implementation Slides contain content by Hal Perkins and Michael Hotan 1 Outline User events and callbacks Event objects Event listeners Registering
More informationLecture VII JAVA SWING GUI TUTORIAL
2. First Step: JFrame Lecture VII Page 1 Lecture VII JAVA SWING GUI TUTORIAL These notes are based on the excellent book, Core Java, Vol 1 by Horstmann and Cornell, chapter 7, graphics programming. Introduction
More informationUsing A Frame for Output
Eventos Roteiro Frames Formatting Output Event Handling Entering Data Using Fields in a Frame Creating a Data Entry Field Using a Field Reading Data in an Event Handler Handling Multiple Button Events
More information5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung
AWT vs. Swing AWT (Abstract Window Toolkit; Package java.awt) Benutzt Steuerelemente des darunterliegenden Betriebssystems Native Code (direkt für die Maschine geschrieben, keine VM); schnell Aussehen
More informationjava.applet Reference
18 In this chapter: Introduction to the Reference Chapters Package diagrams java.applet Reference Introduction to the Reference Chapters The preceding seventeen chapters cover just about all there is to
More informationGUI Components: Part 2
GUI Components: Part 2 JComboBox and Using an Anonymous Inner Class for Event Handling A combo box (or drop-down list) enables the user to select one item from a list. Combo boxes are implemented with
More informationpublic class Application extends JFrame implements ChangeListener, WindowListener, MouseListener, MouseMotionListener {
Application.java import javax.swing.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.event.*; import java.util.*; public class Application extends JFrame implements ChangeListener,
More informationhttp://netbeans.org/kb/docs/java/gui-functionality.html?print=yes
Page 1 of 6 Introduction to GUI Building Contributed by Saleem Gul and Tomas Pavek, maintained by Ruth Kusterer and Irina Filippova This beginner tutorial teaches you how to create a simple graphical user
More informationAdvanced Network Programming Lab using Java. Angelos Stavrou
Advanced Network Programming Lab using Java Angelos Stavrou Table of Contents A simple Java Client...3 A simple Java Server...4 An advanced Java Client...5 An advanced Java Server...8 A Multi-threaded
More informationPrinciples of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad 15-214. Spring 2013
Principles of Software Construction: Objects, Design and Concurrency GUIs with Swing 15-214 toad Spring 2013 Christian Kästner Charlie Garrod School of Computer Science 2012-13 C Garrod, C Kästner, J Aldrich,
More informationINTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction
INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program
More informationJava Mouse and Keyboard Methods
7 Java Mouse and Keyboard Methods 7.1 Introduction The previous chapters have discussed the Java programming language. This chapter investigates event-driven programs. Traditional methods of programming
More informationThe following four software tools are needed to learn to program in Java:
Getting Started In this section, we ll see Java in action. Some demo programs will highlight key features of Java. Since we re just getting started, these programs are intended only to pique your interest.
More information// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;
// Correntista public class Correntista { String nome, sobrenome; int cpf; public Correntista(){ nome = "zé"; sobrenome = "Pereira"; cpf = 123456; public void setnome(string n){ nome = n; public void setsobrenome(string
More informationProgramming with Java GUI components
Programming with Java GUI components Java includes libraries to provide multi-platform support for Graphic User Interface objects. The multi-platform aspect of this is that you can write a program on a
More informationProviding Information (Accessors)
Providing Information (Accessors) C++ allows you to declare a method as const. As a result the compiler warns you if statements in the method change the object s state. Java has no such facility, and so
More informationMouse Event Handling (cont.)
GUI Components: Part II Mouse Event Handling (cont.) Each mouse event-handling method receives a MouseEvent object that contains information about the mouse event that occurred, including the x- and y-coordinates
More informationDeveloping GUI Applications: Architectural Patterns Revisited
Developing GUI Applications: Architectural Patterns Revisited A Survey on MVC, HMVC, and PAC Patterns Alexandros Karagkasidis karagkasidis@gmail.com Abstract. Developing large and complex GUI applications
More informationAssignment # 2: Design Patterns and GUIs
CSUS COLLEGE OF ENGINEERING AND COMPUTER SCIENCE Department of Computer Science CSc 133 Object-Oriented Computer Graphics Programming Spring 2014 John Clevenger Assignment # 2: Design Patterns and GUIs
More information11. Applets, normal window applications, packaging and sharing your work
11. Applets, normal window applications, packaging and sharing your work In this chapter Converting Full Screen experiments into normal window applications, Packaging and sharing applications packaging
More informationFondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)
Fondamenti di Java Introduzione alla costruzione di GUI (graphic user interface) component - container - layout Un Container contiene [0 o +] Components Il Layout specifica come i Components sono disposti
More informationCSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus
CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus 1. Purpose This assignment exercises how to write a peer-to-peer communicating program using non-blocking
More informationAltas, Bajas y Modificaciones de Registros en tabla MYSQL
Altas, Bajas y Modificaciones de Registros en tabla MYSQL 1. En MySql crear una base de datos de nombre EmpresaABC y dentro de ella la tabla Empleados con la siguiente estructura: DNI integer(8) Definir
More informationArtificial Intelligence. Class: 3 rd
Artificial Intelligence Class: 3 rd Teaching scheme: 4 hours lecture credits: Course description: This subject covers the fundamentals of Artificial Intelligence including programming in logic, knowledge
More informationCODE WIDTH HEIGHT ARCHIVE ALIGN VSPACE, HSPACE ALT APPLET APPLET ALIGN IMG
Java 2003.11.4 Web Web Web Applet java.applet.applet Applet public void init () start public void start () public void stop () public void destroy () stop Applet Java.awt.Component Component public void
More informationICOM 4015: Advanced Programming
ICOM 4015: Advanced Programming Lecture 10 Reading: Chapter Ten: Inheritance Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 10 Inheritance Chapter Goals To learn about inheritance To
More informationCours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé. http://www.rzo.free.fr
Cours de Java Sciences-U Lyon Java - Introduction Java - Fondamentaux Java Avancé http://www.rzo.free.fr Pierre PARREND 1 Octobre 2004 Sommaire Java Introduction Java Fondamentaux Java Avancé GUI Graphical
More informationHow To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) (
Chapter 11. Graphical User Interfaces To this point in the text, our programs have interacted with their users to two ways: The programs in Chapters 1-5, implemented in Processing, displayed graphical
More informationGraphical User Interface Programming. Robert M. Dondero, Ph.D. Princeton University
Graphical User Interface Programming Robert M. Dondero, Ph.D. Princeton University 1 Objectives You will learn about: Graphical user interface (GUI) programming Specifically... For Java: The AWT/Swing
More informationJiST Graphical User Interface Event Viewer. Mark Fong mjf21@cornell.edu
JiST Graphical User Interface Event Viewer Mark Fong mjf21@cornell.edu Table of Contents JiST Graphical User Interface Event Viewer...1 Table of Contents...2 Introduction...3 What it does...3 Design...3
More information@ - Internal # - External @- Online TH PR OR TW TOTAL HOURS 04 --- 04 03 100 50# --- 25@ 175
COURSE NAME : COMPUTER ENGINEERING GROUP COURSE CODE SEMESTER SUBJECT TITLE : CO/CM/IF/CD : SIXTH : ADVANCED JAVA PROGRAMMING SUBJECT CODE : Teaching and Examination Scheme: @ - Internal # - External @-
More informationSkills and Topics for TeenCoder: Java Programming
Skills and Topics for TeenCoder: Java Programming Our Self-Study Approach Our courses are self-study and can be completed on the student's own computer, at their own pace. You can steer your student in
More informationHow Scala Improved Our Java
How Scala Improved Our Java Sam Reid PhET Interactive Simulations University of Colorado http://spot.colorado.edu/~reids/ PhET Interactive Simulations Provides free, open source educational science simulations
More informationKarsten Lentzsch JGoodies SWING WITH STYLE
Karsten Lentzsch JGoodies SWING WITH STYLE JGoodies: Karsten Lentzsch Open source Swing libraries Example applications Consultant for Java desktop Design assistance Training for visual design and implementation
More informationHow to Convert an Application into an Applet.
How to Convert an Application into an Applet. A java application contains a main method. An applet is a java program part of a web page and runs within a browser. I am going to show you three different
More informationRemote Method Invocation
Goal of RMI Remote Method Invocation Implement distributed objects. Have a program running on one machine invoke a method belonging to an object whose execution is performed on another machine. Remote
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 informationGraphical User Interfaces
M14_REGE1813_02_SE_C14.qxd 2/10/10 3:43 PM Page 822 Chapter14 Graphical User Interfaces 14.1 GUI Basics Graphical Input and Output with Option Panes Working with Frames Buttons, Text Fields, and Labels
More informationEvent-Driven Programming
Event-Driven Programming Lecture 4 Jenny Walter Fall 2008 Simple Graphics Program import acm.graphics.*; import java.awt.*; import acm.program.*; public class Circle extends GraphicsProgram { public void
More informationDev Articles 05/25/07 11:07:33
Java Crawling the Web with Java Contributed by McGraw Hill/Osborne 2005 06 09 Access Your PC from Anywhere Download Your Free Trial Take your office with you, wherever you go with GoToMyPC. It s the remote
More informationExtending Desktop Applications to the Web
Extending Desktop Applications to the Web Arno Puder San Francisco State University Computer Science Department 1600 Holloway Avenue San Francisco, CA 94132 arno@sfsu.edu Abstract. Web applications have
More informationHomework/Program #5 Solutions
Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the
More informationEssentials of the Java(TM) Programming Language, Part 1
Essentials of the Java(TM) Programming Language, Part 1 http://developer.java.sun.com/developer...ining/programming/basicjava1/index.html Training Index Essentials of the Java TM Programming Language:
More informationJava GUI Programming. Building the GUI for the Microsoft Windows Calculator Lecture 2. Des Traynor 2005
Java GUI Programming Building the GUI for the Microsoft Windows Calculator Lecture 2 Des Traynor 2005 So, what are we up to Today, we are going to create the GUI for the calculator you all know and love.
More informationJava is commonly used for deploying applications across a network. Compiled Java code
Module 5 Introduction to Java/Swing Java is commonly used for deploying applications across a network. Compiled Java code may be distributed to different machine architectures, and a native-code interpreter
More informationThe class JOptionPane (javax.swing) allows you to display a dialog box containing info. showmessagedialog(), showinputdialog()
// Fig. 2.8: Addition.java An addition program import javax.swing.joptionpane; public class Addition public static void main( String args[] ) String firstnumber, secondnumber; int number1, number2, sum;
More informationAppendix B Task 2: questionnaire and artefacts
Appendix B Task 2: questionnaire and artefacts This section shows the questionnaire, the UML class and sequence diagrams, and the source code provided for the task 1 (T2) Buy a Ticket Unsuccessfully. It
More informationpublic class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;
Lecture 15 The Game of "Craps" In the game of "craps" a player throws a pair of dice. If the sum on the faces of the pair of dice after the first toss is 7 or 11 the player wins; if the sum on the first
More informationEssentials of the Java Programming Language
Essentials of the Java Programming Language A Hands-On Guide by Monica Pawlan 350 East Plumeria Drive San Jose, CA 95134 USA May 2013 Part Number TBD v1.0 Sun Microsystems. Inc. All rights reserved If
More informationAdobe Digital Signatures in Adobe Acrobat X Pro
Adobe Digital Signatures in Adobe Acrobat X Pro Setting up a digital signature with Adobe Acrobat X Pro: 1. Open the PDF file you wish to sign digitally. 2. Click on the Tools menu in the upper right corner.
More informationDHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen
DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen Aufgabe 1 RMI - TimeService public interface TimeServerInterface extends Remote { public String gettime() throws RemoteException; import java.util.date;
More informationDuring the process of creating ColorSwitch, you will learn how to do these tasks:
GUI Building in NetBeans IDE 3.6 This short tutorial guides you through the process of creating an application called ColorSwitch. You will build a simple program that enables you to switch the color of
More informationMedientechnik. Übung MVC
Medientechnik Übung MVC Heute Model-View-Controller (MVC) Model programmieren Programmlogik Programmdaten Controller programmieren GUI Model Observer-Pattern Observable (Model) verwaltet Daten Observer
More informationCS108, Stanford Handout #33. Sockets
CS108, Stanford Handout #33 Fall, 2007-08 Nick Parlante Sockets Sockets Sockets make network connections between machines, but you just read/write/block on them like there were plain file streams. The
More informationSoftware Design: Figures
Software Design: Figures Today ColorPicker Layout Manager Observer Pattern Radio Buttons Prelimiary Discussion Exercise 5 ColorPicker They don't teach you the facts of death, Your mum and dad. They give
More informationCallbacks. Callbacks Copyright 2007 by Ken Slonneger 1
Callbacks Callbacks refer to a mechanism in which a library or utility class provides a service to clients that are unknown to it when it is defined. Suppose, for example, that a server class creates a
More informationAutomated Data Collection for Usability Evaluation in Early Stages of Application Development
Automated Data Collection for Usability Evaluation in Early Stages of Application Development YONGLEI TAO School of Computing and Information Systems Grand Valley State University Allendale, MI 49401 USA
More informationLAYOUT MANAGERS. Layout Managers Page 1. java.lang.object. java.awt.component. java.awt.container. java.awt.window. java.awt.panel
LAYOUT MANAGERS A layout manager controls how GUI components are organized within a GUI container. Each Swing container (e.g. JFrame, JDialog, JApplet and JPanel) is a subclass of java.awt.container and
More informationHere's the code for our first Applet which will display 'I love Java' as a message in a Web page
Create a Java Applet Those of you who purchased my latest book, Learn to Program with Java, know that in the book, we create a Java program designed to calculate grades for the English, Math and Science
More informationInking in MS Office 2013
VIRGINIA TECH Inking in MS Office 2013 Getting Started Guide Instructional Technology Team, College of Engineering Last Updated: Fall 2013 Email tabletteam@vt.edu if you need additional assistance after
More informationThe Basic Java Applet and JApplet
I2PUJ4 - Chapter 6 - Applets, HTML, and GUI s The Basic Java Applet and JApplet Rob Dempster robd@cs.ukzn.ac.za School of Computer Science University of KwaZulu-Natal Pietermaritzburg Campus I2PUJ4 - Chapter
More informationThe Design and Implementation of Multimedia Software
Chapter 3 Programs The Design and Implementation of Multimedia Software David Bernstein Jones and Bartlett Publishers www.jbpub.com David Bernstein (jbpub.com) Multimedia Software Jones and Bartlett 1
More informationTutorial: Time Of Day Part 2 GUI Design in NetBeans
Tutorial: Time Of Day Part 2 GUI Design in NetBeans October 7, 2010 Author Goals Kees Hemerik / Gerard Zwaan Getting acquainted with NetBeans GUI Builder Illustrate the separation between GUI and computation
More informationEvent processing in Java: what happens when you click?
Event processing in Java: what happens when you click? Alan Dix In the HCI book chapter 8 (fig 8.5, p. 298), notification-based user interface programming is described. Java uses this paradigm and you
More informationabstract windows toolkit swing
GUI abstract windows toolkit swing GUI Graphical User Interface let user enter data for application let user control processing steps display a view of data to user Graphical User Interface Mostly or entirely
More informationLab 9. Spam, Spam, Spam. Handout 11 CSCI 134: Spring, 2015. To gain experience with Strings. Objective
Lab 9 Handout 11 CSCI 134: Spring, 2015 Spam, Spam, Spam Objective To gain experience with Strings. Before the mid-90s, Spam was a canned meat product. These days, the term spam means just one thing unwanted
More informationData Director Create a New Answer Sheet
Data Director Create a New Answer Sheet DataDirector allows you to create answer sheets for assessments. Your answer sheet may contain multiple question types. Once the Answer Sheet is created and saved,
More informationTP #4 b. ClientBourse.java Classe principale du client graphique et fonction main. http://www.centraliup.fr.st
http://www.centraliup.fr.st Conception et Internet TP #4 b ClientBourse.java Classe principale du client graphique et fonction main import javax.swing.table.*; import javax.swing.event.*; import javax.swing.border.*;
More informationNexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability
Nexawebホワイトペーパー Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability Nexaweb Technologies, Inc. February 2012 Overview Many companies today are creating rich internet
More informationKonzepte objektorientierter Programmierung
Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 5: Frameworks Wintersemester 05/06 2 Homework 1 Observer Pattern From: Gamma, Helm,
More information1 Hour, Closed Notes, Browser open to Java API docs is OK
CSCI 143 Exam 2 Name 1 Hour, Closed Notes, Browser open to Java API docs is OK A. Short Answer For questions 1 5 credit will only be given for a correct answer. Put each answer on the appropriate line.
More informationGUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT COURSE CURRICULUM COURSE TITLE: ADVANCE JAVA PROGRAMMING (COURSE CODE: 3360701)
GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT COURSE CURRICULUM COURSE TITLE: ADVANCE JAVA PROGRAMMING (COURSE CODE: 3360701) Diploma Programme in which this course is offered Computer Engineering/
More informationGOPAL RAMALINGAM MEMORIAL ENGINEERING COLLEGE. Rajeshwari nagar, Panapakkam, Near Padappai, Chennai-601301.
GOPAL RAMALINGAM MEMORIAL ENGINEERING COLLEGE Rajeshwari nagar, Panapakkam, Near Padappai, Chennai-601301. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OOAD LAB MANUAL Sub. Code/Sub. Name: CS2357-Object
More informationJava Classes. GEEN163 Introduction to Computer Programming
Java Classes GEEN163 Introduction to Computer Programming Never interrupt someone doing what you said couldn't be done. Amelia Earhart Classes, Objects, & Methods Object-oriented programming uses classes,
More informationWindows Basics. Developed by: D. Cook
Windows Basics Developed by: D. Cook User Interface Hardware and Software Monitor Keyboard Mouse User friendly vs. MS-DOS GUI (graphical user interface) Launching Windows 2000 (XP) CTRL-ALT-DEL Desktop
More informationTutorial Reference Manual. Java WireFusion 4.1
Tutorial Reference Manual Java WireFusion 4.1 Contents INTRODUCTION...1 About this Manual...2 REQUIREMENTS...3 User Requirements...3 System Requirements...3 SHORTCUTS...4 DEVELOPMENT ENVIRONMENT...5 Menu
More informationOS X LION SET UP THE SYSTEM
OS X LION SET UP THE SYSTEM OS X Lion Set Up the System Last Edited: 2012-07-10 1 Personalize the Interface... 3 Organize the Desktop... 3 Configure Apple Trackpad... 4 Configure Apple Magic Mouse... 6
More informationChapter 28.9. Building a Game Pad Controller with JInput
Chapter 28.9. Building a Game Pad Controller with JInput Playing PC games with a keyboard and mouse can sometimes feel like playing tennis in a tuxedo entirely possible but not quite right. Wouldn't it
More informationMapping to the Windows Presentation Framework
Mapping to the Windows Presentation Framework This section maps the main IFML concepts to the.net Windows Presentation Framework (WFP). Windows Presentation Framework (WPF) is a part of.net Framework by
More informationHow To Create A Digital Signature Certificate
Tool. For Signing & Verification Submitted To: Submitted By: Shri Patrick Kishore Chief Operating Officer Sujit Kumar Tiwari MCA, I Year University Of Hyderabad Certificate by Guide This is certifying
More informationReference Guide for WebCDM Application 2013 CEICData. All rights reserved.
Reference Guide for WebCDM Application 2013 CEICData. All rights reserved. Version 1.2 Created On February 5, 2007 Last Modified August 27, 2013 Table of Contents 1 SUPPORTED BROWSERS... 3 1.1 INTERNET
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch11 Interfaces & Polymorphism PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,
More informationIntroduction to Computers: Session 3 Files, Folders and Windows
Introduction to Computers: Session 3 Files, Folders and Windows Files and folders Files are documents you create using a computer program. For example, this document is a file, made with a program called
More informationLab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.
Lab 1A. Create a simple Java application using JBuilder In this lab exercise, we ll learn how to use a Java integrated development environment (IDE), Borland JBuilder 2005, to develop a simple Java application
More informationHP LASER GAMING MOUSE USER MANUAL
HP LASER GAMING MOUSE USER MANUAL v1.0.en Part number: 513192-001 Contents Selecting a User Profile... 1 Customizing a User Profile... 2 Customizing DPI Profiles... 3 Selecting a DPI Profile... 3 Changing
More informationInternet Explorer 7 and Internet Explorer 8 Browser Security Settings
Internet Explorer 7 and Internet Explorer 8 Browser Security Settings From either the Menu Bar or the Tool Bar in your browser click on Tools. Select Internet Options which is the last item on the drop
More informationIntroduction to Microsoft PowerPoint
Introduction to Microsoft PowerPoint School of Medicine Library University of South Carolina WHAT IS POWERPOINT? PowerPoint (PPT) is a powerful, easy-to-use presentation graphics software program which
More informationGeneration and Handcoding
Farbe! Generative Software Engineering 3. Integrating Handwritten Code Prof. Dr. Bernhard Rumpe University http://www.se-rwth.de/ Page 2 Generation and Handcoding Not everything shall and can be generated
More informationREMOTE DESKTOP SETUP INSTRUCTIONS
REMOTE DESKTOP SETUP INSTRUCTIONS 1. Setting up your work desktop to allow Remote Desktop connectivity Windows does not have this feature enabled by default, so we will go through the steps on how to enable
More informationAutoboxing/Autounboxing
Autoboxing Autoboxing/Autounboxing public static void main(string args[]) { int dim=10; Pila s=new Pila(); // s= new Coda(); for (int k=0;k
More informationJIDE Action Framework Developer Guide
JIDE Action Framework Developer Guide Contents PURPOSE OF THIS DOCUMENT... 1 WHAT IS JIDE ACTION FRAMEWORK... 1 PACKAGES... 3 MIGRATING FROM EXISTING APPLICATIONS... 3 DOCKABLEBARMANAGER... 9 DOCKABLE
More informationEclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.
Eclipse with Mac OSX Java developers have quickly made Eclipse one of the most popular Java coding tools on Mac OS X. But although Eclipse is a comfortable tool to use every day once you know it, it is
More informationThis assignment explores the following topics related to GUI input:
6.831 User Interface Design & Implementation Fall 2004 PS3: Input Models This assignment explores the following topics related to GUI input: event handling; hit detection; dragging; feedback. In this problem
More informationInformatik II. // ActionListener hinzufügen btnconvert.addactionlistener(this); super.setdefaultcloseoperation(jframe.
Universität Augsburg, Institut für Informatik Sommersemester 2006 Prof. Dr. Werner Kießling 20. Juli. 2006 M. Endres, A. Huhn, T. Preisinger Lösungsblatt 11 Aufgabe 1: Währungsrechner CurrencyConverter.java
More informationHow to Use the Cypress Report Distribution Service to Access Reports
How to Use the Cypress Report Distribution Service to Access Reports First, if the Cypress client is not already installed on your computer, follow the installation instructions found at https://cypress.doit.wisc.edu/.
More informationJIDE Common Layer Developer Guide (Open Source Project)
JIDE Common Layer Developer Guide (Open Source Project) Contents PURPOSE OF THIS DOCUMENT... 4 WHY USING COMPONENTS... 4 WHY DO WE OPEN SOURCE... 5 HOW TO LEARN JIDE COMMON LAYER... 5 PACKAGE STRUCTURE...
More information