Java Applets.

Slides:



Advertisements
Similar presentations
Made with love, by Zachary Langley Applets The Graphics Presentation.
Advertisements

Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Applets. What is an Applet?  According to Sun “An applet is a small program that is intended not to be run on its own, but rather to be embedded inside.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
JAPPLET.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
GUI programming Graphical user interface-based programming.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
Applets Session 8. Java Simplified / Session 8 / 2 of 31 Review The Abstract Windowing Toolkit (AWT) is a set of classes that allow us to create a graphical.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
SD2071 Games Programming Abstraction, inheritance and interfaces Exceptions Two dimensional arrays Java collections framework Files Aaron Kans.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Intro to Applets August 19, 2008 Mrs. C. Furman. Java Applets vs. Java Applications Java Applet: a program that is intended for use on the web. Java Applet:
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Java's Graphical User Interface Toolkit
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
1 Event Handling – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Java Applet What is a Java Applet? How is applet compiled?
Java Applets.
Applets.
Lecture 09 Applets.
INFSY 547: WEB-Based Technologies
Java Applets.
Chapter 13: Advanced GUIs and Graphics
Graphical user interface-based programming
Applets.
UNIT-5.
Java Applets.
Java Applets.
Chapter 12 GUI Basics.
Advanced GUIs and Graphics
Presentation transcript:

Java Applets

Applets The term Applet refers to a little application . In JAVA the applet is a java program that is embedded within a HTML document and Executed by web browser. Every applet is a subclass of java.applet.Applet ,So we should EXTEND the JApplet Class which is contained in javax.swing. To use swing components, use javax.swing.JApplet

Getting started… Create a new java class file After that build the file … the you will get tow files

Getting started… Now use the previous code in to a regular HTML document <HTML> <HEAD> <TITLE> Welcome Applets </TITLE> </HEAD> <BODY> <OBJECT code="test.class" width="400" height="400" > </OBJECT> </BODY> </HTML>

Developing Applets Java applets do not need a ‘main’ method. they can run in a web browser environment The applet have Init() Start() Stop() Paint( Graphics g)

init() called by the browser or applet viewer to inform this applet that it has been reloaded to the system We use init() to: Initialize variables Get data from user Place various GUI component.

start() & stop() Start() //called by the browser or applet viewer to inform this applet that it should start its execution Stop() //called by the browser or applet viewer to inform this applet that it should stop its execution

paint( Graphics g) is used to create the output . whenever you override this method the first java statement is super.paint(g); To draw a string we use drawString method Public abstract void drawstring(String str, int x, int y)

paint( Graphics g) To change the text font setFont(new Font(“font name”, ”font style”, font_size) To chang the text color setColor(Color.red) The available constant colors White, Black , blue, cyan, darkGray ,gray ,lightGray ,red, yellow,pink, orange, magenta ,green Using JDK guarantees the following fonts: Font style Serif Font.PLAIN Sanserif Font.BOLD Monospaced Font.ITALIC Dialog DialogInput

Example

JAVA application VS. applets Java applications and Applets share some common programming features although they differ in some aspects GUI Applets Is derived from class Jframe Is derived from class JApplet Have “MAIN” method Do not have main method instead It have init(), start(), stop(), paint(..) Uses the class constructor to initialize the GUI component and data members Uses the init() method to initialize the GUI component and data members Uses setSize(),setTitle(), setVisible() methode don not use the because the HTML document do the job.

converting JAVA application to applets Change the extends from JFrame to JApplets. Change the constructor to method init(). Remove method calls like setSize(),setTitle(), setVisible() . Remove the method main

Simple application Example

Convert to applet

Mouse events import javax.swing.*; import java.awt.*; import java.awt.event.*; class Test extends JFrame implements MouseListener { private Container contentPane; private JTextField t1;

public Test() { setTitle("Playing With The Mouse public Test() { setTitle("Playing With The Mouse!"); setSize(400, 200); setResizable(false); setVisible(true); addMouseListener(this); setDefaultCloseOperation(EXIT_ON_CLOSE); contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); t1=new JTextField (20); contentPane.add(t1); }

public void mouseEntered(MouseEvent me) { t1 public void mouseEntered(MouseEvent me) { t1.setText("Mouse entered at: ("+ me.getX() + ", " + me.getY() + ")"); } public void mouseExited(MouseEvent me) { t1.setText("Mouse exited at: (" + me.getX() + ", " + me.getY() + ")"); public void mouseClicked(MouseEvent me) { t1.setText("Mouse clicked at: ("

public void mousePressed(MouseEvent me) { t1.setText("Mouse pressed at: (" + me.getX() + ", " + me.getY() + ")"); } public void mouseReleased(MouseEvent me) { t1.setText("Mouse released at: (" public static void main(String[] args) { new Test(); } // End of Test class