Fondamenti di Informatica C. Lezione 24: Dentro le applet

Similar documents
Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Java - Applets. public class Buttons extends Applet implements ActionListener

Java Applet & its life Cycle. By Iqtidar Ali

Java Applets / Flash

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Java. GUI building with the AWT

Advanced Internet Programming CSY3020

Java Applet Basics. Life cycle of an applet:

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

Contents 8-1. Copyright (c) N. Afshartous

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

CS335 Graphics and Multimedia

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

ORF 201 Computer Methods in Problem Solving. Lab 8: The Guassian Eliminator

CHAPTER 2. Java Overview

Programming Mobile Devices J2SE GUI

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

PESIT Bangalore South Campus

G51PRG: Introduction to Programming Second semester Applets and graphics

Introduction to Computer Science I

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components



1 GUI GUI GUI GUI GUI. GUI(Graphical User Interface) JDK java.awt. ? Component

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

Uguaglianza e Identità. (no, non avete sbagliato corso )

Java AWT Windows, Text, & Graphics

Chapter 7 Applets. Answers

Lecture Static Methods and Variables. Static Methods

IPM 12/13 P4 Handling Events in AWT

Tecniche di Progettazione: Design Patterns

CS2 Advanced Programming in Java note 8

Dr. Hikmat A. M. AbdelJaber

Lecture Static Methods and Variables. Static Methods

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

JavaBeans. JavaBeans. Java. Java JavaBeans. JavaBeans. JavaBeans GUI. JavaBeans Builder (vitsual) Java. JavaBeans. Beans. Builder.

Applet which displays a simulated trackball in the upper half of its window.

Using the API: Introductory Graphics Java Programming 1 Lesson 8

CPS221 Lecture: Threads

Tecniche di Progettazione: Design Patterns

CS 170 Java Programming 1. Week 9: Learning about Loops

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

Lecture 06: Classes and Objects

File Upload Instructions Customer Access To Transcript Bulletin Publishing s FTP Site

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

MODULE 8p - Applets - Trials B

Java Foundations. 7-2 Instantiating Objects. Copyright 2015, Oracle and/or its affiliates. All rights reserved.


Campo Minato Nel Form1 sono presenti i seguenti componenti:

Which of the following syntax used to attach an input stream to console?

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

SIMPLE APPLET PROGRAM

EE219 - Semester /2009 Solutions Page 1 of 10

User interfaces and Swing

(Refer Slide Time: 02:01)

CSD Univ. of Crete Fall Java Applets

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Introduction to the Java T M Language

04MAC03/03/01/001 RIMADIMA an INTERREG III B CADSES NP, An EU-funded project managed by the European Agency for Reconstruction

UNIT-2: CLASSES, INHERITANCE, EXCEPTIONS, APPLETS. To define a class, use the class keyword and the name of the class:

CSC System Development with Java Introduction to Java Applets Budditha Hettige

1 Getting started with Processing

CS 106A, Lecture 23 Interactors and GCanvas

Implementazione Java di Alberi Binari. A.A. 16/17 DA1 - Andrea Pietracaprina 1

GUI in Java TalentHome Solutions

Metodo di Holt-Winters M. Romito 7 dicembre 2016

CSE 11 Midterm Fall 2008

CORBA Java. Java. Java. . Java CORBA. Java CORBA (RMI) CORBA ORB. . CORBA. CORBA Java

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,

Equality for Abstract Data Types

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

Review. Designing Interactive Systems II. Introduction. Web 2.0 in keywords GWT Cappuccino HTML5. Cross platform GUI Toolkit

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

Designing Interactive Systems II

SNS COLLEGE OF ENGINEERING, Coimbatore

Multithread Computing

EE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

EE219 Object Oriented Programming I Repeat Solutions for 2005/2006

Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

CS1004: Intro to CS in Java, Spring 2005

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Lab 5 Classy Chat. XMPP Client Implementation --- Part 2 Due Oct. 19 at 11PM

Programming: You will have 6 files all need to be located in the dir. named PA4:

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Selected Java Topics

Contents Introduction 1

ORF 201 Computer Methods in Problem Solving. Lab 7: Maze Solver

Methods (Deitel chapter 6)

Graphical User Interface (GUI)

CS506 Web Design & Development Final Term Solved MCQs with Reference

