Java Appletek II. Applet GUI



Similar documents
Advanced Network Programming Lab using Java. Angelos Stavrou

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html

How To Write A Program For The Web In Java (Java)

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

Using A Frame for Output

Homework/Program #5 Solutions

Informatik II. // ActionListener hinzufügen btnconvert.addactionlistener(this); super.setdefaultcloseoperation(jframe.

Dev Articles 05/25/07 11:07:33

Graphical User Interfaces

CS 335 Lecture 06 Java Programming GUI and Swing

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Java Appletek I. Java és GUI-k. .'~tj;i~e~tu"eg~ye'l"rne(;lb9.$ha redorganili ngprincipies. ,fromdrugdevelopmentto Internet security

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

Essentials of the Java(TM) Programming Language, Part 1

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Animazione in Java. Animazione in Java. Problemi che possono nascere, e loro soluzione. Marco Ronchetti Lezione 1

XML nyelvek és alkalmazások

method is never called because it is automatically called by the window manager. An example of overriding the paint() method in an Applet follows:

How to Convert an Application into an Applet.

CS506 Web Design and Development Solved Online Quiz No. 01

Programming with Java GUI components

Building a Multi-Threaded Web Server

11. Applets, normal window applications, packaging and sharing your work

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

An Overview of Java. overview-1

Essentials of the Java Programming Language

Network Traffic based Application Identification Demonstrator (Net AI) GUI. Kenny Nguyen

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

Tutorial Reference Manual. Java WireFusion 4.1

Introduction to the Java Programming Language

public class demo1swing extends JFrame implements ActionListener{

The following four software tools are needed to learn to program in Java:

Chapter 2 Introduction to Java programming

How To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) (

Creating a Simple, Multithreaded Chat System with Java

The Basic Java Applet and JApplet

Division of Informatics, University of Edinburgh

Lösningsförslag till tentamen

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Files and input/output streams

How Scala Improved Our Java

OBJECT ORIENTED PROGRAMMING LANGUAGE

During the process of creating ColorSwitch, you will learn how to do these tasks:

JiST Graphical User Interface Event Viewer. Mark Fong

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;

Swing. A Quick Tutorial on Programming Swing Applications

Building a Java chat server

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal

Fundamentals of Java Programming

Lesson: All About Sockets

Logging in Java Applications

LAYOUT MANAGERS. Layout Managers Page 1. java.lang.object. java.awt.component. java.awt.container. java.awt.window. java.awt.panel

Fachbereich Informatik und Elektrotechnik Java Applets. Programming in Java. Java Applets. Programming in Java, Helmut Dispert

WEEK 2 DAY 14. Writing Java Applets and Java Web Start Applications

CS108, Stanford Handout #33. Sockets

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

public static void main(string[] args) { System.out.println("hello, world"); } }

Java applets. SwIG Jing He

Analysis Of Source Lines Of Code(SLOC) Metric

Course/Year W080/807 Expected Solution Subject: Software Development to Question No: 1

CS 121 Intro to Programming:Java - Lecture 11 Announcements

Coding Standard for Java

Introduction to Java

Using NetBeans IDE for Desktop Development. Geertjan Wielenga

JAVA Program For Processing SMS Messages

BCA 421- Java. Tilak Maharashtra University. Bachelor of Computer Applications (BCA) 1. The Genesis of Java

Szervletek. ANTAL Margit. Sapientia - EMTE, Pannon Forrás,,Egységes erdélyi felnőttképzés a


Tutorial: Getting Started

B.Sc (Honours) - Software Development

Socket-based Network Communication in J2SE and J2ME

Konzepte objektorientierter Programmierung

Java SE 6 Update 10. la piattaforma Java per le RIA. Corrado De Bari. Sun Microsystems Italia Spa. Software & Java Ambassador

Java Interview Questions and Answers

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

13 File Output and Input

Continuous Integration Part 2

CISC 4700 L01 Network & Client- Server Programming Spring Harold, Chapter 8: Sockets for Clients

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Extending Desktop Applications to the Web

Schueler-Organisiertes Lernen am Beispiel von Grafischen Benutzer-Schnittstellen in Java Tag der Offenen Tür - GTS 2008

Prof. Edwar Saliba Júnior

