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

📄 wb.java

📁 it is whiteboard sourse code
💻 JAVA
字号:
package org.merlin.step.nov;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.io.*;import java.net.*;import java.util.*;public class WB extends Frame implements ActionListener {  public WB () {    super ("Whiteboard");    enableEvents (AWTEvent.WINDOW_EVENT_MASK);  }  protected void processWindowEvent (WindowEvent e) {    super.processWindowEvent (e);    if (e.getID () == WindowEvent.WINDOW_CLOSING)      setVisible (false);  }  protected void processEvent (AWTEvent e) {    if ((e instanceof ActionEvent) && (e.getSource () instanceof Applet)) {      init ((Applet) e.getSource ());    } else {      super.processEvent (e);    }  }  Applet parent;  ObservableList contents;  Hashtable ctrlImages, ctrlClasses;  LWContainer infoHolder;  WBContainer display;  void init (Applet a) {    parent = a;    contents = new ObservableList ();    display = new WBContainer (contents, new Dimension (256, 256));    display.setLayout (new BorderLayout ());    add ("Center", display);    LWContainer ctrlHolder = new LWContainer (), ctrls = new LWContainer ();    add ("West", ctrlHolder);    ctrlHolder.setLayout (new FlowLayout (FlowLayout.LEFT, 0, 0));    ctrlHolder.add (ctrls);    ctrls.setLayout (new GridLayout (0, 1, 0, 2));    ctrlImages = new Hashtable ();    ctrlClasses = new Hashtable ();    try {      URL u = new URL (parent.getCodeBase (), "config.txt");      BufferedReader r = new BufferedReader (new InputStreamReader (u.openStream (), "latin1"));      String line;      while ((line = r.readLine ()) != null) {        StringTokenizer t = new StringTokenizer (line, ",");        String name = t.nextToken (), imageName = t.nextToken (), className = t.nextToken ();        Image theImage = parent.getImage (parent.getCodeBase (), imageName);        LWImageButton button = new LWImageButton (name, theImage, new Dimension (64, 64));        ctrls.add (button);        ctrlImages.put (name, theImage);        try {          ctrlClasses.put (name, Class.forName (className));        } catch (ClassNotFoundException ex) {        button.setEnabled (false);        }        button.addActionListener (this);      }      r.close ();    } catch (IOException ex) {      ex.printStackTrace ();    }    infoHolder = new LWContainer ();    infoHolder.setLayout (new BorderLayout ());    LWImageButton logo = new LWImageButton ("", parent.getImage (parent.getCodeBase (), "logo.jpeg"), new Dimension (64, 64));    logo.setEnabled (false);    infoHolder.add ("West", logo);    add ("South", infoHolder);    pack ();  }  Tool currentTool;  public void actionPerformed (ActionEvent e) {    Image theImage = (Image) ctrlImages.get (e.getActionCommand ());    Class theClass = (Class) ctrlClasses.get (e.getActionCommand ());    try {      if (currentTool != null) {        currentTool.dispose ();        currentTool = null;      }      currentTool = (Tool) theClass.newInstance ();      currentTool.setDisplayList (contents);      LWImageButton button = new LWImageButton (e.getActionCommand (), theImage, new Dimension (64, 64));      button.setEnabled (false);      infoHolder.removeAll ();      infoHolder.add ("West", button);      infoHolder.add ("Center", currentTool.getControls ());      infoHolder.validate ();      display.removeAll ();      display.add ("Center", currentTool.getDisplay ());      display.validate ();    } catch (InstantiationException ex) {      ex.printStackTrace ();    } catch (IllegalAccessException ex) {      ex.printStackTrace ();    }  }}

⌨️ 快捷键说明

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