CODE WIDTH HEIGHT ARCHIVE ALIGN VSPACE, HSPACE ALT APPLET APPLET ALIGN IMG



Similar documents
Using A Frame for Output

core 2 Handling Mouse and Keyboard Events

public class Application extends JFrame implements ChangeListener, WindowListener, MouseListener, MouseMotionListener {

Java Mouse and Keyboard Methods

CS 335 Lecture 06 Java Programming GUI and Swing

Advanced Network Programming Lab using Java. Angelos Stavrou

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

java.applet Reference

How to Convert an Application into an Applet.

Tutorial Reference Manual. Java WireFusion 4.1

Java Appletek II. Applet GUI

There are some important differences between an applet and a standalone Java application, including the following:

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

Graphical User Interfaces

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

An Overview of Java. overview-1

Remote Method Invocation

The Basic Java Applet and JApplet

abstract windows toolkit swing

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

Event-Driven Programming

Essentials of the Java Programming Language

Mouse Event Handling (cont.)

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

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

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

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

Tutorial: Building a Java applet

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

Using the Beans Development Kit 1.0. September A Tutorial. Alden DeSoto. Sept Garcia Avenue Mountain View, CA U.S.A.

Java Example. A First Java Program. Pixels, Rasters, Sprites, and BitBlts. Exercise #1. Experiencing JAVAphobia?

Homework/Program #5 Solutions

GUI Components: Part 2

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

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

MillMedia Guidelines

The Design and Implementation of Multimedia Software

Chapter 1 Java Program Design and Development

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

JAVA DEVELOPER S GUIDE TO ASPRISE SCANNING & IMAGE CAPTURE SDK

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

Introduction to Java Applets (Deitel chapter 3)

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

XHTML BASICS. Institute of Finance Management CIT Department Herman Mandari

Web Development and Core Java Lab Manual V th Semester

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

Website Login Integration

core 2 Applets and Basic Graphics

JAVA Program For Processing SMS Messages

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

How to create buttons and navigation bars

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

CSS Techniques: Scrolling gradient over a fixed background

GUI Event-Driven Programming

How to develop your own app

Working with forms in PHP

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

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

Chapter 1 Programming Languages for Web Applications

Implementing Specialized Data Capture Applications with InVision Development Tools (Part 2)

Java applets. SwIG Jing He

Fireworks 3 Animation and Rollovers

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

JavaScript and Dreamweaver Examples

Internet Technologies

Hello World RESTful web service tutorial

1 Hour, Closed Notes, Browser open to Java API docs is OK

Tutorial 8: Quick Form Button

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

Interview Questions in Core Java

Interactive Programs and Graphics in Java

Software Design: Figures

Simple Line Drawing. Description of the Simple Line Drawing program

CSS - Cascading Style Sheets

Cisco Adaptive Security Appliance (ASA) Web VPN Portal Customization: Solution Brief

JAVA - MULTITHREADING

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

Chapter 2 Introduction to Java programming

Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad Spring 2013

Introduction to XHTML. 2010, Robert K. Moniot 1

ICE: HTML, CSS, and Validation

Tema: Encriptación por Transposición

An Attribute is a special word used inside tag to specify additional information to tag such as color, alignment etc.

Transcription:

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 paint () EventListener implements EventListener Web HTML APPLET <APPLET CODE = appletfile WIDTH = pixels HEIGHT = pixels> </APPLET> CODE WIDTH HEIGHT ARCHIVE ALIGN VSPACE, HSPACE ALT APPLET APPLET ALIGN IMG 20

Java 2003.11.4 GUI java.awt GUI Canvas MyCanvas Jikken.java import java.applet.applet; import java.awt.*; import java.awt.event.*; import javax.imageio.*; import java.net.*; /** */ public class JikkenApplet extends Applet implements ActionListener, ItemListener, AdjustmentListener, MouseListener, MouseMotionListener, WindowListener, KeyListener { Button button, button1, button2; // Checkbox check[]; // CheckboxGroup group; // Choice choice; // Dialog dialog; // Frame frame; Image image; Label label; // // // List list1, list2; // Scrollbar scroll; // TextArea textarea; // TextField textfield1, textfield2; // Panel panel1, panel2, panel3; // MyCanvas canvas; public void init() { GridBagLayout gridbag = new GridBagLayout(); setlayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridheight = 2; makepanel1(); gridbag.setconstraints(panel1, c); add(panel1); c.weightx = 1.0; canvas = new MyCanvas(); gridbag.setconstraints(canvas, c); canvas.addmouselistener(this); canvas.addmousemotionlistener(this); add(canvas); canvas.addkeylistener(this); 21

c.weightx = 0.0; c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER; makepanel2(); gridbag.setconstraints(panel2, c); add(panel2); makepanel3(); gridbag.setconstraints(panel3, c); add(panel3); c.weightx = 1.0; c.weighty = 1.0; c.gridheight = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER; textarea = new TextArea("TextArea"); gridbag.setconstraints(textarea, c); add(textarea); try { image = getimage(new URL(getCodeBase(), "2euro.gif")); catch (MalformedURLException ex) { ex.printstacktrace(); canvas.setimage(image); canvas.setpoint(30, 30); canvas.repaint(); makeframe(); public void makepanel1() { panel1 = new Panel(); panel1.setbackground(color.yellow); panel1.setlayout(new GridLayout(8, 1)); button = new Button("Button"); button.addactionlistener(this); panel1.add(button); check = new Checkbox[6]; group = new CheckboxGroup(); for(int i = 0; i < 3; i++) { check[i] = new Checkbox("check " + i); check[i].additemlistener(this); panel1.add(check[i]); for(int i = 0; i < 3; i++) { check[i + 3] = new Checkbox("radio " + i, false, group); check[i + 3].addItemListener(this); panel1.add(check[i + 3]); 22

choice = new Choice(); for(int i = 0; i < 3; i++) { choice.additem("choice " + (i + 1)); choice.additemlistener(this); panel1.add(choice); public void makepanel2() { panel2 = new Panel(); panel2.setbackground(new Color(255, 192, 192)); list1 = new List(4, false); list2 = new List(4, true); for(int i = 0; i < 6; i++) { list1.add("list " + (i + 1)); list2.add("list " + (i + 1)); list1.additemlistener(this); list2.additemlistener(this); panel2.add(list1); panel2.add(list2); public void makepanel3() { panel3 = new Panel(); panel3.setbackground(color.white); panel3.setlayout(null); label = new Label("Label"); label.setbounds(10, 10, 80, 25); panel3.add(label); button1 = new Button("Frame"); button1.addactionlistener(this); button1.setbounds(10, 40, 80, 30); panel3.add(button1); textfield1 = new TextField("TextField"); textfield1.setbounds(100, 10, 120, 25); textfield1.addactionlistener(this); panel3.add(textfield1); textfield2 = new TextField("50"); textfield2.seteditable(false); textfield2.setbounds(100, 45, 120, 25); panel3.add(textfield2); scroll = new Scrollbar(Scrollbar.HORIZONTAL, 50, 5, 0, 105); scroll.setbounds(10, 80, 210, 25); scroll.addadjustmentlistener(this); panel3.add(scroll); public void makeframe() { frame = new Frame("Frame"); frame.setbounds(100, 100, 200, 200); frame.add(new Label("Dialog "), BorderLayout.CENTER); 23

button2 = new Button("Dialog"); button2.addactionlistener(this); frame.addwindowlistener(this); frame.add(button2, BorderLayout.SOUTH); dialog = new Dialog(frame, "Dialog"); dialog.setbounds(500, 100, 200, 200); dialog.add(new Label(" ")); dialog.addwindowlistener(this); public void actionperformed(actionevent e) { Object obj = e.getsource(); if(obj == button) { textarea.append(" nbutton "); else if(obj == button1) { frame.setvisible(true); else if(obj == button2) { dialog.setvisible(true); else { textarea.append(" ntextfield " + textfield1.gettext() + " "); public void itemstatechanged(itemevent e) { Object obj = e.getsource(); boolean c = false; for(int i = 0; (i < 3) && (c == false); i++) { if(obj == check[i]) { textarea.append(" n" + check[i].getlabel() + " " + check[i].getstate() + " "); c = true; if(i == 0) { boolean b = check[0].getstate(); canvas.setdoublebuffer(b); if (b) { /* */ textarea.append(" n else { if(c == false) { if(obj == choice) { "); textarea.append(" n "); textarea.append(" n" + choice.getselectedindex() + " " + choice.getselecteditem() + " "); else if(obj == list1) { textarea.append(" n " + list1.getselectedindex() + 24

Java 2003.11.4 " " + list1.getselecteditem() + " "); else if(obj == list2) { int[] x = list2.getselectedindexes(); String[] s = list2.getselecteditems(); int ii = x.length; if(ii == 0) { textarea.append(" n "); else { String str =" n "; str = str + x[0] + " " + s[0] + " "; for(int i = 1; i < ii; i++) { str = str + " " + x[i] + " " + s[i] + " "; textarea.append(str + " "); else { Checkbox cb = group.getselectedcheckbox(); textarea.append(" n" + cb.getlabel() + " "); String str; if (cb == check[3]) { str = "2euro.gif"; else if(cb == check[4]) { str = "norokko.png"; else { str = "grasshopper.jpg"; try { image = getimage(new URL(getCodeBase(), str)); catch (MalformedURLException ex) { canvas.setimage(image); public void adjustmentvaluechanged(adjustmentevent e) { textfield2.settext(integer.tostring(scroll.getvalue())); public void mouseclicked(mouseevent e) { textarea.append(" n ( " + e.getx() + ", " + e.gety() + canvas.setpoint(e.getx(), e.gety()); ") "); public void mousepressed(mouseevent e) { textarea.append(" n ( " + e.getx() + ", " + e.gety() + ") "); public void mousereleased(mouseevent e) { textarea.append(" n ( " + e.getx() + ", " + e.gety() + ") "); 25

public void mouseentered(mouseevent e) { textarea.append(" n ( " + e.getx() + ", " + e.gety() + ") "); public void mouseexited(mouseevent e) { textarea.append(" n ( " + e.getx() + ", " + e.gety() + ") "); public void mousedragged(mouseevent e) { canvas.setpoint(e.getx(), e.gety()); public void mousemoved(mouseevent e) { label.settext("( " + e.getx() + ", " + e.gety() + ")"); public String which(object obj) { if(obj == frame) { return "Frame"; else { return "Dialog"; public void windowopened(windowevent e){ textarea.append(" n" + which(e.getsource()) + " "); public void windowclosing(windowevent e){ ((Window)e.getSource()).setVisible(false); String str; if(e.getsource() == frame) { str = "Frame"; else { str = "Dialog"; textarea.append(" n" + which(e.getsource()) + " "); public void windowclosed(windowevent e) { public void windowiconified(windowevent e) { public void windowdeiconified(windowevent e) { public void windowactivated(windowevent e) { public void windowdeactivated(windowevent e) { public void keytyped(keyevent e) { textarea.append(" n" + e.getkeychar() + " "); public void keypressed(keyevent e) { public void keyreleased(keyevent e) { 26

MyCanvas.java import java.awt.*; import java.util.*; public class MyCanvas extends Canvas implements Runnable { int drawx, drawy; Image image, buffer; Thread thread; Font font; boolean dbuffer; public MyCanvas() { thread = null; font = null; buffer = null; dbuffer = false; this.init(); public void init() { image = null; drawx = -1; drawy = -1; if(font == null) { font = new Font("Sans-serif", 0, 50); if(thread == null) { thread = new Thread(this); thread.start(); public void setdoublebuffer(boolean b) { dbuffer = b; public boolean getdoublebuffer() { return dbuffer; public void setimage(image i) { image = i; public Image getimage() { return image; public void setpoint(int x, int y) { drawx = x; drawy = y; 27

public int getx() { return drawx; public int gety() { return drawy; public String time() { GregorianCalendar cal = new GregorianCalendar(); String str = Integer.toString(cal.get(Calendar.HOUR_OF_DAY)) + ":"; int x = cal.get(calendar.minute); if(x < 10) { str += "0"; str = str + x + ":"; x = cal.get(calendar.second); if(x < 10) { str += "0"; return (str + x); public void paint(graphics g) { Graphics gr; if(dbuffer) { int w = getwidth(); int h = getheight(); if (buffer == null) { buffer = createimage(w, h); gr = buffer.getgraphics(); gr.setcolor(getbackground()); gr.fillrect(0, 0, w - 1, w - 1); gr.setcolor(color.black); else { gr = g; if((image!= null) && (drawx >=0) && (drawy >= 0)) { int w = image.getwidth(this); int h = image.getheight(this); gr.drawimage(image, drawx - w / 2, drawy - h / 2, this); gr.setfont(font); gr.drawstring(time(), 5, 70); if(dbuffer) { g.drawimage(buffer, 0, 0, this); public void update(graphics g) { if(dbuffer) { paint(g); else { super.update(g); 28

public void run() { while(true) { repaint(); try { thread.sleep(100); catch(interruptedexception e) { jikken.html <!DOCUMENT HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"> <HTML> <BODY> <HEAD> <META http-equiv="content-type" content="text/html; charset=shift_jis"> <TITLE> </TITLE> </HEAD> <P> <H2> </H2> </P> </P> <BODY BGCOLOR="#ffffff"> <P> <APPLET CODE="JikkenApplet.class" WIDTH=600 HEIGHT=400> </APPLET><BR> </P> </BODY> </HTML> 2euro.gif norokko.png grasshopper.jpg 29