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

📄 reusable.java

📁 Java中可重用的事件处理的设计与实现的代码
💻 JAVA
字号:
index = ++index % params.length;
         area.setText(params[index]);
      }
   }

   public static void main(String args[]){
      if(args.length > 1){
         UIDemo1 one = new UIDemo1(args);
      }else{
         usage();
      }
   }
   private static void usage(){
      System.err.println("You may excute this program as below:");
      System.err.println("java UIDemo1 params1 params2 ...");
      System.exit(-1);
   }
}


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

public class UIDemo2{
  private JFrame frame;
  private JButton button;
  private JTextArea area;
  private int index = -1;
  private String [] params;

  private UIDemo2(String args[]){
    params = args;
    area = new JTextArea(5,25);
    button = new JButton("Click Here!");
    button.addActionListener(new SemiReusableActionListener(this));

    frame = new JFrame(getClass().getName());
    frame.addWindowListener(new ReusableWindowAdapter());
    Container cont = frame.getContentPane();
    JScrollPane scrollPane = new JScrollPane(area);
    cont.add(scrollPane,BorderLayout.NORTH);
    cont.add(button,BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
  }
  void setMessage(Object source){
    if(source.equals(button)){
      index = ++index % params.length;
      area.setText(params[index]);
    }
  }

  public static void main(String args[]){
    if(args.length > 1){
      UIDemo2 two = new UIDemo2(args);
    }else{
      usage();
    }
  }
  private static void usage(){
      System.err.println("You may excute this program as below:");

⌨️ 快捷键说明

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