DEMONSTRATION OF AWT CONTROLS

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Overloading Example. Overloading. When to Overload. Overloading Example (cont'd) (class Point continued.)

Transcription:

Fondamenti di Informatica C Lezione 24: Dentro le applet 22-11-2004 Il commento iniziale /* --------------------------------------------------- This applet creates a few different user interface components and detects when the user interacted with them. Java's classes: Applet (applet) System (lang) Button (awt) Choice (awt) TextField (awt) Checkbox (awt) CheckboxGroup (awt) Label (awt) Event (awt) Custom classes: UIApplet ------------------------------------------------------ */ Lezione 24: Dentro le applet 22-11-2004 2 Lezione 24: Dentro le applet 22-11-2004 1

Importazioni e dichiarazioni import java.awt.*; public class UIApplet extends java.applet.applet { Button Choice TextField button; choice; textfield; Lezione 24: Dentro le applet 22-11-2004 3 Creazione dell interfaccia 1 /** Create a user interface. */ public void init() { Checkbox checkbox; CheckboxGroup checkboxgroup; Label label; // create a choice list choice = new Choice(); choice.additem("apple"); choice.additem("banana"); choice.additem("cherry"); add(choice); Lezione 24: Dentro le applet 22-11-2004 4 Lezione 24: Dentro le applet 22-11-2004 2

Creazione dell interfaccia 2 // create a text field textfield = new TextField(10); // 10 columns wide add(textfield); // create a button button = new Button("Click me"); add(button); // create a label label = new Label("I am a label"); add(label); Lezione 24: Dentro le applet 22-11-2004 5 Creazione dell interfaccia 3 // create 3 exlusive-choice checkboxes checkboxgroup = new CheckboxGroup(); checkbox = new Checkbox("Yes", checkboxgroup, false); add(checkbox); checkbox = new Checkbox("No", checkboxgroup, false); add(checkbox); checkbox = new Checkbox("Maybe", checkboxgroup, true); add(checkbox); Lezione 24: Dentro le applet 22-11-2004 6 Lezione 24: Dentro le applet 22-11-2004 3

Per poterla provare <applet codebase=." code="uiapplet.class" width=256 height=77> </applet> Lezione 24: Dentro le applet 22-11-2004 7 La gestione degli eventi 1 /** Respond to user input events. */ public boolean action(event e, Object arg) { if (e.target == textfield) System.out.println("User entered text into the text field"); button"); choice"); else if (e.target == button) System.out.println("User clicked the else if (e.target == choice) System.out.println("User selected a new Lezione 24: Dentro le applet 22-11-2004 8 Lezione 24: Dentro le applet 22-11-2004 4

La gestione degli eventi 2 box"); else if (e.target instanceof Checkbox) System.out.println("User clicked a check else System.out.println("Unrecognized event"); System.out.println(arg); return super.action(e, arg); Proviamo a compilarla ex novo Lezione 24: Dentro le applet 22-11-2004 9 Esecuzione con tre browser diversi: I.E. Netscape Safari Lezione 24: Dentro le applet 22-11-2004 10 Lezione 24: Dentro le applet 22-11-2004 5

Considerazione ovvia: Finora abbiamo visto applet contenenti tre metodi: init paint action action ovviamente gestisce gli eventi init e paint non sono molto chiare Nessuno di questi viene chiamato direttamente da noi! Perché? Lezione 24: Dentro le applet 22-11-2004 11 Le fasi iniziali Lezione 24: Dentro le applet 22-11-2004 12 Lezione 24: Dentro le applet 22-11-2004 6

Il ciclo di vita Lezione 24: Dentro le applet 22-11-2004 13 Il ciclo di vita, a parole (1) First, an applet is born. This occurs when the applet is loaded into the browser and instantiated. As soon as the applet has been instantiated, the browser invokes the applet s init() method. After the applet has been initialized, the browser starts it going. The browser invokes the applet s start() method. If the user changes to another Web page or to another program, the applet goes to sleep. The browser invokes the applet s stop() method when this occurs. If the user turns back to the original Web page that did contain the applet, the applet wakes up. The browser invokes its start() method again when this occurs. Lezione 24: Dentro le applet 22-11-2004 14 Lezione 24: Dentro le applet 22-11-2004 7

Il ciclo di vita, a parole (2) Finally, at some point when the applet is no longer needed, it goes away. This would occur if the user quit the browser, for example. At this point, the browser invokes the applet s destroy() method. Lezione 24: Dentro le applet 22-11-2004 15 Intervenire nel ciclo di vita... public void init() { public void start() { public void stop() { public void destroy() { Provare, provare subito!!!! [Ciclovita.java] Lezione 24: Dentro le applet 22-11-2004 16 Lezione 24: Dentro le applet 22-11-2004 8

Ulteriori dettagli: init() init(): This method is invoked only once in the applet s life the very first time the user runs the applet. You might want to initialize your applet s user interface by creating windows, buttons, and other graphical elements. For example, the SimpleDraw applet provides an init() method to create the shape and color selection choices. init() is probably the method you ll use the most. Lezione 24: Dentro le applet 22-11-2004 17 Ulteriori dettagli: start() start(): This method is invoked every time the browser starts up your applet. For example, if the user turns to the Web page containing this applet, start() will be invoked. If the user then turns to another page and then turns back, start() will be invoked again. This is different from init(), which is only invoked the very first time. If you are performing any animation or playing any sounds, you might want to start these going inside the start() method. Lezione 24: Dentro le applet 22-11-2004 18 Lezione 24: Dentro le applet 22-11-2004 9

Ulteriori dettagli: stop() stop(): This method is invoked every time the browser stops your applet. There will be one stop() invocation for every start(). You can take this time to halt any animation or sound that you might have begun in start(). Lezione 24: Dentro le applet 22-11-2004 19 Ulteriori dettagli: destroy() destroy(): This method is invoked only once at the very end of an applet s life. There will be one destroy() invocation for every init(). When the browser unloads the applet for example, if the user quits the browser this method will be invoked. You might take this time to free any resources you ve allocated in the system. It s very likely that you ll hardly ever write a destroy() method. Lezione 24: Dentro le applet 22-11-2004 20 Lezione 24: Dentro le applet 22-11-2004 10