airframe.java

来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 238 行

JAVA
238
字号
/* AirFrame.java * $Id: AirFrame.java,v 2.3 1997-11-19 19:22:41+09 ht Exp $ * $Name: alpha5_1-release $ */package com.ibm.acl.kqmlsample.travel;import com.ibm.acl.kqml.*;import java.lang.*;import java.util.*;import java.awt.*;import java.awt.image.*;import java.io.*;/** * Class AirFrame * * @version     $Revision: 2.3 $ $Date: 1997-11-19 19:22:41+09 $ * @author      Osamu Furusawa * @author      Hajime Tsuchitani */public class AirFrame extends Frame {  private final static String rcsid = "$Id: AirFrame.java,v 2.3 1997-11-19 19:22:41+09 ht Exp $ $Name: alpha5_1-release $";  private List flightSched; // List box;  private Vector flightTable = null; // real service table  private Label flightSchedLabel;  private Label titleLabel;  private Panel northPanel;  private AirLine agent;  private TextArea textArea; // for system log  private Menu fileMenu;  private MenuItem quit;  private MenuBar menuBar;  private Button delay;  private GridBagLayout gridbag;  private GridBagConstraints gridBC;  public AirFrame(String title,			  AirLine agent)  {    super(title);    this.agent = agent;    flightTable = agent.getFlightTable();    // menu creation    fileMenu = new Menu("File");    quit = new MenuItem("Quit");    menuBar = new MenuBar();    fileMenu.add(quit);    menuBar.add(fileMenu);    setMenuBar(menuBar);    // syslog text area/*    textArea = new TextArea();    textArea.minimumSize(400, 300);    textArea.preferredSize(400, 400);    textArea.setBackground(Color.white);    textArea.setEditable(false);*/    // service table construction    flightSched = new List(20, false);    flightSched.minimumSize(20); // 5 rows needed.    flightSched.preferredSize(20);     flightSched.setFont(new Font("Monospaced", Font.BOLD, 20));    //flightSched.setFont(new Font("Courier", Font.PLAIN, 12));    flightSched.setBackground(Color.white);    Enumeration enum = flightTable.elements();    while(enum.hasMoreElements()) {      this.addItem((FlightInfo) enum.nextElement());    }    flightSchedLabel = new Label("Flight Schedule");    flightSchedLabel.setFont(new Font("Serif", Font.BOLD, 20));    //flightSchedLabel.setFont(new Font("Times", Font.BOLD, 16));    delay = new Button("Delay");    titleLabel = new Label(title);    titleLabel.setFont(new Font("SanSerif", Font.BOLD, 36));    //titleLabel.setFont(new Font("Helvetica", Font.PLAIN, 36));    titleLabel.setForeground(new Color(60, 170, 60)); //  green    northPanel = new Panel();    gridbag = new GridBagLayout();    gridBC = new GridBagConstraints();    northPanel.setLayout(gridbag);    gridBC.gridwidth = GridBagConstraints.REMAINDER;    gridbag.setConstraints(titleLabel, gridBC);    northPanel.add(titleLabel);    gridBC.gridwidth = GridBagConstraints.RELATIVE;    gridBC.anchor = GridBagConstraints.WEST;    gridBC.weightx = 1.0;    gridBC.weighty = 1.0;    gridbag.setConstraints(flightSchedLabel, gridBC);    northPanel.add(flightSchedLabel);    gridBC.gridwidth = GridBagConstraints.REMAINDER;    gridBC.anchor = GridBagConstraints.EAST;    gridbag.setConstraints(delay, gridBC);    northPanel.add(delay);    gridBC.anchor = GridBagConstraints.CENTER;    gridBC.fill = GridBagConstraints.BOTH;    gridbag.setConstraints(flightSched, gridBC);    northPanel.add(flightSched);    northPanel.setBackground(Color.white);    add("North", northPanel);    add("Center", flightSched);    pack();    resize(450, 500);  }  public void setMessage(String msg) {    textArea.appendText(msg + "\n");  }  public void addItem(FlightInfo flightInfo) {    if (flightTable == null) flightTable = new Vector(); // for test    StringBuffer       sb = new	StringBuffer("                                                  ");    String classname;    String arl;    sb.insert(0, classname = new String(flightInfo.getCarrier()));    sb.insert(5, classname = new String(flightInfo.getFlight()));    sb.insert(10, classname = new String(flightInfo.getDeparture()));    sb.insert(15, classname = new String(flightInfo.getArrival()));    sb.insert(20, classname = new String(flightInfo.getDeptTime()));    flightSched.addItem(sb.toString().trim());    // flightTable.addElement(flightInfo);   }  public boolean handleEvent(Event evt) {    if (evt.id == Event.WINDOW_DESTROY) {      System.exit(0);    } else if (evt.id == Event.ACTION_EVENT) {      if (evt.target == quit) {	System.exit(0);      } else if (evt.target == delay) {	int selectedIndex;	if ((selectedIndex = flightSched.getSelectedIndex()) != -1) {	  FlightInfo flightInfo = 	    (FlightInfo) flightTable.elementAt(selectedIndex);	  StringBuffer 	    sb = new	      StringBuffer("                                                  ");	  sb.insert(0, new String(flightInfo.getCarrier()));	  sb.insert(5, new String(flightInfo.getFlight()));	  sb.insert(10, new String(flightInfo.getDeparture()));	  sb.insert(15, new String(flightInfo.getArrival()));	  String deptTime = flightInfo.getDeptTime();	  String newDeptTime;	  if (deptTime.endsWith("AM")) {	    newDeptTime = 	      new String(deptTime.substring(0, deptTime.lastIndexOf("AM")) + 		       "PM");	  } else if (deptTime.endsWith("PM")){	    newDeptTime = 	      new String(deptTime.substring(0, deptTime.lastIndexOf("PM")) + 		       "AM");	  } else {	    newDeptTime = deptTime;	  }	  sb.insert(20, newDeptTime);	  	  flightInfo.setDeptTime(newDeptTime);	  flightTable.setElementAt(flightInfo, selectedIndex);	  flightSched.replaceItem(sb.toString(), selectedIndex);	  flightSched.select(selectedIndex);	  agent.updateSchedule(flightInfo);	}	return true;      }    }    return super.handleEvent(evt);  }// for test      public static void main(String[] args) {     AirFrame frame =       new AirFrame("Airline-A", null);    frame.addItem(new FlightInfo("JAL", "123", "NRT", "JFK",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "323", "NRT", "CDG",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "523", "NRT", "LHR",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "623", "NRT", "SFO",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "723", "NRT", "SFO",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "613", "NRT", "SFO",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "621", "NRT", "SFO",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "622", "NRT", "SFO",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "625", "NRT", "SFO",					      "03/21/97 AM"));    frame.addItem(new FlightInfo("JAL", "626", "NRT", "SFO",					      "03/21/97 AM"));    frame.show();  }}

⌨️ 快捷键说明

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