Applet
Applet
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.
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.
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
//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