13
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Embed Size (px)

Citation preview

Page 1: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

LAB SESSION 7

Graphical user interfaceApplet fundamentalsMethods in appletsExecution of an appletGraphics class

Page 2: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Two types of Java programs

JAVA PROGRAM

JAVA APPLET

JAVA APPLICATION

Page 3: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Java applet is a java program that is intended to be embedded into a html document,tansported across a network and executed using a web browser.

Java application is a standalone program that can be executed using a java interpreter

Page 4: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Execution of an applet

An applet may be viewed locally either using an web Browser

Or it can be run using a tool in java SDK (software development kit) called the APPLET VIEWER.

Page 5: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Example PROGRAM

Import java.applet.Applet; import java.awt.*;Public class applet1 extends Applet{Public void paint(Graphics g){g.drawString(“This is my first applet”,100,50);}}

Page 6: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Graphics class

A graphics object defines a particular graphics context with which we can interact.

A graphics context passed into a paint method represents the entire applet window

Each graphics context has its own coordinate system

Page 7: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Embedding a applet in HTML file

<applet code=“applet1.class” width=350

height=200></applet>

Append this statement in your html file and place the .class file in your folder which contains this html file .

Then this applet is downloaded and executed by web browser when u run the html file

Page 8: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Graphics class

The graphics class is present in java.awt package.

It contains various methods that allow us to draw shapes,including lines ,rectangle,etc.

Page 9: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Methods in graphics class

Void drawLine(int x1,int x2,int y1,int y2)

Paints a line from point(x1,y1) to (x2,y2).

(x1,y1) (x2,y2)

Page 10: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Draw rectangle Void drawRect(int x1,int x2,int width,int height) Void fillRect(int x1,int x2,int width,int height)

Paints a rectangle with upperleft corner(x,y) and dimensions width and height

Fills the rectangle with current foreground color

(x1,y1)

width

height

Page 11: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Draw string

Void drawString(String string,int x1,int x2);

Paints the message at specified coordinates

(x1,y1) string

Page 12: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Color class methods

Color getColor() returns the graphics context current foreground color

Void setColor(Color color) Sets the graphics context foreground color

setBackground(Color color)//method in applet class sets the background of applet to specified color

Page 13: LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class

Draw oval Void drawOval(int x1,int y1,int width,int height) Paints an oval bounded by an rectangle with an upper left

corners (x,y) and dimensions width and height

Void fillOval(int x1,int y1,int width,int height)

(x1,y1)

height

width