Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Running an Applet

We need to use html code to run applets. The minimum html required to run applet with a browser (java host) is as follows:



TitleName



    CODE = Classname.class
    CODEBASE = . directory of class file
    WIDTH = 50 width of window in pixels
    HEIGHT = 50 height of window in pixels



Note that in the applet tag you include the. class bytecode file and not the .java.

Graphics Class
- Browser or appletviewer sends a Graphics object to the paint method.
- The Graphics object represents the applet window, current font, and current color and provides methods to draw shapes (rectangles, triangles, circles, etc.) and text on the window.
The Graphics Class Coordinate System

- Never use 0,0 because the applet itself uses it for the title bar.

Graphics class methods
- No return type so they are all void
- Draw ()… methods draw an outlined share
- Fill ()… methods draw a solid shapeDisplaying text use g.drawString( "string", x, y); Need to draw the strings.
- Draw a lin g.drawLine( xStart, yStart, xEnd, yEnd );
- How do you draw a square? You need to make multiple lines that attach at the points.
Drawing a rectangle, Use pixels for height and width and an anchoring corner.
Drawing an oval, drawn inside an invisible rectangle. Give rectangle coordinates.
Graphics methods, Use offsets to make your figure easier to move resize.

import javax.swing.JApplet;
import java.awt.Graphics;

public class ShapesApplet extends JApplet
{
  public void paint( Graphics g )
  {
    super.paint( g );
    g.drawRect( 900, 40, 30, 900 );
    g.fillRect( 200, 70, 80, 80 );
    g.fillOval( 100, 50, 40, 100 );
    g.drawOval( 100, 200, 100, 40 );
    int X = 250, Y = 225;
    int r = 25;
   g.drawOval( X - r, Y - r, r * 2, r * 2 );
 }
}

- Draw a rectangle g.drawRect( x, y, width, height );
- Draw a solid recta ngle: g.fillRect( x, y, width, height );
- Draw am oval: g.drawOval( x, y, width, height );

 
     
   
Java Language Tutorial
 
  What is JAVA
What is JAVA
  Java an Object Oriented Language
Java an Object Oriented Language
  Java Keywords
Java Keywords
  Data Types
Data Types
  Java Operators
Java Operators
  Control Structure
Control Structure
  Arrays
Arrays
  Java Classes
Java Classes
  Java Constructors
Java Constructors
  Java Methods
Java Methods
  Java Method Overloading
Java Method Overloading
  Java Method Overriding
Java Method Overriding
  Java Nested Classes
Java Nested Classes
  Inheritance in Java
Inheritance in Java
  Interfaces in Java
Interfaces in Java
  Polymorphism in Java
Polymorphism in Java
  Exception Handling in Java
Exception Handling in Java
  Catching Exceptions
Catching Exceptions
  Embedding information in an exception object
Embedding information in an exception object
  The throws clause
The throws clause
  Checked and unchecked exceptions
Checked and unchecked exceptions
  The finally clause
The finally clause
  Applets in Java
Applets in Java
  Running an Applet
Running an Applet
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Art of Programming Contest  Ebook Art of Programming Contest
   
Download Blog for Dollar Ebook Blog for Dollar
   
Download How To Design Programs: An Introduction To Programming and Computing  Ebook How To Design Programs: An Introduction To Programming and Computing
   
Download The Downline Code  Guru Secrets For Explosive MLM Growth  Ebook The Downline Code Guru Secrets For Explosive MLM Growth
   
Download Domain Name Whitepaper  Making Money with Domains  Ebook Domain Name Whitepaper Making Money with Domains
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz