applet1.java

来自「java网络高级编程的配套源码,java网络高级编程为清华出版社出版.」· Java 代码 · 共 110 行

JAVA
110
字号
/*源程序清单4-9*/

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;

public class Applet1 extends Applet
{
  XYLayout xYLayout1 = new XYLayout();
  boolean isStandalone = false;
  Label label1 = new Label();
  TextArea textArea1 = new TextArea();
  Label label2 = new Label();
  Button button1 = new Button();
  Button button2 = new Button();
  Button button3 = new Button();
  AppletContext ac=null;
  Applet applet=null;

  //Construct the applet
  
  public Applet1()
  {
  }
//Initialize the applet

  public void init()
  {
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception
  {
    this.setBackground(new Color(192,192,192));
    xYLayout1.setWidth(400);
    xYLayout1.setHeight(300);
    label1.setText("从右面的applet接收到的数据:");
    label2.setText("控制右面applet的背景颜色");
    button1.setLabel("红色");
    button1.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        button1_actionPerformed(e);
      }
    });
    button2.setLabel("白色");
    button2.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        button2_actionPerformed(e);
      }
    });
    button3.setLabel("恢复");
    button3.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        button3_actionPerformed(e);
      }
    });
    this.setLayout(xYLayout1);
    this.add(label1, new XYConstraints(11, 5, 285, 24));
    this.add(textArea1, new XYConstraints(8, 34, 363, 143));
    this.add(label2, new XYConstraints(11, 183, 325, 20));
    this.add(button1, new XYConstraints(11, 217, 107, 28));
    this.add(button2, new XYConstraints(134, 218, 120, 29));
    this.add(button3, new XYConstraints(269, 221, 100, 26));
    ac=this.getAppletContext();
    applet=ac.getApplet("applet2");
  }
//Get Applet information
  
  public String getAppletInfo()
  {
    return "Applet Information";
  }
//Get parameter info

  public String[][] getParameterInfo()
  {
    return null;
  }

  void button1_actionPerformed(ActionEvent e)
  {
    applet.setBackground(Color.red);
  }

  void button2_actionPerformed(ActionEvent e)
  {
    applet.setBackground(Color.white);
  }

  void button3_actionPerformed(ActionEvent e)
  {
    applet.setBackground(new Color(192,192,192));
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?