IMRAN DAUDFOUNDATION UNIVERSITYINSTITUTE OF MANAGEMENT ANDCOMPUTER SCIENCESImran DaudFUIMCSWeb EngineeringJava Applets
Applets An applet is a Java program that a browser candownload and run. An applet is embedded inside a web page and runs...
Sample Applet Code Two steps to turning it in to an Applet 1. Change "extend JFrame" to "extends JApplet" and get rid of...
Applet Life Cycle loaded -> created -> initialized -> started <=> stopped -> destroyed The applet maybe stopped because ...
Applets have restrictions: Cannot read or write files on the client machine Cannot run programs on the client machine C...
Steps to create Applet Projects inNetbeans Choose File > New Project (Ctrl-Shift-N). UnderCategories, select Java. Choos...
Create applet source file Right-click the HelloApplet project and choose Propertiesto open the Properties window. Select...
Demo Init() Start() Stop() Destroy()
Setting ground for applet Set all static parameters in init() function. Like Setsize(int width, int height) Setbackgrou...
Applet ExampleDraw Lines
Drawing Shapes Rectangle Oval Etc (consult documentation)
Adding Mouse MouseListener MouseMotionListener (Consult API Documentation for function details)
Keyboard Input KeyListener actionListener (Consult API Documentatio)
 Panel JTextField JTextArea JCombobox etc
Java Layouts FlowLayout BorderLayout GridLayout BoxLayout CardLayout GridBagLayout GroupLayout SpringLayout
Threads Thread --- Class Runnable ---- Interface
Class --- Thread Public Class A extends Thread{ Public void run(){ } } A aa= new A(); aa.start();
Runnable Public class A implements Runnable{ Public void run(){ } } A aa = new A(); Thread t1 = new Thread(aa); t1....
Reference http://www.csl.mtu.edu/cs2321/ Netbeans.org
Upcoming SlideShare
Loading in …5
×

3. applets

528 views

Published on

JSP (Java Server Pages) Lecture # 3
Alternative of the Flash, Very easy and helpful notes

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
528
On SlideShare
0
From Embeds
0
Number of Embeds
155
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

3. applets

  1. 1. IMRAN DAUDFOUNDATION UNIVERSITYINSTITUTE OF MANAGEMENT ANDCOMPUTER SCIENCESImran DaudFUIMCSWeb EngineeringJava Applets
  2. 2. Applets An applet is a Java program that a browser candownload and run. An applet is embedded inside a web page and runs inthe context of a browser. An applet must be a subclass of thejava.applet.Applet class. Swing provides javax.swing.JApplet.
  3. 3. Sample Applet Code Two steps to turning it in to an Applet 1. Change "extend JFrame" to "extends JApplet" and get rid of the main, youll have to import javax.swing.JApplet public class MyApp extends JApplet { ... } // end MyApp 2. Embed the application into the webpage, using html <html> <head> <title> My Applet </title </head> <body> <! this is the applet tag which has attributes, there must be code, width, height> <applet code = "MyApp.class” width = "300” height = "300”> <! there can be optional parameters > <param name="someParamName" value="paramStringValue" > </applet> </body> </html>
  4. 4. Applet Life Cycle loaded -> created -> initialized -> started <=> stopped -> destroyed The applet maybe stopped because the user has changed focused JApplet has methods initialized, started, stopped and destroyed phases.They have default behavior that you can over write. init() - this where you can load the parameter, someParamName, with theirString values using getParamter("someParamName"). Note that order isnot important. start() - here you can start things after stopping stop() - allows you save information before stopping and to use in start() destroy() - allows you clean up. Note stop will be called first.
  5. 5. Applets have restrictions: Cannot read or write files on the client machine Cannot run programs on the client machine Cannot make any computer connectionsBut the Applet can read data files on the Sever
  6. 6. Steps to create Applet Projects inNetbeans Choose File > New Project (Ctrl-Shift-N). UnderCategories, select Java. Choose one of the following: If you are creating a new applet source file, select Java ClassLibrary under Projects. Click Next. If you want to import an applet source file, select Java Projectwith Existing Sources. Click Next. Specify the files location inthe Source Packages Folder text box. Under Project Name, type HelloApplet. Change theProject Location to any folder on your computer. Click Finish.
  7. 7. Create applet source file Right-click the HelloApplet project and choose Propertiesto open the Properties window. Select the desired Source / Binary Format for the projectfrom source tab. Right-click the HelloApplet project node in the Projectswindow and select New > Other (Ctrl-N). Under Categories, select Java. Under File Types, selectApplet. (for visual design applet select Swing GUI Forms > JAppletForm.) Give name to applet and click finish.
  8. 8. Demo Init() Start() Stop() Destroy()
  9. 9. Setting ground for applet Set all static parameters in init() function. Like Setsize(int width, int height) Setbackgroundcolor()
  10. 10. Applet ExampleDraw Lines
  11. 11. Drawing Shapes Rectangle Oval Etc (consult documentation)
  12. 12. Adding Mouse MouseListener MouseMotionListener (Consult API Documentation for function details)
  13. 13. Keyboard Input KeyListener actionListener (Consult API Documentatio)
  14. 14.  Panel JTextField JTextArea JCombobox etc
  15. 15. Java Layouts FlowLayout BorderLayout GridLayout BoxLayout CardLayout GridBagLayout GroupLayout SpringLayout
  16. 16. Threads Thread --- Class Runnable ---- Interface
  17. 17. Class --- Thread Public Class A extends Thread{ Public void run(){ } } A aa= new A(); aa.start();
  18. 18. Runnable Public class A implements Runnable{ Public void run(){ } } A aa = new A(); Thread t1 = new Thread(aa); t1.start();
  19. 19. Reference http://www.csl.mtu.edu/cs2321/ Netbeans.org

×