How To Program In Java (Ipt) With A Bean And An Animated Object In A Powerpoint (For A Powerbook)

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Summer Internship 2013

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

JIDE Action Framework Developer Guide

Here's the code for our first Applet which will display 'I love Java' as a message in a Web page

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Final Project Report E3390 Electronic Circuit Design Lab. Electronic Notepad

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Assignment No.3. /*-- Program for addition of two numbers using C++ --*/

@ - Internal # - Online TH PR OR TW TOTAL HOURS # @ 175

Section 6 Spring 2013

Computing Concepts with Java Essentials

Java is commonly used for deploying applications across a network. Compiled Java code

Capabilities of a Java Test Execution Framework by Erick Griffin

Transcription:

THE INTERNET,mapped on the opposite page, is a scalefree network in that Java Appletek II. dis.'~tj port,from BYALBERTU\SZLOBARABASI ANDERICBONABEAU THE INTERNET,mapped on the opposite page, is a scalefree network in that BYALBERTU\SZLOBARABASI ANDERICBONABEAU 2 Applet GUI Az appletek a böngész! ablakában jelennek meg háttér szín paraméter meghatározott méret platformok layout manager Az applet osztályok letöltése a hálózaton alosztályok

THE INTERNET,mapped on the opposite page, is a scalefree network in that BYALBERTU\SZLOBARABASI ANDERICBONABEAU 3 Standard out Diagnosztikai, debug üzenetek standard out, standard error System.out, System.err Appletviewer consol ablak shell ablak Célszer"en kikapcsolható kiírás THE INTERNET,mapped on the opposite page, is a scalefree network in that 4 Rendszer tulajdonságok M"ködési környezet tulajdonságai java.util.properties System.getProperty BYALBERTU\SZLOBARABASI ANDERICBONABEAU "file.separator" File separator (for example, "/") "java.class.version" Java class version number "java.vendor" Java vendorspecific string "java.vendor.url" Java vendor URL "java.version" Java version number "line.separator" Line separator "os.arch" Operating system architecture "os.name" Operating system name "path.separator" Path separator (for example, ":")

