***Welcome to ashrafedu.blogspot.com ***This website is maintained by ASHRAF***

posts

    JApplet

    JApplet is a simple extension of java.applet.Applet to use when creating Swing programs designed to be used in a web browser (or appletviewer ). As a direct subclass of Applet, JApplet is used in much the same way, with the init( ) , start( ), and stop( ) methods still playing critical roles. The primary thing JApplet provides that Applet does not is the use of a JRootPane as its single display component.

    JApplet extends the class in the form of java.applet.Applet. JApplets are executed in a tightly-controlled set of resources referred to as sandboxes. This prevents the JApplets from accessing local data like the clipboard or file system.

    Ex:

    import java.applet.*; 

    import javax.swing.*; 

    import java.awt.event.*; 

    public class EventJApplet extends JApplet implements ActionListener{ 

    JButton b; 

    JTextField tf; 

    public void init(){ 

    tf=new JTextField(); 

    tf.setBounds(30,40,150,20); 

    b=new JButton("Click"); 

    b.setBounds(80,150,70,40); 

    add(b);add(tf);  

    b.addActionListener(this); 

    setLayout(null); 

    } 

    public void actionPerformed(ActionEvent e){ 

    tf.setText("Welcome"); 

    } 

    } 

    Since JApplet actually extends Applet, much of the functionality is identical. There are a few differences, with JApplet, you have access to the content pane, which can be called using getContentPane(). If you have a content pane of your own (such as a panel) that you want to replace it with, you can call setContentPane(). When you add components to your applet, you add them to the content pane, not the frame.

    No comments:

    Post a Comment