Java Programming Unit 6. Inner Classes. Intro to Apples. Installing Apache Tomcat Server.

Similar documents
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

Chapter 1 GUI Applications

CT 229 Arrays in Java

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

G51PRG: Introduction to Programming Second semester Applets and graphics

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

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

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

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

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Java Applet & its life Cycle. By Iqtidar Ali

For live Java EE training, please see training courses at

Setup and Getting Startedt Customized Java EE Training:

9. APPLETS AND APPLICATIONS

Summary. 962 Chapter 23 Applets and Java Web Start

Chapter 3 - Introduction to Java Applets

Chapter Two Bonus Lesson: JavaDoc

CSC System Development with Java Introduction to Java Applets Budditha Hettige

Java Programming Unit 2. Intro to Object Oriented Programming

More Swing. CS180 Recitation 12/(04,05)/08

CS1004: Intro to CS in Java, Spring 2005

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1

CSE 8B Intro to CS: Java

GUI, Events and Applets from Applications, Part III

Programming graphics

Lesson 10: Quiz #1 and Getting User Input (W03D2)

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

Setting Up the Development Environment

Java Applet Basics. Life cycle of an applet:

Introduction to Computer Science I

Chapter 7 Applets. Answers

1. What is Jav a? simple

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

Sample Spark Web-App. Overview. Prerequisites

Lecture Static Methods and Variables. Static Methods

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

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

WEB APPLICATION. XI, Code- 803

The init() Method. Browser Calling Applet Methods

The Design and Implementation of Multimedia Software

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

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

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

Chapter 2 Using Objects. Types. Number Literals. A type defines a set of values and the operations that can be carried out on the values Examples:

FORMAS DE IMPLEMENTAR LOS OYENTES. A).- El oyente en una clase independiente con el constructor con un argumento y usando el método getactioncommand.

CSCI 201 Lab 1 Environment Setup

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

Introduction to Java Applets 12

Swing from A to Z Some Simple Components. Preface

CHAPTER 7 WEB SERVERS AND WEB BROWSERS

Chapter 12 Advanced GUIs and Graphics

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

Netscape Introduction to the JavaScript Language

Supporting Materials

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

PROGRAMMING LANGUAGE 2

The AWT Package, Graphics- Introduction to Images

BM214E Object Oriented Programming Lecture 13

How to Install (then Test) the NetBeans Bundle

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Programming Languages and Techniques (CIS120e)

Java WebStart, Applets & RMI

Introduction, Notepad++, File Structure, 9 Tags, Hyperlinks 1

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

11. HTML5 and Future Web Application

HTML OBJECTIVES WHAT IS HTML? BY FAITH BRENNER AN INTRODUCTION


Graphical Interfaces

INTRODUCTION TO WEB USING HTML What is HTML?

Website Development Komodo Editor and HTML Intro

Java Training For Six Weeks

Getting Started with Eclipse/Java

Google Web Toolkit (GWT)

CS 11 java track: lecture 1

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

Graphics Applets. By Mr. Dave Clausen

Graphical User Interface (GUI)

Shared Collection of Java Course Materials: New Topics Covered. Agenda

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

SELF-STUDY. Glossary

CSD Univ. of Crete Fall Java Applets

Understanding How Java Programs Work

CS2 Advanced Programming in Java note 8

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

CPSC 324 Topics in Java Programming

Java with Eclipse: Setup & Getting Started

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

SIMPLE APPLET PROGRAM

UNIT -5. Java Server Page

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

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

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

Outline. Announcements. Feedback. CS1007: Object Oriented Design and Programming in Java. Java beans Applets

MULTIMEDIA PROGRAMMING IN JAVA. Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana

Swing from A to Z Using Focus in Swing, Part 2. Preface

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

Transcription:

Java Programming Unit 6 Inner Classes. Intro to Apples. Installing Apache Tomcat Server.

Swing Adapters Swing adapters are classes that implement empty funchons required by listener interfaces. You need to override only the methods you are interested in. class MyWindowEventProcessor extends java.awt.windowsadapter { public void windowclosing(windowevent e) { // your code goes here. For example, ask if the user wants to save data The code above is more compact than wrihng class MyWindowEventProcessor that implements WindowListener with all the methods below: windowachvated (WindowEvent) windowclosed(windowevent) windowclosing(windowevent) windowdeachvated (WindowEvent) windowdeiconified(windowevent) windowiconified(windowevent) windowopened(windowevent)

Inner Classes class Tax{ double grossincome; int dependents; double calcstatetax(){ A class defined inside another one is called an inner class. TaxOpHmizer topt = new TaxOpHmizer(); topt.ophmize(grossincome, dependents); public TaxOpHmizer gettaxop9mizer(){ The method gettaxophmizer() returns an instance of the inner class. return new TaxOpHmizer(); If a class TestTax need to call the method settaxcode() from the inner class it can: class TaxOp9mizer { int taxcode; void settaxcode(int tcode){ taxcode=tcode; int op9mize(double grossincome, int dep){ // Some op9miza9on code goes here Tax t = new Tax(2, NY, 50000); Tax.TaxOpHmizer tophmizer = t.gettaxophmizer(); tophmizer.settaxcode(12345); Here s another syntax producing the same result: Tax t = new Tax(2, NY, 50000); Tax.TaxOpHmizer tophmizer = t.new TaxOpHmizer(); tophmizer.settaxcode(12345);

Anonymous Inner Classes If an inner class does not have a name, it s called anonymous. Imagine, that the CalculatorEngine class has the following code: this.addwindowlistener( new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); Instead of providing a pre- created object reference to the method addwindowlistener() this code both declares and instanhates an annonymus class with one method windowclosing().

Java Applets in a Web page Java Applet Web Server HTML page with the tag to embed a Java applet Web Browser with Java plugin Client Computer

HTML in 10 minutes (start) <HTML> <HEAD> <TITLE>My First Web Page</TITLE> </HEAD> <BODY> My Tic- Tac- Toe applet is coming soon </BODY> </HTML> Hyper Text Markup Language is not a programming language. It s a set of tags that you can use with any text to let the Web Browser know how to display it.

HTML in 10 minutes (cont.) <HTML> <HEAD> <TITLE>My First Web Page</TITLE> </HEAD> <BODY> My Tic- Tac- Toe applet is coming soon <br> In the meanhme, listen to <a href= hip://americhka.us >Budam s podcasts</a> </BODY> </HTML> This is a hyperlink The user will see this

HTML in 10 minutes (end) <HTML> <HEAD> <TITLE>My First Web Page</TITLE> </HEAD> Include the Java applet TicTacToe here <BODY> My Tic- Tac- Toe applet is coming soon <APPLET code= TicTacToe.class width=300 height=250 /> <br> In the meanhme, listen to <a href= hip://americhka.us >Budam s podcasts</a> </BODY> </HTML>

Walkthrough 1 Enter the text below in a plain text editor like Notepad or TextEdit. Save it in the file HelloWorld.html and open this file in your Web browser using the menu File Open. <HTML> <HEAD> <TITLE>My First Web Page</TITLE> </HEAD> <BODY> My Tic- Tac- Toe applet is coming soon. In the meanhme, listen to <a href="hip://americhka.us">budam podcasts</a> <p> <APPLET code= TicTacToe.class width=300 height=250 /> </BODY> </HTML> Why don t you see the TicTacToe applet?

Swing Applet Hello World import javax.swing.japplet; import java.awt.graphics; public class HelloWorld extends JApplet { public void paint(graphics g){ g.drawstring("hello World", 50, 100);

Applet s callbacks init() is called when the applet is loaded by the browser s Java Plug- in. It s called only once playing a role similar to constructors in regular Java classes. start() is called right aoer the init(). It is called each Hme when a user returns to the Web page with the applet aoer visihng another page. paint() is called when the applet s window needs to be displayed or refreshed aoer some achvity on the screen. For example, the applet is overlapped with some other window and the browser needs to repaint it. This method gets an instance of the Graphics object as an argument. stop() is called when the user leaves the Web page containing the applet. destroy() is called when the browser destroys the applet. Write code in this method only if the applet uses some other resources, for example, it holds a connechon to the remote computer.

Walkthrough 2 Create Eclipse project called MyApplets Create and compile an applet HelloWorld there Copy HelloWorld.class into the same directory where HelloWorld.html is located Modify the <applet> tag in html file to include HelloWorld.class Open HelloWorld.html in the Web browser your applet should be displayed in the Web page.

Tic- Tac- Toe Applet

Walkthrough 3 Download the source code from Lesson11 and import it to Eclipse Run the program TickTacToeApplet1 in appletviewer (right- click, Run As Java Applet) Read the code and explain it to the instructor Review the code of TickTacToe.html Run in the TickTacToeApplet in appletviewer and review the code with instructor

Configuring Apache Tomcat 7 Server in Eclipse 1. Download and unzip Apache Tomcat from hip://tomcat.apache.org/download- 70.cgi - select one of the binary core distribuhons. 2. In Eclipse, go to Java EE perspechve, select the menu File New Other Server Server Apache Tomcat v7.0 Server, select Tomcat installahon directory and press Finish. 3. In the Project Explorer you ll see the Tomcat entry. Go to menu Windows Show View and open the Servers view too. Start Tomcat using the right- click menu. Double- click on the Tomcat entry, select the radio buion Use Tomcat Installa6on, and press Ctrl- S to save changes. This tells Eclipse to deploy your classes in the original Tomcat directories 4. Open your Window Explorer (or Finder on Mac OS) and examine the tomcat/webapps/root directory. Copy there HelloWorld.html html from Walkthrough 1. 5. Open the URL hip://localhost:8080/helloworld.html in your Web browser the content of HelloWorld.html is displayed 6. Copy TicTacToe.html and the bin directory from your Eclipse workspace to /webapps/root Open the URL hip://localhost:8080/tictactoe.html and play your TicTacToe game.

Homework 1. Learn HTML basics: hip://www.w3schools.com/html/html_primary.asp. 2. Bookmark the Java Glossary and refer to it when need be: hip://mindprod.com/jgloss/jgloss.html 3. Install and configure Apache Tomcat 7 as per instruchons from the previous slide. For more details refer to Eclipse configurahon instruchons at hip://www.coreservlets.com/apache- Tomcat- Tutorial/ 4. Deploy your TicTacToe applet under Tomcat 5. Do the assignment from the Try It sechon from lessons 10 and 11 from the textbook