Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Creating a Java Applet: Steps, Code, and Graphics, Exercises of Java Programming

A step-by-step guide on creating a java applet, including importing packages, writing code, and using graphics methods to draw shapes and display text. It also covers loading images and experiencing the applet's life cycle.

Typology: Exercises

2011/2012

Uploaded on 07/03/2012

netu
netu 🇮🇳

4.5

(4)

55 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Do not use the JBuilder Applet Wizard at this step
1. Following the following steps to create your first applet
a. Import the following packages into your program
import java.applet.*;
import java.awt.*;
b. Create a class of your choice
c. Extend the class from java.applet.Applet class
d. Add the following method
public void paint(Graphics g)
e. Add g.drawString(“Hello World”,25,25)
f. Save the program to a file HelloWorld.java
g. Compile the file
h. Create the following html file
<html>
<applet codebase=“.” code=“HelloWorld.class” height=100
width=100 >
</applet>
</html>
i. Save this file to the location where your class file resides
2. Try JBuilder to create a similar applet
3. Write code to display Bio-Data of your Institute
4. Modify your program and add the following line of code to change you font
color
g.setColor(Color.green);
5. Use following methods to draw some rectangles and circles
a. g.drawLine (int, int ,int, int);
b. g.drawOval(int, int ,int, int);
c. g.fillOval(int, int ,int, int);
d. g.drawPolygon(int xpoints[], int ypoints[],int numpoints);
6. Use the following code to load an image
Image img=getImage(getCodeBase(),"test.gif");
g.drawImage(img,40,40,50,50,this);
7. Use the following code to experience the life cycle of an applet
public class AppLife extends Applet{
public void init(){
System.out.println("Init called"); }
public void start(){
System.out.println("strat called") }
public void paint(Graphics g){
g.drawString("Paint called",25,25); }
public void stop(){
System.out.println("Calling stop"); }
public void destroy(){
System.out.println("Calling destroy"); }}
8. Use your drawing skills and graphics methods to draw the following calendar
Day-03
Exercise-01
Java-Programming
Docsity.com

Partial preview of the text

Download Creating a Java Applet: Steps, Code, and Graphics and more Exercises Java Programming in PDF only on Docsity!

Do not use the JBuilder Applet Wizard at this step

  1. Following the following steps to create your first applet a. Import the following packages into your program import java.applet.; import java.awt.; b. Create a class of your choice c. Extend the class from java.applet.Applet class d. Add the following method public void paint(Graphics g) e. Add g.drawString(“Hello World”,25,25) f. Save the program to a file HelloWorld.java g. Compile the file h. Create the following html file <applet codebase=“.” code=“HelloWorld.class” height= width=100 > i. Save this file to the location where your class file resides 2. Try JBuilder to create a similar applet
  2. Write code to display Bio-Data of your Institute
  3. Modify your program and add the following line of code to change you font color g.setColor(Color.green);
  4. Use following methods to draw some rectangles and circles a. g.drawLine (int, int ,int, int); b. g.drawOval(int, int ,int, int); c. g.fillOval(int, int ,int, int); d. g.drawPolygon(int xpoints[], int ypoints[],int numpoints);
  5. Use the following code to load an image Image img=getImage(getCodeBase(),"test.gif"); g.drawImage(img,40,40,50,50,this);
  6. Use the following code to experience the life cycle of an applet

public class AppLife extends Applet{ public void init(){ System.out.println("Init called"); } public void start(){ System.out.println("strat called") } public void paint(Graphics g){ g.drawString("Paint called",25,25); } public void stop(){ System.out.println("Calling stop"); } public void destroy(){ System.out.println("Calling destroy"); }}

  1. Use your drawing skills and graphics methods to draw the following calendar

Day- 03

Exercise- 01 Java-Programming

Docsity.com