+ Reply to Thread
Results 1 to 1 of 1

Thread: Java: JApplet

  1. #1
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Java: JApplet

    All of my tutorials thus far have been using JFrame to create windows. However, Java also supports the Applet, this enables your applications to be viewable in your internet browser. All swing components that have been discussed in my previous tutorials can be used in an Applet. Lets take a look at how an applet with a JButton might look.

    We are going to start with our basic class:

    Code:
    package tutorials;
    
    public class ApplTut {
    
    	public ApplTut() {
    		
    	}
    	
    }
    When creating the basic class, one of the main differences between a java application and an java applet is that applets do not use the [highlight="Java"]public static void main(String args[])[/highlight] as its main method for instantiation - it uses the init method.

    First we must extend the JApplet, just as we extend JFrame when making applications. Also we import javax.swing.JApplet.

    Code:
    package tutorials;
    
    import javax.swing.JApplet;
    
    public class ApplTut extends JApplet {
    
    	public ApplTut() {
    		
    	}
    
    	
    }
    Next we add the init method.

    Code:
    package tutorials;
    
    import javax.swing.JApplet;
    
    public class ApplTut extends JApplet {
    
    	public ApplTut() {
    		
    	}
    
    	public void init() {
    		
    	}
    	
    }
    And that is the basic shell of an applet. To add swing components, use the same method's you would for an application. Here is an example of how you would add a JButton.

    Code:
    package tutorials;
    
    import javax.swing.JApplet;
    import javax.swing.JButton;
    
    public class ApplTut extends JApplet {
    	private JButton button;
    	
    	public ApplTut() {
    		
    	}
    
    	public void init() {
    		button = new JButton("Click Me");
    		add(button);
    		
    	}
    	
    }
    Originally posted as The JApplet
    Last edited by John; 08-01-2010 at 09:29 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with array in JApplet
    By Qistina Tajuddin in forum Java Help
    Replies: 1
    Last Post: 08-21-2011, 06:03 AM
  2. Replies: 6
    Last Post: 06-14-2010, 04:11 PM
  3. Figuring out JApplet structure
    By denarced in forum Java Help
    Replies: 4
    Last Post: 04-09-2009, 08:58 AM
  4. Replies: 0
    Last Post: 10-19-2007, 09:57 AM
  5. Problem with JApplet and HTML page??
    By stack in forum Java Help
    Replies: 10
    Last Post: 08-22-2007, 07:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts