Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class."— Presentation transcript:

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

2 Two types of Java programs JAVA PROGRAM JAVA APPLET JAVA APPLICATION

3 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

4 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.

5 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); }

6 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

7 Embedding a applet in HTML file 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

8 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.

9 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)

10 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

11 Draw string Void drawString(String string,int x1,int x2); Paints the message at specified coordinates (x1,y1) string

12 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

13 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


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

Similar presentations


Ads by Google