Docstoc

me _6_

Document Sample
me _6_ Powered By Docstoc
					                                Applets
                                                                               html-file for an applet
       public class MyApplet extends JApplet {
         public void init () {
            JPanel pane = getContentPane();                              <applet
            pane.add(new Jlabel("a label"));                                   code="path/MyAppletClass.class";
                    ...                                                        width="350"; height="130">
         }
                                                                         </applet>
         public void start() { . . . }
         public void stop() { . . . }
         public void destroy() { . . . }                                 path must be located in the dir of the .html
       }




           A main that can call an applet
import javax.swing.*;
                                                                                        An Applet
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
                                                                        public class MyAppletClass extends JApplet {
public class mainDisplay extends JApplet {                                 JPanel panel;
  public static void main (String [] args) {   // started with java
                                                                           public void init() {
      JFrame frame = new JFrame();
      JMenuBar menuBar = new JMenuBar();                                       panel = (JPanel)getContentPane();
      frame.setJMenuBar(menuBar);                                              panel.add (new JLabel("Bravo"));
      new Display().process(menuBar, (JPanel)frame.getContentPane());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                                                           }
      frame.pack();                                                        public void start() { }
      frame.setVisible(true);
                                                                           public void stop() { }
  }
      ...                                                               }




                The applet initialization                                            The applet body
                                                                        class Display {
       public void init () {          // started by a browser
                                                                           public void process (JMenuBar menuBar,
                                     // or appletviewer
                                                                                             JPanel pane) {
                 JMenuBar menuBar = new JMenuBar();
                 setJMenuBar(menuBar);                                        JMenu menu = new JMenu("A menu");
                 new Display().process(                                       menuBar.add(menu);
                      menuBar, (JPanel) getContentPane()                      menu.add(new JMenuItem("An item"));
                 );                                                           pane.add(new JLabel("A label"));
            }                                                              }
       }                                                                }




                                                                                                                        1

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:3
posted:5/6/2012
language:
pages:1