⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 componenttest.java

📁 详细讲解了java的基础知识
💻 JAVA
字号:
package AWTTest;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//import javax.swing.*;

public class ComponentTest extends Applet {
  boolean isStandalone = false;
  Panel panel1 = new Panel();
  Button button1 = new Button();
  Button button2 = new Button();
  TextArea textArea1 = new TextArea();

  //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 ComponentTest() {
  }

  //Initialize the applet
  public void init() {
    try  {
      jbInit();
    }
    catch(Exception e)  {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception {
    this.setSize(new Dimension(400,300));
    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);
      }
    });
    textArea1.setText("请压按钮一");
    this.getContentPane().add(panel1, BorderLayout.SOUTH);
    panel1.add(button1, null);
    panel1.add(button2, null);
    this.getContentPane().add(textArea1, BorderLayout.CENTER);
  }

  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }

  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }
  // static initializer for setting look & feel
  static {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }
    catch (Exception e) {}
  }

  void button1_actionPerformed(ActionEvent e) {
    String btn1name=button1.getName ();
    textArea1.append("按钮一的名称:"+btn1name);
    String lbl1=button1.getLabel();
    textArea1.append ("按钮一的标签:"+lbl1);
    Dimension size1=button1.getSize ();
    textArea1.append ("按钮一的大小:"+size1);
  }

  void button2_actionPerformed(ActionEvent e) {
    System.exit(0);
  }

}    


⌨️ 快捷键说明

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