我现在是想在自己的机器的配置完成web服务器,却不知如何配置,才能访问至该applet,能不能给我一个示例,谢了先!

解决方案 »

  1.   

    applet还需要WEB服务器支持?????
    你只要把applet嵌入到网页中,直接打开网页就可以看到效果了
      

  2.   

    那个applet的源代码是这样的。package chat_applet;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.net.*;
    /**
     * Title:        
     * Description:  
     * Copyright:    Copyright (c) 2001
     * Company:      
     * @author 
     * @version 1.0
     */public class Applet_chat extends Applet {
      boolean isStandalone = false;
      JPanel jPanel1 = new JPanel();
      BorderLayout borderLayout1 = new BorderLayout();
      JButton jButton1 = new JButton();
      JButton jButton2 = new JButton();
      JButton jButton3 = new JButton();
      JButton jButton4 = new JButton();
      JTextField jTextField_from = new JTextField();
      JButton jButton5 = new JButton();
      GridLayout gridLayout1 = new GridLayout();
      JLabel jLabel1 = new JLabel();
      TextField textField_pass = new TextField();
      JLabel jLabel2 = new JLabel();
      JTextField jTextField_to = new JTextField();
      JSplitPane jSplitPane1 = new JSplitPane();
      JSplitPane jSplitPane2 = new JSplitPane();
      JSplitPane jSplitPane3 = new JSplitPane();
      JScrollPane jScrollPane1 = new JScrollPane();
      JLabel jLabel3 = new JLabel();
      JTextArea jTextArea_con = new JTextArea();
      JLabel jLabel4 = new JLabel();
      JScrollPane jScrollPane2 = new JScrollPane();
      JTextArea jTextArea_rec = new JTextArea();
      Border border1;
      Border border2;
      TitledBorder titledBorder1;
      TitledBorder titledBorder2;
      TitledBorder titledBorder3;
      TitledBorder titledBorder4;
      TitledBorder titledBorder5;
      JButton jButton6 = new JButton();
      JTextField jTextField_name = new JTextField();
      TitledBorder titledBorder6;
      /**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 Applet_chat() {
      }
      /**Initialize the applet*/
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      /**Component initialization*/
      private void jbInit() throws Exception {
        border2 = BorderFactory.createEmptyBorder();
        titledBorder1 = new TitledBorder("");
        titledBorder2 = new TitledBorder("");
        titledBorder3 = new TitledBorder("");
        titledBorder4 = new TitledBorder("");
        titledBorder5 = new TitledBorder("");
        titledBorder6 = new TitledBorder("");
        this.setLayout(borderLayout1);
        jPanel1.setLayout(gridLayout1);
        jButton1.setBackground(Color.orange);
        jButton1.setEnabled(false);
        jButton1.setForeground(Color.blue);
        jButton1.setBorder(titledBorder5);
        jButton1.setMargin(new Insets(2, 4, 2, 4));
        jButton1.setText("发送");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        jButton2.setBackground(Color.orange);
        jButton2.setEnabled(false);
        jButton2.setForeground(Color.blue);
        jButton2.setBorder(titledBorder2);
        jButton2.setToolTipText("阅读最新消息");
        jButton2.setMargin(new Insets(2, 4, 2, 4));
        jButton2.setText("阅读");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton2_actionPerformed(e);
          }
        });
        jButton3.setBackground(Color.orange);
        jButton3.setEnabled(false);
        jButton3.setForeground(Color.blue);
        jButton3.setBorder(titledBorder1);
        jButton3.setToolTipText("查看历史所有记录");
        jButton3.setMargin(new Insets(2, 4, 2, 4));
        jButton3.setText("全部消息");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton3_actionPerformed(e);
          }
        });
        jButton4.setBackground(Color.orange);
        jButton4.setEnabled(false);
        jButton4.setForeground(Color.blue);
        jButton4.setBorder(titledBorder3);
        jButton4.setToolTipText("");
        jButton4.setMargin(new Insets(2, 4, 2, 4));
        jButton4.setText("清空");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton4_actionPerformed(e);
          }
        });
        jTextField_from.setColumns(10);
        jButton5.setBackground(Color.orange);
        jButton5.setForeground(Color.blue);
        jButton5.setBorder(titledBorder4);
        jButton5.setMargin(new Insets(2, 4, 2, 4));
        jButton5.setText("登录");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton5_actionPerformed(e);
          }
        });
        gridLayout1.setRows(2);
        gridLayout1.setColumns(6);
        gridLayout1.setHgap(5);
        jLabel1.setBorder(BorderFactory.createLoweredBevelBorder());
        jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel1.setText("登录号:");
        textField_pass.setEchoChar('*');
        jLabel2.setBorder(BorderFactory.createLoweredBevelBorder());
        jLabel2.setToolTipText("");
        jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel2.setText("对方编号:");
        jTextField_to.setToolTipText("请输入对方的编号");
        jTextField_to.setColumns(10);
        jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
        jSplitPane3.setOrientation(JSplitPane.VERTICAL_SPLIT);
        jLabel3.setText("消息录入框:");
        jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
        jTextArea_con.setMinimumSize(new Dimension(60, 50));
        jTextArea_con.setText("jTextArea1");
        jTextArea_con.setColumns(10);
        jLabel4.setText("消息接收框:");
        jButton6.setBackground(Color.orange);
        jButton6.setForeground(Color.blue);
        jButton6.setBorder(titledBorder6);
        jButton6.setText("注册");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton6_actionPerformed(e);
          }
        });
        jTextField_name.setColumns(10);
        this.add(jPanel1, BorderLayout.NORTH);
        jPanel1.add(jButton1, null);
        jPanel1.add(jButton2, null);
        jPanel1.add(jButton3, null);
        jPanel1.add(jButton4, null);
        jPanel1.add(jButton5, null);
        jPanel1.add(jButton6, null);
        jPanel1.add(jLabel1, null);
        jPanel1.add(jTextField_from, null);
        jPanel1.add(textField_pass, null);
        jPanel1.add(jTextField_name, null);
        jPanel1.add(jLabel2, null);
        jPanel1.add(jTextField_to, null);
        this.add(jSplitPane1, BorderLayout.CENTER);
        jSplitPane1.add(jSplitPane2, JSplitPane.TOP);
        jSplitPane2.add(jScrollPane1, JSplitPane.BOTTOM);
        jScrollPane1.getViewport().add(jTextArea_con, null);
        jSplitPane2.add(jLabel3, JSplitPane.TOP);
        jSplitPane1.add(jSplitPane3, JSplitPane.BOTTOM);
        jSplitPane3.add(jLabel4, JSplitPane.TOP);
        jSplitPane3.add(jScrollPane2, JSplitPane.BOTTOM);
        jScrollPane2.getViewport().add(jTextArea_rec, null);
      }
      /**Start the applet*/
      public void start() {
      }
      /**Stop the applet*/
      public void stop() {
      }
      /**Destroy the applet*/
      public void destroy() {
        of_logout();
        super.destroy();
      }
      /**Get Applet information*/
      public String getAppletInfo() {
        return "Applet Information";
      }
      /**Get parameter info*/
      public String[][] getParameterInfo() {
        return null;
      }
      /**Main method*/
      public static void main(String[] args) {
        Applet_chat applet = new Applet_chat();
        applet.isStandalone = true;
        Frame frame;
        frame = new Frame() {
          protected void processWindowEvent(WindowEvent e) {
            super.processWindowEvent(e);
            if (e.getID() == WindowEvent.WINDOW_CLOSING) {
              System.exit(0);
            }
          }
          public synchronized void setTitle(String title) {
            super.setTitle(title);
            enableEvents(AWTEvent.WINDOW_EVENT_MASK);
          }
        };
        frame.setTitle("Applet Frame");
        frame.add(applet, BorderLayout.CENTER);
        applet.init();
        applet.start();
        frame.setSize(500,320);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
        frame.setVisible(true);
      }
      
      //发送请求,并获得回信
       public void of_send(String as_send) {
        try{
           Socket sck = new Socket("lqh",888);
           DataInputStream dis  = new DataInputStream(sck.getInputStream());
           DataOutputStream dos = new DataOutputStream(sck.getOutputStream());
           dos.writeUTF(as_send);
           dos.flush();
           String ls_ret = dis.readUTF();
           jTextArea_rec.setText(ls_ret);
           sck.shutdownOutput();
           sck.shutdownInput();
           sck.close();
        }
      catch(Exception epp){
          jTextArea_rec.setText("请求失败:"+epp.toString());
        }
      }
      //登录
      public void of_login() {
        String ls_id,ls_pass,ls_send;
        ls_id = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_send = "login||"+ls_id +"||"+ls_pass+"||";
        try{
           Socket sck = new Socket("lqh",888);
           DataInputStream dis  = new DataInputStream(sck.getInputStream());
           DataOutputStream dos = new DataOutputStream(sck.getOutputStream());
           dos.writeUTF(ls_send);
           dos.flush();
           boolean lb_ret = dis.readBoolean();
           if (lb_ret) {
              jTextArea_rec.setText("登录成功!");
              jButton1.setEnabled(true);
              jButton2.setEnabled(true);
              jButton3.setEnabled(true);
              jButton4.setEnabled(true);
              jTextField_from.setEditable(false);
              textField_pass.setEditable(false);
              jButton5.setText("退出");
           }   
           else{
              jTextArea_rec.setText("登录失败!");  
           }
               
           sck.shutdownOutput();
           sck.shutdownInput();
           sck.close();
        }
      catch(Exception epp){
          jTextArea_rec.setText(epp.toString());
        }
      }
      
      //退出
      public void of_logout() {
        String ls_id,ls_pass,ls_send;
        ls_id = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_send = "close||"+ls_id +"||"+ls_pass+"||";
        of_send(ls_send);
        jButton1.setEnabled(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jTextField_from.setEditable(true);
        textField_pass.setEditable(true);
        jButton5.setText("登录");
                
         
      }
      //发送消息给
      void jButton1_actionPerformed(ActionEvent e) {
        String ls_id,ls_pass,ls_to,ls_con,ls_send;
        ls_id   = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_to   = jTextField_to.getText();
        ls_con  = jTextArea_con.getText();
        ls_send = "up||"+ls_id+"||"+ls_pass+"||"+ls_to+"||"+ls_con+"||";
        of_send(ls_send);
      }  //阅读其它人发给自己的消息 
      void jButton2_actionPerformed(ActionEvent e) {
        String ls_id,ls_pass,ls_to,ls_con,ls_send;
        ls_id   = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_send = "querynew||"+ls_id+"||"+ls_pass+"||";
        of_send(ls_send);
      }
      //读取全部历史记录。
      void jButton3_actionPerformed(ActionEvent e) {
        String ls_id,ls_pass,ls_to,ls_con,ls_send;
        ls_id   = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_send = "queryall||"+ls_id+"||"+ls_pass+"||";
        of_send(ls_send);
      }
      //清空历史记录。
      void jButton4_actionPerformed(ActionEvent e) {
        String ls_id,ls_pass,ls_to,ls_con,ls_send;
        ls_id   = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_send = "clearall||"+ls_id+"||"+ls_pass+"||";
        of_send(ls_send);
      }  void jButton5_actionPerformed(ActionEvent e) {
        if (jButton5.getText().equals(new String("登录"))){
          of_login();
        }
        else{
          of_logout();
        }
        
      }  void jButton6_actionPerformed(ActionEvent e) {
        String ls_id,ls_pass,ls_to,ls_con,ls_name,ls_send;
        ls_id   = jTextField_from.getText();
        ls_pass = textField_pass.getText();
        ls_name = jTextField_name.getText();
        ls_send = "newuser||"+ls_id+"||"+ls_pass+"||"+ls_name+"||";
        of_send(ls_send);
      }
      
    }