THE INTERNET,mapped on the opposite page, is a scalefree network in that 5 import java.awt.*; import java.awt.event.*; import javax.swing.*; Rendszer tulajdonságok (pl.) public class GetOpenProperties extends JApplet { private String[] propertynames = {"file.separator", "line.separator", "path.separator", "java.class.version", "java.vendor", "java.vendor.url", "java.version", "os.name", "os.arch", "os.version"; private final int numproperties = propertynames.length; private JLabel[] values; private javax.swing.timer timer; private int currentpropnum = 0; public void init() { ;i~e~tu"eg~ye'l"rne(;lb9.$ha redorganili //Execute ngprincipies. a job on the eventdispatching thread: //creating this applet's GUI. SwingUtilities.invokeAndWait(new Runnable() { BYALBERTU\SZLOBARABASI ANDERICBONABEAU public void run() { creategui(); ); catch (Exception e) { System.err.println("createGUI didn't successfully complete"); public void start() { //Update the GUI every 1/4 second or so. timer = new javax.swing.timer(250, new PropertyUpdater()); timer.setcoalesce(false); timer.start(); public void stop() { if (timer!= null) { timer.stop(); public void destroy() { //Execute a job on the eventdispatching thread: //destroying this applet's GUI. SwingUtilities.invokeAndWait(new Runnable() { public void run() { remove(getcontentpane()); ); catch (Exception e) { THE INTERNET,mapped on the opposite page, is a scalefree network in that 6 Rendszer tulajdonságok (pl.) private void creategui() { JPanel contentpane = new JPanel(new GridBagLayout()); GridBagConstraints labelconstraints = new GridBagConstraints(); GridBagConstraints valueconstraints = new GridBagConstraints(); labelconstraints.anchor = GridBagConstraints.WEST; labelconstraints.ipadx = 10; valueconstraints.fill = GridBagConstraints.HORIZONTAL; valueconstraints.gridwidth = GridBagConstraints.REMAINDER; valueconstraints.weightx = 1.0; //Extra space to values column. for (int i = 0; i < numproperties; i++) { names[i] = new JLabel(propertyNames[i]); names[i].setfont(propertyfont); contentpane.add(names[i], labelconstraints); values[i] = new JLabel(firstValue); values[i].setfont(valuefont); contentpane.add(values[i], valueconstraints); names[i].setlabelfor(values[i]); BYALBERTU\SZLOBARABASI ANDERICBONABEAU //Set up the Label arrays. JLabel[] names = new JLabel[numProperties]; values = new JLabel[numProperties]; String firstvalue = "<not read yet>"; //Fonts Font headingfont = new Font("SansSerif", Font.BOLD, 14); Font propertyfont = new Font("SansSerif", Font.BOLD, 12); Font valuefont = new Font("SansSerif", Font.PLAIN, 12); //Add headings. contentpane.add(createheading("property Name", headingfont), labelconstraints); contentpane.add(createheading("value", headingfont), valueconstraints); contentpane.setborder(borderfactory.createcompoundborder( BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5,20,5,10))); setcontentpane(contentpane); private JLabel createheading(string text, Font font) { JLabel l = new JLabel(text); l.setfont(font); l.setborder(borderfactory.createcompoundborder( BorderFactory.createEmptyBorder(0,0,5,0), BorderFactory.createMatteBorder(0,0,1,0,Color.black))); return l;

THE INTERNET,mapped on the opposite page, is a scalefree network in that 7 Rendszer tulajdonságok (pl.) private class PropertyUpdater implements ActionListener { private String value; public void actionperformed(actionevent e) { if (currentpropnum < numproperties) { value = System.getProperty(propertyNames[currentPropNum]); if (value == null) { value = "<null value!>"; values[currentpropnum].settext(value); catch (SecurityException exc) { values[currentpropnum].settext("could not read: SECURITY EXCEPTION!"); currentpropnum++; else { timer.stop(); BYALBERTU\SZLOBARABASI ANDERICBONABEAU THE INTERNET,mapped on the opposite page, is a scalefree network in that 8 Többszálúság BYALBERTU\SZLOBARABASI ANDERICBONABEAU Id!igényes taszk végrehajtása a eseménykezelés felfüggesztése nélkül Periódikusan ismétl!d! tevékenységek végrehajtása Szerver alkalmazások

THE INTERNET,mapped on the opposite page, is a scalefree network in that BYALBERTU\SZLOBARABASI ANDERICBONABEAU 9 Swing és a szálak Swing komponensek általában nem támogatják a többszálon való hozzáférés (nem thread safeek) hozzáférés csak az eseménykezel! szálon komponens realizálás >eseménykezel! szál Swing komponens megrajzolása, eseménykezelés paint(), ActionPerformed() THE INTERNET,mapped on the opposite page, is a scalefree network in that 10 Swing és a szálak (folyt.) BYALBERTU\SZLOBARABASI ANDERICBONABEAU public class MyApplication { public static void main(string[] args) { JFrame f = new JFrame("Labels"); // Add components to // the frame here... f.pack(); realizálás f.show(); // Don't do any more GUI work here... biztonságos

THE INTERNET,mapped on the opposite page, is a scalefree network in that 11 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Swing és a szálak (folyt.) Applet GUI létrehozható az init() metódusban realizálás start()kor ne legyen id!igényes init() külön szál indítása Thread safe bárhonnan repaint(), revalidate() add...listener(), remove...listener() THE INTERNET,mapped on the opposite page, is a scalefree network in that 12 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Swing és a szálak (folyt.) Realizált GUI UIevent (AWT event) driven m"ködes GUI update igény más forrásból (nem AWT event) invokeandwait(), invokelater()

THE INTERNET,mapped on the opposite page, is a scalefree network in that 13 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Swing és a szálak (folyt.) Szálak Swing barát létrehozása Timer class periódikus tevékenységekhez actionperformed() metódus végrehajtása az eseménykezel! szálon THE INTERNET,mapped on the opposite page, is a scalefree network in that 14 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Többszálú appletek Az appletnek lehet több szála GUI létrehozása az eseménykezel! szálból init, start, stop, destroy nem kerül meghívásra innen Szálak használata Id!igényes inicializálás Animáció

THE INTERNET,mapped on the opposite page, is a scalefree network in that 15 using import like colors forjavax.swing.*; similar Webaddresses. import java.awt.*; public class PrintThread extends JApplet { Szálak példa 1. public void start() { additem("start: " + threadinfo(thread.currentthread()), false); //not on eventdispatching thread JTextArea display; public void init() { //Execute a job on the eventdispatching thread: //creating this applet's GUI. SwingUtilities.invokeAndWait(new Runnable() { public void run() { creategui(); ); catch (Exception e) { System.err.println("createGUI didn't successfully complete"); additem("init: " + threadinfo(thread.currentthread()), false); //not on eventdispatching thread private void creategui() { //Create the text area and make it uneditable. display = new JTextArea(1, 80); display.seteditable(false); BYALBERTU\SZLOBARABASI ANDERICBONABEAU //Set the layout manager so that the text area //will be as wide as possible. getcontentpane().setlayout(new GridLayout(1,0)); public void stop() { additem("stop: " + threadinfo(thread.currentthread()), false); //not on eventdispatching thread public void destroy() { additem("destroy: " + threadinfo(thread.currentthread()), false); //not on eventdispatching thread //Execute a job on the eventdispatching thread: //destroying this applet's GUI. SwingUtilities.invokeAndWait(new Runnable() { public void run() { getcontentpane().removeall(); additem("doing removeall: " + threadinfo(thread.currentthread()), true); //on eventdispatching thread ); catch (Exception e) { String threadinfo(thread t) { return "thread=" + t.getname() + ", " + "thread group=" + t.getthreadgroup().getname(); //Add the text area (in a scroll pane) to the applet. getcontentpane().add(new JScrollPane(display)); additem("creategui: " + threadinfo(thread.currentthread()), true); //on eventdispatching thread THE INTERNET,mapped on the opposite page, is a scalefree network in that 16 Szálak példa 1. (folyt.) void additem(string newword, boolean onedt) { final String s = newword + "\n"; System.out.println(newWord); if (onedt) { display.append(s); else { //Execute a job on the eventdispatching thread: //updating this applet's GUI. SwingUtilities.invokeAndWait(new Runnable() { public void run() { display.append(s); ); catch (Exception e) { BYALBERTU\SZLOBARABASI ANDERICBONABEAU

THE INTERNET,mapped on the opposite page, is a scalefree network in that 17 Szálak példa 2. import java.awt.*; import java.applet.applet; /* * Based on Arthur van Hoff's animation examples, this applet * can serve as a template for all animation applets. */ public class AnimatorApplet extends Applet implements Runnable { int framenumber = 1; int delay; Thread animatorthread; boolean frozen = false; public void init() { String str; int fps = 10; public void start() { if (frozen) { //Do nothing. The user has requested that we //stop changing the image. else { //Start animating! if (animatorthread == null) { animatorthread = new Thread(this); animatorthread.start(); public void stop() { //Stop the animating thread. animatorthread = null; BYALBERTU\SZLOBARABASI ANDERICBONABEAU //How many milliseconds between frames? str = getparameter("fps"); if (str!= null) { fps = Integer.parseInt(str); catch (Exception e) { delay = (fps > 0)? (1000 / fps) : 100; public boolean mousedown(event e, int x, int y) { if (frozen) { frozen = false; start(); else { frozen = true; stop(); return true; THE INTERNET,mapped on the opposite page, is a scalefree network in that 18 Szálak példa 2. (folyt.) public void run() { //Just to be nice, lower this thread's priority //so it can't interfere with other processing going on. Thread.currentThread().setPriority(Thread.MIN_PRIORITY); //Remember the starting time. long starttime = System.currentTimeMillis(); //This is the animation loop. while (Thread.currentThread() == animatorthread) { //Advance the animation frame. framenumber++; //Display it. repaint(); //Delay depending on how far we are behind. starttime += delay; Thread.sleep(Math.max(0, starttimesystem.currenttimemillis())); catch (InterruptedException e) { break; BYALBERTU\SZLOBARABASI ANDERICBONABEAU //Draw the current frame of animation. public void paint(graphics g) { g.drawstring("frame " + framenumber, 0, 30);

THE INTERNET,mapped on the opposite page, is a scalefree network in that 19 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Szálak példa 3. getaudioclip csak miután végzett tér vissza betöltés különszálon termel!/fogyasztó felállás SoundLoader/SoundExample SoundList THE INTERNET,mapped on the opposite page, is a scalefree network in that 20 Együttm!ködés szerveroldali alkalmzásokkal BYALBERTU\SZLOBARABASI ANDERICBONABEAU java.net csomag használható csak azzal a hoszttal, melyr!l az applet jött getcodebase().gethost() t"zfalak?

THE INTERNET,mapped on the opposite page, is a scalefree network in that 21 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Biztonsági korlátok megkerülése szerverrel Applet nem írhat és olvashat fájlokat a helyi fájlrendszeren adatok tárolása szerver alk. segítségével Hálózati kapcsolat csak a származási hoszttal szerver alk. építi ki a hálózati kapcsolatot más hosztokhoz Applet nem indíthat alkalmazásokat a futtató gépen szerveroldalon futhatnak alkalmazások THE INTERNET,mapped on the opposite page, is a scalefree network in that 22 BYALBERTU\SZLOBARABASI ANDERICBONABEAU A kész applet Debug konzol üzenetek kikapcsolva O# screen nem fogyaszt CPUt stop() metódus hang kikapcsolható getparameterinfo() getappletinfo()

THE INTERNET,mapped on the opposite page, is a scalefree network in that JNLP és Java Web Start dis.'~tj port,from BYALBERTU\SZLOBARABASI ANDERICBONABEAU THE INTERNET,mapped on the opposite page, is a scalefree network in that 24 BYALBERTU\SZLOBARABASI ANDERICBONABEAU Java Web Start Java alkalmazások elérése Web szerveren keresztül böngész! kontextuson kívüli végrehajtás végrahajtás homokozóban hozzáférési kérések kliens oldalon Java Web Start szerveroldal megfelel!en csomagolt alkalmazás Java Network Launch Protocol

THE INTERNET,mapped on the opposite page, is a scalefree network in that 25 Java Web Start példa import java.awt.*; import javax.swing.*; import java.io.*; import java.net.*; public class TheTime { public static void main(string args[]) { JFrame frame = new JFrame("Time Check"); frame.setdefaultcloseoperation(jframe.exit_on_close); JLabel label = new JLabel(); Container content = frame.getcontentpane(); content.add(label, BorderLayout.CENTER); String message = "missing"; BufferedReader reader = null; Socket socket = new Socket("time.nist.gov", 13); InputStream is = socket.getinputstream(); InputStreamReader isr = new InputStreamReader(is); reader = new BufferedReader(isr); reader.readline(); // skip blank line message = reader.readline(); catch (MalformedURLException e) { System.err.println("Malformed: " + e); catch (IOException e) { System.err.println("I/O Exception: " + e); finally { BYALBERTU\SZLOBARABASI ANDERICBONABEAU if (reader!= null) { reader.close(); catch (IOException ignored) { label.settext(message); frame.pack(); frame.show(); TheTime.java THE INTERNET,mapped on the opposite page, is a scalefree network in that 26 Java Web Start példa (folyt.) <?xml version="1.0" encoding="utf8"?> <jnlp spec="1.0+" codebase="file:///c:/jdc/jnlp/" > <information> <title>time Check</title> <vendor>java Developer Connection</vendor> <homepage href="/jdc" /> <description>demonstration of JNLP</description> </information> <offlineallowed/> <security> <j2eeapplicationclientpermissions/> </security> <resources> <j2se version="1.2+" /> <jar href="/developer/technicalarticles/programming/jnlp/jnlptime.jar"/> </resources> <applicationdesc mainclass="thetime" /> </jnlp> BYALBERTU\SZLOBARABASI ANDERICBONABEAU time.jnlp

a 27 THE INTERNET,mapped on the opposite page, is a scalefree network in that traces the shortest routes from a test Web sinho about 100,000 others, Java Web Start példa (folyt.) using like colors for similar Web addresses. s J;i~e~tu"eg~Ye'l"rne(;lb9.$ha red organili ng principies. t m a BYALBERTU\SZLO BARABASI ANDERICBONABEAU 28 THE INTERNET,mapped on the opposite page, is a scalefree network in that traces the shortest routes from a test Web sinho about 100,000 others, using like colors for similar Web addresses. s J;i~e~tu"eg~Ye'l"rne(;lb9.$ha red organili ng principies. t m BYALBERTU\SZLO BARABASI ANDERICBONABEAU Java Web Start példa (folyt.)