Automation of Java and Java Applications (GUI, awt)

Ähnliche Dokumente
Was passiert, wenn Button "Ok?" mit Maus angeklickt?

Objektorientierte Software-Entwicklung

Session 1: Classes and Applets

Vorlesung Informatik II

Ziel dieses Kapitels: Einführung in die Grundzüge der Programmierung graphischer Benutzeroberflächen (engl.: "graphical user interface", GUI) in Java

BSF4ooRexx Version 4.0

Ein Manager mit CardLayout layout/cards.java

J.1. J.1 GUI-Programmierung in in Java Prof. Dr. Rainer Manthey Informatik II 1

Prof. Dr. Oliver Haase Karl Martin Kern Achim Bitzer. Programmiertechnik GUI-Programmierung mit Swing

Kapitel 10. Event Handling 10.1 MVC

GRAFISCHE BENUTZERSCHNITTSTELLEN

Graphische Benutzungsoberflächen

I. Grundlagen II. Ereignistypen III. Ereignisempfänger. Event-Handling (EH)

Grafikprogrammierung mit Java Teil 1/2

NEWSLETTER. FileDirector Version 2.5 Novelties. Filing system designer. Filing system in WinClient

GUI Programmierung mit JAVA Swing

NTB Druckdatum:

Objektorientierte Programmierung

Java I Vorlesung 11 Graphische Oberflächen mit Swing

Einführung in die Informatik: Programmierung und Software-Entwicklung, WS 11/12. Kapitel 7. Grafische Benutzeroberflächen

Programmieren II. Java im Vergleich zu anderen Sprachen. Einführung: GUI. Einführung: Grafische Benutzeroberflächen. Dr.

p^db=`oj===pìééçêíáåñçêã~íáçå=

Liste Programmieren Java Überblick

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL USER GUIDE June 2016

Grundlagen der Programmierung APPLETS

25 Object Serialization

Seite Architektur interaktiver Systeme. 7. Architektur interaktiver Systeme. 7.1 Entkopplung durch Sichten. Schichtenarchitektur

6. Eventhandling in Java

Einführung in die Informatik: Programmierung und Software-Entwicklung, WS 15/16. Kapitel 7. Grafische Benutzeroberflächen 1

Cameraserver mini. commissioning. Ihre Vision ist unsere Aufgabe

GUIs in Java und ihre Programmierung

p^db=`oj===pìééçêíáåñçêã~íáçå=

Exercise (Part XI) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Aufbau einer typischen Java-Datei

OpenOffice.org. Ad-hoc-Generierung der API- Dokumentation

Zentrale Objekte zur Programmierung graphischer Benutzeroberflächen (GUI)

Wählen Sie das MySQL Symbol und erstellen Sie eine Datenbank und einen dazugehörigen User.

Grundlagen der Informatik für Ingenieure I

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL - USER GUIDE June 2016

11. GUI-Programmierung mit SWING Überblick

The 2011 Edition of BSF4ooRexx (for Windows, Linux and MacOSX)

Grundlagen der Informatik für Ingenieure I. 8. AWT - Abstract Window Toolkit Teil 1

AK-Automatisierungs und Kommunikationstechnik TI Technische Informatik. NWT Netzwerktechnik

JButton, JCheckBox, JRadioButton. Programmieren II. Vorlesung 7. Handout S. 1. Dr. Klaus Höppner. Hochschule Darmstadt Sommersemester 2009.

Softwarepraktikum: Enigma

Installation Guide/ Installationsanleitung. Spring 16 Release

7. Architektur interaktiver Systeme

ReadMe zur Installation der BRICKware for Windows, Version ReadMe on Installing BRICKware for Windows, Version 6.1.2

Exercise (Part VIII) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

AWT. Einfache AWT-Anwendung. Swing. Vorlesung 1. Handout S. 2. import java. awt. * ;

Programmentwicklung ohne BlueJ

August Macke Abschied, 1914 Museum Ludwig, Köln

Wiederholung: Objektorientierte Oberflächen-Programmierung mit Java und Swing

$ java awt.main A # typische Dekodierung $ java -Dtrace=all awt.main A # alle Events $ java -Dtrace=none awt.main A # keine Dekodierung

Institut für Informatik

Kurs OPR. Objektorientierte Programmierung

Titelbild1 ANSYS. Customer Portal LogIn

Exercise (Part I) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Einführung in die Programmierung Blockkurs Java

