Applet and Graphics - PowerPoint PPT Presentation

Applet and graphics l.jpg
Download
1 / 28

Applet and Graphics Inheritance Hierarchy of GUI Classes Constructors and Methods of the class Component Constructors and Methods of the class Component Constructors and Methods of the class Component Constructors and Methods of the class Container Applets

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Download Presentation

Applet and Graphics

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Applet and graphics l.jpg

Applet and Graphics


Inheritance hierarchy of gui classes l.jpg

Inheritance Hierarchy of GUI Classes


Constructors and methods of the class component l.jpg

Constructors and Methods of the class Component


Constructors and methods of the class component4 l.jpg

Constructors and Methods of the class Component


Constructors and methods of the class component5 l.jpg

Constructors and Methods of the class Component


Constructors and methods of the class container l.jpg

Constructors and Methods of the class Container


Applets l.jpg

Applets

  • Applet: a Java program that is embedded within a Web page and executed by a Web browser

  • Create an applet by extending the class JApplet

  • class JApplet contained in package javax.swing


Members of class japplet l.jpg

Members of class JApplet


Members of class japplet9 l.jpg

Members of class JApplet


Applets10 l.jpg

Applets

  • No main method

  • Methods init, start, and paint guaranteed to be invoked in sequence

  • To develop an applet

    • Override any/all of the methods above


Applet methods l.jpg

Applet Methods

  • init Method

    • Initializes variables

    • Gets data from user

    • Places various GUI components

  • paint Method

    • Performs output


Skeleton of a java applet l.jpg

Skeleton of a Java Applet

import java.awt.Graphics;

import javax.swing.JApplet;

public classWelcomeApplet extends JApplet

{

}


Applet displaying welcome message l.jpg

Applet Displaying Welcome Message

//Welcome Applet

import java.awt.Graphics;

import javax.swing.JApplet;

public class WelcomeApplet extends JApplet

{

public void paint(Graphics g)

{

super.paint(g); //Line 1

g.drawString(“Welcome to Java Programming”,

30, 30); //Lineƒ2

}

}


Html to run applet l.jpg

HTML to Run Applet


Class font l.jpg

class Font

  • Shows text in different fonts

  • Contained in package java.awt

  • Available fonts

    • Serif/SanSerif

    • Monospaced

    • Dialog/DialogInput

  • Arguments for constructor

    • String specifying the Font face name

    • int value specifying Font style

    • int value specifying Font size

      • Expressed in points (72 points = 1 inch)


Constructors and methods of the class font l.jpg

Constructors and Methods of the class Font


Class color l.jpg

class Color

  • Shows text in different colors

  • Changes background color of component

  • Contained in package java.awt


Constructors of the class color l.jpg

Constructors of the class Color


Methods of the class color l.jpg

Methods of the class Color


Methods of the class color20 l.jpg

Methods of the class Color


Constants defined in the class color l.jpg

Constants Defined in the class Color


Class graphics l.jpg

class Graphics

  • Provides methods for drawing items such as lines, ovals, and rectangles on the screen

  • Contains methods to set the properties of graphic elements including clipping area, fonts, and colors

  • Contained in the package java.awt


Constructors and methods of the class graphics l.jpg

Constructors and Methods of the class Graphics


Constructors and methods for the class graphics l.jpg

Constructors and Methods for the class Graphics


Constructors and methods for the class graphics25 l.jpg

Constructors and Methods for the class Graphics


Constructors and methods for the class graphics26 l.jpg

Constructors and Methods for the class Graphics


Differences between applets and gui applications l.jpg

Applets

Derived from JApplet

No main method

Uses init method

Displayed by HTML

Sets title in HTML

Size set in HTML

Applet closes when HTML doc closes

GUI applications

class extends JFrame

Invokes main method

Uses constructors

Uses method setVisible

Uses setTitle method

Uses method setSize

Closes with Exit button

Differences Between Applets and GUI Applications


Converting a gui application to an applet l.jpg

Converting a GUI Application to an Applet

  • Change JFrame to JApplet

  • Change constructor to method init

  • Remove method calls such as setVisible, setTitle, setSize

  • Remove the method main

  • If applicable, remove Exit button/all code associated with it (e.g. action listener)


  • Login