0% found this document useful (0 votes)
39 views

Applet

The document discusses several Java applet programs that demonstrate using threads, resizing images, getting user input, and other concepts. It includes programs that increment a value when started and stopped, draw increasing sized rectangles, display an image that resizes on minimizing/maximizing, and requests user input to display the largest number. The student is asked questions about executing the programs in different environments and modifying the code to demonstrate thread usage and image/output behavior.

Uploaded by

Ifnaan Jeylan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Applet

The document discusses several Java applet programs that demonstrate using threads, resizing images, getting user input, and other concepts. It includes programs that increment a value when started and stopped, draw increasing sized rectangles, display an image that resizes on minimizing/maximizing, and requests user input to display the largest number. The student is asked questions about executing the programs in different environments and modifying the code to demonstrate thread usage and image/output behavior.

Uploaded by

Ifnaan Jeylan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Advanced Programming [IT 3305] Lab Activity Week 4 [on Applet] I Creating and Executing Threads //Program I import

java.awt.Graphics; import javax.swing.JApplet; public class NewJApplet extends JApplet{ int x ; public void init(){x = 5;} public void start(){x+=2;} public void paint(Graphics g){ super.paint(g); g.drawString("value of x is " + x, 20, 20); } public void stop(){x*=2;} }
1.

Answer the following questions based on program I

Compile the program by using the javac command and embed the class file into an HTML document. a) Execute it by using a browser b) Execute it by the appletViewer command.

2. Execute the program in NetBeans IDE (


Select File->New File; From the categories list of the New File dialog box select java, From the File Types list JApplet Click on Next then Finish Write the program Right-Click in the program and select Run-File )

3.

Open the HTML document generated by NetBeans with Notepad (it is in path of the project_folder\build directory). start and stop methods

II

Answer the following questions based on program II

//Program I import java.awt.Graphics; import javax.swing.JApplet; public class NewJApplet extends JApplet{ int x ; public void init(){x = 5;} public void start(){x+=2;} public void paint(Graphics g){ super.paint(g); g.drawString("value of x is " + x, 20, 20); } public void stop(){x*=2;} } 1. Execute the program by using appletViewer
2.

Minimize and then maximize the appletViever repeatedly and explain about the result. Answer the following questions based on program III //Program III import java.awt.Graphics; import javax.swing.JApplet; public class NewJApplet extends JApplet{ int x ; public void init(){x = 10;}

III

public void paint(Graphics g){ super.paint(g); for(x = 0; x <= 500; x+=10) g.drawRect(10, 10, x, x); } }
1. 2.

Run the program, explain about it. Replace the last line by the statement g.drawRect(x, x, 100, 100); . Execute the program and explain about the output. Replace the last line by the statement g.drawRect(2*x, 10, 10, 100); Execute the program and explain about the output. Answer the following questions based on program IV //Program III import javax.swing.JApplet; import java.awt.Image; import java.awt.Graphics; public class app1 extends JApplet{ Image img1; int x = 100; public void init(){ img1 = getImage(getDocumentBase(), "flag.png"); } public void paint(Graphics g){ super.paint(g); g.drawImage(img1, 20, 20, x, x, this); } }

3.

IV

1.

Create an image with paint brush and save it in the same folder with the HTML document that contains the applet by the name flag.png. Execute the program and explain about it. Replace the last line by the statement g.drawImage(img1, 10, 10, getWidth() - 20, getHeight() - 20, this); Modify the program so that the size of the image increases whenever you minimize and maximize the appletViewer that displays the image. Write an applet program that receives three numbers from the keyboard and displays the largest number. Write an applet program that displays
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

2. 3.

VI

You might also like