Techniken der Projektentwicklung

NVR Mobile Viewer for iphone/ipad/ipod Touch

<body> <h1>testseite für HTML-Parameter-Übergabe<br>50 Parameter werden übergeben</h1>

Einstieg in die Informatik mit Java

Programmier-Befehle - Woche 10

Eingabe von Texten. Vorlesung Software-Entwicklung / Folie 101

Universität Paderborn Prof. Dr. Stefan Böttcher. Kapitel 3: Java Applets

Benutzeroberflächen. Abstract Windowing Toolkit, Rahmen, Wächter, Ereignisbehandlung, Ausgabe, Menüs.

USB Treiber updaten unter Windows 7/Vista

Interaktive Elemente, GUI-Programmierung

Graphische Programmierung: GUIs: graphical user interfaces

DHBW Karlsruhe, Angewandte Informatik Programmieren in JAVA W. Geiger, T. Schlachter, C. Schmitt, W.

Employment and Salary Verification in the Internet (PA-PA-US)

public class Beispiel1 extends Frame {

1. General information Login Home Current applications... 3

Programmieren 2 Selbststudium Semesterwoche 4

Network premium POP UP Display

Automatisierung von Java Anwendungen (6)

SELF-STUDY DIARY (or Lerntagebuch) GER102

GUI Programmierung mit javax.swing

How to access licensed products from providers who are already operating productively in. General Information Shibboleth login...

HIR Method & Tools for Fit Gap analysis

Grafische Benutzeroberflächen Container Menüs JComponent JLabel/JTextField Buttons Events und Listener. Programmieren I.

GUI-Programmierung. Kapitel Der Window-Manager

Graphische Benutzeroberflächen mit Matlab

Der Adapter Z250I / Z270I lässt sich auf folgenden Betriebssystemen installieren:

How-To-Do. Hardware Configuration of the CC03 via SIMATIC Manager from Siemens

How-To-Do. Hardware Configuration of the CPU 317NET with external CPs on the SPEED Bus by SIMATIC Manager from Siemens

Algorithms for graph visualization

TIn 1: Feedback Laboratories. Lecture 4 Data transfer. Question: What is the IP? Institut für Embedded Systems. Institut für Embedded Systems


Getting started with MillPlus IT V530 Winshape

General info on using shopping carts with Ogone

Softwareschnittstellen

Swing :Komponenten I (Teil 2)

LiLi. physik multimedial. Links to e-learning content for physics, a database of distributed sources

Effizienz im Vor-Ort-Service

Programmieren II. Events (Ereignisse) Heusch 16.6 (2. Bd) Ratz 15. Institut für Angewandte Informatik

ONLINE LICENCE GENERATOR

Transkript:

MIS Department Automation of Java and Java Applications (GUI, awt) Bean Scripting Framework for oorexx (BSF4ooRexx), 2 Using Java Classes to Create and Use Platform Independent Graphical User Interfaces (GUI) Prof. Dr. Rony G. Flatscher Vienna University of Economics and Business Administration Wirtschaftsuniversität Wien Augasse 2-6 A-1090 Vienna Hier Automation Vortrags-/Vorlesungstitel Automatisierung of Java and von Java Windows Applications im Master Anwendungen eintragen (BSF4ooRexx (3) 2, GUI), p. 1 Prof. Dr. Rony G. Flatscher

Graphical User Interfaces with Java Basics of GUIs with Java Components Events Event adapters BSF4ooRexx-Example Processing events in a loop Using Java's awt from oorexx Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 2

Graphical User Interfaces, 1 Graphical User Interface Output Graphical (pixel-oriented) CRT Black/white, colour Speech Input Keyboard Mouse CRT Pen Speech Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 3

Graphical User Interfaces, 2 Output on pixel-oriented screen Addressing of screen Each picture element ("pixel") Two-dimensional co-ordinates ("x", "y") - Resolution e.g. 320x240, 640x480, 1024x768, 1280x1024,... Origin (i.e. co-ordinate: "0,0") - Left upper corner (e.g. Windows) - Left lower corner (e.g. OS/2) Colour Black/white (1 Bit per pixel) Three base colours - Red, green, blue ("RGB") - Intensity from 0 through 255-1 byte per base colour (2**8) Three base colours (2**8)**3 = 16.777.216 colours! Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 4

Graphical User Interfaces, 3 Amount of pixels, amount of bytes 640x480 307.200 px = 300 Kpx 38.400 bytes (b/w) = 37,5 KB 921.600 bytes (full colour) = 900 KB 1280x1024 1.310.720 px = 1.280 Kpx 163.840 bytes (b/w) = 160 KB 3.932.160 bytes (full colour) = 3.840 KB = 3,75 MB Computing intensive Look of each component must be programmed with individual pixels! E.g. Colour points, rectangles, circles, boxes, shadows, fonts,... Even animation effects! Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 5

Graphical User Interfaces, 4 Structure of elements/components ("Component"s), e.g. "Container" "Window" "Frame" "Panel" "Button" "Checkbox", "CheckboxGroup" ('Radio-Buttons') "Choice" "Image" Text fields "Label" (only for output) "TextField" (both, input and output) "TextArea" (both, input and output, multiple lines) "List", "Scrollbar", "Canvas",... Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 6

Graphical User Interfaces, 5 Component Button Canvas Checkbox Choice Container Label List Scrollbar TextComponent... JComponent Panel... Window... TextArea TextField... JButton JLabel... Applet... Frame JWindow... JApplet JFrame Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 7

Graphical User Interfaces, 6 "Component" Can create events, e.g. "ActionEvent", "KeyEvent", "MouseEvent",... Accept "EventListener" and send them events, by invoking the respective methods of the "EventListener"-objects Can be positioned in "Container"s "Container" A graphical "Component" Can contain other graphical components Contained "Component"s can be of type "Container" as well Contained components can be maintained and positioned with the help of layout manager "Frame" Extends/specializes the "Window" (a "Container") class Adds a frame and a title to a "Window" Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 8

"Hello, my beloved world", Graphically (Java) import java.awt.*; class HelloWorld { public static void main (String args[]) { Frame f = new Frame("Hello, my beloved world!"); f.show(); } } Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 9

"Hello, my beloved world", Graphically (oorexx).bsf~new('java.awt.frame', 'Hello, my beloved world - from oorexx.') ~show call SysSleep 10 ::requires BSF.CLS Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 10

Events, 1 Many events conceivable and possible, e.g. "ActionEvent" Important for components for which only one action is conceived, e.g. "Button" "ComponentEvent" "FocusEvent" "InputEvent" "KeyEvent" "MouseEvent" "WindowEvent" Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 11

Events, 2 Event interfaces are defined in interfaces of type "EventListener" C.f. Java online documentation for package "java.util" Important "EventListener" for graphical user interfaces Interface "ActionListener" void actionperformed (ActionEvent e) Interface "KeyListener" void keypressed (KeyEvent e) void keyreleased (KeyEvent e) void keytyped (KeyEvent e) Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 12

Events, 3 Important "EventListener" for graphical user interfaces... Interface "MouseListener" void mouseclicked ( MouseEvent e) void mouseentered ( MouseEvent e) void mouseexited ( MouseEvent e) void mousepressed ( MouseEvent e) void mousereleased( MouseEvent e) Interface "WindowListener" void windowactivated ( WindowEvent e) void windowclosed ( WindowEvent e) void windowclosing ( WindowEvent e) void windowdeactivated( WindowEvent e) void windowdeiconified( WindowEvent e) void windowiconified ( WindowEvent e) void windowopened ( WindowEvent e) Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 13

Events and Components Components create events Components accept "Listener" objects, which then will be informed of events that got created by the component Registration of "Listener" objects is possible with a void add...listener(...listener listener) e.g.: void addkeylistener (KeyListener kl) void addmouselistener (MouseListener ml) Information is carried out by invoking the "event method" that got defined in the respective interface, e.g. kl.keypressed (e); ml.mouseclicked (e); Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 14

Example "Input", 1 "TextField" Input field to allow for entering a name "Choice" Choice of "Mister" bzw. "Misses" "Button": "Revert" Reverts the input (clears the input) "Button": "Process Input" Accepts input Choice value and input text are read and output to "System.out" Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 15

Example "Input", 2 Considerations Which awt classes? "Frame", "Choice", "TextField", "Button" Which events? Closing the frame Event method "windowclosing" from "WindowListener" Using an adapter class - Otherwise we would need to implement seven (!) event methods! Pressing the respective "Button"s Event method "actionperformed" from "ActionListener" All other events are totally uninmportant for this particular application and get therefore ignored by us! Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 16

Example "Input", 3 Frame Button Choice TextField Button Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 17

"Input.java", Anonymous Java-Class import java.awt.*; import java.awt.event.*; class Input { public static void main (String args[]) { Frame f = new Frame("Please enter your name!"); f.addwindowlistener( new WindowAdapter() { public void windowclosing( WindowEvent e) { System.exit(0); } } ); f.setlayout(new FlowLayout()); // create a flow layout manager final Choice cf = new Choice(); cf.add("mister"); cf.add("misses"); f.add(cf); // add component to container final TextField tf = new TextField("", 50); // space for 50 characters f.add(tf); // add component to container Button bneu = new Button("Reset"); f.add(bneu); // add component to container bneu.addactionlistener( new ActionListener () { public void actionperformed(actionevent e) { tf.settext(""); cf.select("mister"); } } ); Button bok = new Button("Process Input"); f.add(bok); // add component to container bok.addactionlistener( new ActionListener () { public void actionperformed(actionevent e) { System.out.println(cf.getSelectedItem()+" "+tf.gettext()); System.exit(0); } } ); f.pack(); f.show(); } } Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 18

"Input.rex", oorexx f=.bsf~new("java.awt.frame", "Please Enter Your Name!") -- create frame f~bsf.addeventlistener( 'window', 'windowclosing', 'call BSF "exit"') - add event listener f~setlayout(.bsf~new("java.awt.flowlayout") ) -- create FlowLayout object and assign it cf=.bsf~new("java.awt.choice") -- create Choice object cf ~~add("mister") ~~add("missis") -- add options/choices f~add(cf) -- add Choice object to frame tf=.bsf~new("java.awt.textfield", "", 50) -- create TextField, show 50 chars f~add(tf) -- add TextField object to frame but=.bsf~new('java.awt.button', 'Reset') -- create Button object f~add(but) -- add Button object to frame but~bsf.addeventlistener('action', '', ' tf~settext("") ') -- add event listener to button but=.bsf~new('java.awt.button', 'Process Input') -- create Button object f~add(but) -- add Button object to frame but~bsf.addeventlistener( 'action', '', 'call done cf, tf')-- add event listener to button f ~~pack ~~setvisible(.true) ~~tofront -- layout the Frame object, show it, make sure it is in front do forever INTERPRET.bsf~bsf.pollEventText -- get event text, interpret it as Rexx code if result="shutdown, REXX!" then leave --Java will be exited, leave Rexx end exit /* called, if the "done" button is pressed and the according eventtext gets sent */ done: procedure use arg cf, tf say cf~getselecteditem tf~gettext return.bsf~bsf.exit /* shutdown JVM in.1sec, in case this program was started via Java */ ::requires BSF.cls -- load Object Rexx BSF support Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 19

BsfRexxProxy(), 1 Rexx-Objekte für Java verfügbar machen BsfCreateRexxProxy(ooRexx-Objekt[, userdata [, xyz] ]) userdata xyz optionales weiteres Rexx-Objekt, das mit den Java-Nachrichten mitgeschickt werden kann optionales Argument xyz (optional gefolgt von weiteren Argumenten) - ein oder mehrere Java-Interface-Klassen, bzw. - eine einzelne abstrakte Java-Klasse, optional gefolgt von Argumenten für das Erzeugen einer Java-Instanz Retourniert ein Java-Objekt, das man Nachrichten für Java- Objekten als Argument mitgeben kann! Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 20

BsfRexxProxy(), 2 BsfCreateRexxProxy(ooRexx-Objekt[, userdata [, xyz]...]) Java-Nachrichten wird ein weiteres Argument immer das allerletzte Argument "slotdir" mit folgenden, möglichen Einträgen - "USERDATA", liefert oorexx-objekt "userdata", wenn es angegeben wurde - "METHODOBJECT", liefert das Java-Methodenobjekt, wenn das RexxProxy für ein Java-Interface definiert wurde - "METHODNAME", liefert exakte Groß- und Kleinschreibung der Java- Methode - "METHODDESCRIPTOR", liefert oorexx-zeichenkette mit Signatur der Java-Methode - "JAVAOBJECT", liefert das Java-Objekt, für das das Rexx-Objekt aufgerufen wird (erlaubt das Senden von Java-Nachrichten von der oorexx-seite aus) Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 21

BsfRexxProxy(), 3 BsfCreateRexxProxy( ) Erlaubt es, (abstrakte) Java-Interface-Methoden mit Hilfe von oorexx-methoden zu implementieren Ermöglicht es solche Rexx-Objekte in Java-RexxProxy-Objekten einzupacken Java-RexxProxy-Objekte können anschließend als Argumente für alle Java-Interfaces verwendet werden, die bei BsfCreateRexxProxy( ) angegeben wurden Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 22

RexxProxy-Beispiel anhand von "input.rex", 1 Vorgehen Es werden für jene awt-objekte Rexx-EventHandler-Klassen definiert, an deren Ereignissen wir interessiert sind Wenn in den Rexx-EventHandler-Klassen auf awt-objekte zugegriffen werden soll, dann werden diese z.b. in einem oorexx-directory "userdata" aufgenommen Beim Erzeugen eines Java-RexxProxy-Objektes wird angegeben, für welche(s) Java-Interface(s) es benutzbar sein soll bestimmen, ob "userdata" als Argument angegeben werden soll Zuweisen der RexxProxy-Objekte an die entsprechenden awt- Objekte mit der entsprechenden "add Listener"-Methode Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 23

RexxProxy-Beispiel anhand von "input.rex", 2 userdata =.directory~new -- a directory which will be passed to Rexx with the event rexxcloseeh =.RexxCloseAppEventHandler~new -- Rexx event handler userdata~rexxcloseeh=rexxcloseeh -- save Rexx event handler for later use rpcloseeh = BsfCreateRexxProxy(rexxCloseEH,, "java.awt.event.windowlistener") f=.bsf~new("java.awt.frame", "Please Enter Your Name!") -- create frame f~addwindowlistener(rpcloseeh) -- add RexxProxy event handler f~setlayout(.bsf~new("java.awt.flowlayout") ) -- create FlowLayout object and assign it cf=.bsf~new("java.awt.choice") -- create Choice object userdata~cf=cf -- add choice field for later use cf ~~add("mister") ~~add("missis") -- add options/choices f~add(cf) -- add Choice object to frame tf=.bsf~new("java.awt.textfield", "", 50) -- create TextField, show 50 chars userdata~tf=tf -- add text field for later use f~add(tf) -- add TextField object to frame but=.bsf~new('java.awt.button', 'Reset') -- create Button object f~add(but) -- add Button object to frame rp=bsfcreaterexxproxy(.rexxreseteventhandler~new, userdata, "java.awt.event.actionlistener") but~addactionlistener(rp) -- add RexxProxy event handler but=.bsf~new('java.awt.button', 'Process Input') -- create Button object f~add(but) -- add Button object to frame rp=bsfcreaterexxproxy(.rexxprocesseventhandler~new, userdata, "java.awt.event.actionlistener") but~addactionlistener(rp) -- add RexxProxy event handler f ~~pack ~~setvisible(.true)~~tofront -- layout the Frame object, show it, make sure it is in front rexxcloseeh~waitforexit -- wait until we are allowed to end the program call SysSleep.2 -- let Java's RexxProxy finalizations find a running Rexx instance ::requires BSF.cls -- load Object Rexx BSF support --... continued on next page... Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 24

RexxProxy-Beispiel anhand von "input.rex", 3 /* Rexx event handler to set "close app" indicator: "java.awt.event.windowlistener" */ ::class RexxCloseAppEventHandler ::method init /* constructor */ expose closeapp closeapp =.false -- if set to.true, then it is safe to close the app ::attribute closeapp -- indicates whether app should be closed ::method unknown ::method windowclosing expose closeapp closeapp=.true -- intercept unhandled events, do nothing -- event method (from WindowListener) -- indicate that the app should close ::method waitforexit -- method blocks until attribute is set to.true expose closeapp guard on when closeapp=.true /* Rexx event handler: "java.awt.event.actionlistener" */ ::class RexxResetEventHandler ::method actionperformed use arg eventobject, slotdir slotdir~userdata~tf~settext("") -- get text field and set it to empty string slotdir~userdata~cf~select("mister") -- reset choice /* Rexx event handler : "java.awt.event.actionlistener" */ ::class RexxProcessEventHandler ::method actionperformed use arg eventobject, slotdir userdata=slotdir~userdata -- get 'userdata' directory say userdata~cf~getselecteditem userdata~tf~gettext -- show input userdata~rexxcloseeh~closeapp=.true -- make sure main program ends Automation of Java and Java Applications (BSF4ooRexx 2, GUI), p. 25