personalassistframe.java

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

JAVA
462
字号
/* PersonalAssistFrame.java * $Id: PersonalAssistFrame.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 PersonalAssistFrame * * @version     $Revision: 2.3 $ $Date: 1997-11-19 19:22:41+09 $ * @author      Osamu Furusawa * @author      Hajime Tsuchtiani */public class PersonalAssistFrame extends Frame {  private static final String rcsid = "$Id: PersonalAssistFrame.java,v 2.3 1997-11-19 19:22:41+09 ht Exp $ $Name: alpha5_1-release $";  private   PersonalAssist          agent;  private   Choice     carrier      = new Choice();  private   TextField  flight       = new TextField("");  private   Choice     departure     = new Choice();  private   Choice     arrival      = new Choice();  private   Choice     month        = new Choice();  private   Choice     day          = new Choice();  private   Choice     timeRange    = new Choice();  private   TextField  expired      = new TextField("30");  private   Button     show         = new Button("Show Flight");  private   Button     clear        = new Button("Clear");  private   Button     close        = new Button("Close");      private   FlightInfo flightInfo = new FlightInfo();      /**   * Constructor   *   * @param agent reference to KTPAgent   */  public PersonalAssistFrame(PersonalAssist agent) {    super("Flight Plan in PersonalAssistant");        this.agent = agent;        // carrier    setCarrier();     // departure    setDeparture();    // arrival    setArrival();    // month    setMonth();    // day    setDay();        // timeRange    timeRange.addItem("AM");    timeRange.addItem("PM");        // title label    Label titleLabel = new Label("Travel Assistant");    //Label titleLabel = new Label("Personal Assistant");    titleLabel.setFont(new Font("Helvetica", Font.BOLD, 36));    titleLabel.setForeground(new Color(60, 170, 60)); //  green    Panel titlePanel = new Panel();    titlePanel.add(titleLabel);    titlePanel.setBackground(Color.white);            // Panel 1 -------------------------------    GridBagLayout gridbag = new GridBagLayout();    Panel panel1 = new Panel();    panel1.setLayout(gridbag);    panel1.setBackground(Color.white);        // set Departure     Label labelDep = new Label("Departure");    labelDep.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelDep, 0, 0, 2, 1, 5, 5, 5, 5);    departure.setFont(new Font("TimesRoman", Font.BOLD, 15));    constrain(panel1, departure, 0,1,1,1, 5, 5, 5, 5);        // set Arrival    Label labelArr = new Label("Arrival");    labelArr.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelArr, 0, 2, 2, 1, 5, 5, 5, 5);    arrival.setFont(new Font("TimesRoman", Font.BOLD, 15));    constrain(panel1, arrival, 0,3,1,1, 5, 5, 5, 5);        // set Carreir     Label labelCar = new Label("Carrier");    labelCar.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelCar, 0, 4, 1, 1, 5, 5, 5, 5);    carrier.setFont(new Font("TimesRoman", Font.BOLD, 15));    constrain(panel1, carrier, 0, 5, 1, 1, 5, 5, 5, 5);        // set Month    Label labelMon = new Label("Month    ");    labelMon.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelMon, 2, 0, 1, 1, 5, 5, 5, 5);    month.setFont(new Font("TimesRoman", Font.BOLD, 15));    //constrain(panel1, month, 2, 1, 1, 1, 5, 5, 5, 5);        constrain(panel1, month,	      2, 1, 1, 1,	      12, 0,	      GridBagConstraints.NONE,	      GridBagConstraints.NORTHWEST,	      0.0, 0.0, 5, 5, 5, 5);        // set TimeRange    Label labelTime = new Label("TimeRange");    labelTime.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelTime, 2, 2, 1, 1, 5, 5, 5, 5);    timeRange.setFont(new Font("TimesRoman", Font.BOLD, 15));    constrain(panel1, timeRange,  	      2, 3, 1, 1, 	      50, 0,	      GridBagConstraints.NONE,	      GridBagConstraints.NORTHWEST,	      0.0, 0.0, 5, 5, 5, 5);            // set Day    Label labelDay = new Label("Day");    labelDay.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelDay, 4, 0, 1, 1, 5, 5, 5, 5);    day.setFont(new Font("TimesRoman", Font.BOLD, 15));    //constrain(panel1, day, 4, 1, 1, 1, 5, 5, 5, 5);    constrain(panel1, day,  	      4, 1, 1, 1, 	      20, 0,	      GridBagConstraints.NONE,	      GridBagConstraints.NORTHWEST,	      0.0, 0.0, 5, 5, 5, 5);            // set Expired    Label labelExp = new Label("Expired Time");    labelExp.setFont(new Font("TimesRoman", Font.BOLD, 18));    constrain(panel1, labelExp, 4, 2, 1, 1, 5, 5, 5, 5);    expired.setFont(new Font("TimesRoman", Font.BOLD, 15));    //constrain(panel1, expired, 4, 3, 1, 1, 5, 5, 5, 5);    constrain(panel1, expired,  	      4, 3, 1, 1, 	      21, 0,	      GridBagConstraints.NONE,	      GridBagConstraints.NORTHWEST,	      0.0, 0.0, 5, 5, 5, 5);            // set Button ----------------------------    Panel buttonPanel = new Panel();    buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));    buttonPanel.setBackground(Color.white);        show = new java.awt.Button("Show Flight");    show.setFont(new Font("Courier", Font.BOLD, 13));    //show.reshape(5,5,80,23);    //show.setBounds(new Rectangle(5,5,80,23));    buttonPanel.add(show);        close = new java.awt.Button("   Close   ");    close.setFont(new Font("Courier", Font.BOLD, 13));    //close.reshape(100,5,80,23);    //close.setBounds(new Rectangle(100,5,80,23));    buttonPanel.add(close);        //constrain(buttonPanel, show, 0,0,1,1,GridBagConstraints.NONE,    //          GridBagConstraints.CENTER, 0.3, 0.0, 0,0,0,0);    //constrain(buttonPanel, close, 2,0,1,1,GridBagConstraints.NONE,    //          GridBagConstraints.CENTER, 0.3, 0.0, 0,0,0,0);        // set Layout of whole frame ---------------------    setLayout(gridbag);    setBackground(Color.white);            constrain(this, titlePanel,0,0,1,1, GridBagConstraints.NONE,	      GridBagConstraints.CENTER, 0.0, 0.0, 1, 1, 1, 1);    constrain(this, panel1,0,1,1,1, GridBagConstraints.BOTH,	      GridBagConstraints.NORTHWEST, 0.0, 0.0, 1, 1, 1, 1);    constrain(this, buttonPanel,0,2,1,1, GridBagConstraints.HORIZONTAL,	      GridBagConstraints.CENTER, 0.0, 0.0, 10, 0, 10,0);            // set initial value    arrival.select("(CDG) Paris, France");    month.select("March");    day.select("21");    timeRange.select("AM");        //setSize(400,325);    pack();    show();  }      /**   * action on Button and Choice   *   * @param e event   * @param o object   */  public boolean action(Event e, Object o) {        if (e.target instanceof Button) {      if (e.target == show) {		flightInfo.setCarrier(carrier.getSelectedItem());	flightInfo.setDeparture(departure.getSelectedItem());	flightInfo.setArrival(arrival.getSelectedItem());		StringBuffer strbuf = new StringBuffer(monthToNumber(month.getSelectedItem()));	strbuf.append("/");	strbuf.append(day.getSelectedItem());	strbuf.append("/97 ");	strbuf.append(timeRange.getSelectedItem());	flightInfo.setDeptTime(strbuf.toString());		int expiredTime;	String temp = expired.getText();		if ( temp == null) 	  expiredTime = 15;	else	  expiredTime = Integer.parseInt(temp);		agent.showFlightSchedule(flightInfo, expiredTime);		return true;      } else if (e.target == close) {	dispose();	System.exit(0);      }    } else if (e.target instanceof Choice) {      print("select Choice");    }    return super.action(e, o);  }      /**   * handle event   *   * @param e event   */  public boolean handleEvent(Event e) {    if (e.id == Event.WINDOW_DESTROY) {      dispose();      System.exit(0);      return true;    }    return super.handleEvent(e);  }        /**   * set carrier.    */  private void setCarrier() {    carrier.addItem("any");    carrier.addItem("JAL");    carrier.addItem("ANA");  }      /**   * set departure   */  private void setDeparture() {    departure.addItem("(NRT) Tokyo, Japan");    departure.addItem("(CDG) Paris, France");    departure.addItem("(JFK) New York, U.S.");  }    /**   * set arrival   */  private void setArrival() {    arrival.addItem("(NRT) Tokyo, Japan");    arrival.addItem("(CDG) Paris, France");    arrival.addItem("(JFK) New York, U.S.");  }      /**   * set month   */  private void setMonth() {    month.addItem("January");    month.addItem("Febrary");    month.addItem("March");    month.addItem("April");    month.addItem("May");    month.addItem("June");    month.addItem("July");    month.addItem("August");    month.addItem("September");    month.addItem("October");    month.addItem("November");    month.addItem("December");  }      /**   * set day   */  private void setDay() {    day.addItem("01");    day.addItem("02");    day.addItem("03");    day.addItem("04");    day.addItem("05");    day.addItem("06");    day.addItem("07");    day.addItem("08");    day.addItem("09");    day.addItem("10");    day.addItem("11");    day.addItem("12");    day.addItem("13");    day.addItem("14");    day.addItem("15");    day.addItem("16");    day.addItem("17");    day.addItem("18");    day.addItem("19");    day.addItem("20");    day.addItem("21");    day.addItem("22");    day.addItem("23");    day.addItem("24");    day.addItem("25");    day.addItem("26");    day.addItem("27");    day.addItem("28");    day.addItem("29");    day.addItem("30");    day.addItem("31");  }    /**   * frame utility   */  public void constrain(Container container, Component component,			int grid_x, int grid_y, int grid_width, int grid_height,			int ipad_x, int ipad_y,			int fill, int anchor, double weight_x, double weight_y,			int top, int left, int bottom, int right) {        GridBagConstraints c = new GridBagConstraints();    c.gridx = grid_x; c.gridy = grid_y;    c.ipadx = ipad_x; c.ipady = ipad_y;        c.gridwidth = grid_width; c.gridheight = grid_height;    c.fill = fill; c.anchor = anchor;    c.weightx = weight_x; c.weighty = weight_y;    if ( top + bottom + left + right > 0 )       c.insets = new Insets(top, left, bottom, right);        ((GridBagLayout)container.getLayout()).setConstraints(component,c);    container.add(component);  }      /**   * frame utility   */  public void constrain(Container container, Component component,			int grid_x, int grid_y, int grid_width, int grid_height,			int fill, int anchor, double weight_x, double weight_y,			int top, int left, int bottom, int right) {        GridBagConstraints c = new GridBagConstraints();    c.gridx = grid_x; c.gridy = grid_y;    c.gridwidth = grid_width; c.gridheight = grid_height;    c.fill = fill; c.anchor = anchor;    c.weightx = weight_x; c.weighty = weight_y;    if ( top + bottom + left + right > 0 )       c.insets = new Insets(top, left, bottom, right);        //print("container.getLayout()" + container.getLayout());    ((GridBagLayout)container.getLayout()).setConstraints(component,c);    container.add(component);  }      /**   * frame utility   */  public void constrain(Container container, Component component,			int grid_x, int grid_y, int grid_width,int grid_height){        constrain(container, component, grid_x, grid_y, grid_width, grid_height,	      GridBagConstraints.NONE, 	      GridBagConstraints.NORTHWEST, 0.0, 0.0, 0, 0, 0, 0);  }      /**   * frame utility   */  public void constrain(Container container, Component component,			int grid_x, int grid_y, int grid_width, int grid_height,			int top, int left, int bottom, int right) {	            constrain(container, component, grid_x, grid_y, grid_width, grid_height,	      GridBagConstraints.NONE, 	      GridBagConstraints.NORTHWEST, 0.0, 0.0, top, left, bottom, right);      }      /**   *     */		  private String monthToNumber(String month) {        if ( month.equals("January") )      return "01";    else if ( month.equals("Febrary") )      return "02";    else if ( month.equals("March") )      return "03";    else if ( month.equals("April") )      return "04";    else if ( month.equals("May") )      return "05";    else if ( month.equals("June") )      return "06";    else if ( month.equals("July") )      return "07";    else if ( month.equals("August") )      return "08";    else if ( month.equals("September") )      return "09";    else if ( month.equals("October") )      return "10";    else if ( month.equals("November") )      return "11";        else       return "12";  }      /**   *    */  private void print(String msg) {    System.err.println("PersonalAssistFrame." + msg);  }    	    	  }

⌨️ 快捷键说明

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