1 / 13

LAB SESSION 7

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.

shelleyw
Télécharger la présentation

LAB SESSION 7

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • <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

  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). (x2,y2) (x1,y1)

  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 width (x1,y1) 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) width (x1,y1) height

More Related