applet是个panel,你直接把他勇于frame之类的就跟application一样了。

解决方案 »

  1.   

    不清楚,不过可以将一个类写成即是applet又是application
      

  2.   

    package com.lnboy;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class TestApplet extends Applet {
      private boolean isStandalone = false;
      Button button1 = new Button();  //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public TestApplet() {
      }
    //Main method
      public static void main(String[] args) {
        TestApplet applet = new TestApplet();
        applet.isStandalone = true;
        JFrame frame = new JFrame();
        //EXIT_ON_CLOSE == 3
        frame.setDefaultCloseOperation(3);
        frame.setTitle("Applet Frame");
        frame.getContentPane().add(applet, BorderLayout.CENTER);
        applet.init();
        applet.start();
        frame.setSize(400,320);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
        frame.setVisible(true);
      }  //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }  //Component initialization
      private void jbInit() throws Exception {
        button1.setLabel("button1");
        button1.addActionListener(new TestApplet_button1_actionAdapter(this));
        this.add(button1, null);
      }  //Start the applet
      public void start() {
      }  //Stop the applet
      public void stop() {
      }  //Destroy the applet
      public void destroy() {
      }  //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }  //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  void button1_actionPerformed(ActionEvent e) {
    if ("button1".equals( button1.getLabel())) {
      button1.setLabel("按钮一");
    }
    else {
      button1.setLabel("button1");
    }
      }
    }class TestApplet_button1_actionAdapter implements java.awt.event.ActionListener {
      TestApplet adaptee;  TestApplet_button1_actionAdapter(TestApplet adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.button1_actionPerformed(e);
      }
    }
      

  3.   

    这就是传说中的既是applet又是applecatoin