[BACK]Return to PolyCalc.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath

Annotation of OpenXM/src/OpenMath/PolyCalc.java, Revision 1.5

1.2       tam         1: /**
1.5     ! tam         2:  * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.4 1999/11/02 15:10:31 tam Exp $
1.2       tam         3:  */
                      4:
1.1       tam         5: import JP.ac.kobe_u.math.tam.OpenXM.*;
                      6: import java.applet.*;
1.5     ! tam         7: import java.awt.event.*;
1.1       tam         8: import java.awt.*;
                      9:
1.5     ! tam        10: class PolyCalc extends Applet implements ActionListener{
        !            11:   private String host = "localhost";
        !            12:   private int ControlPort = 1200,DataPort = 1300;
1.1       tam        13:   private OpenXM oxm;
1.5     ! tam        14:   //private Button random1_button,random2_button;
        !            15:   //private Button mul_button,remainder_button,swap_button,set_button;
1.1       tam        16:   private TextField poly1,poly2;
                     17:   private TextArea textarea;
1.5     ! tam        18:   private boolean debug = false;
1.1       tam        19:   //private Text
                     20:
                     21:   PolyCalc(String host,int ControlPort,int DataPort){
                     22:     this.host = host;
                     23:     this.ControlPort = ControlPort;
                     24:     this.DataPort = DataPort;
                     25:   }
                     26:
                     27:   public void init(){
                     28:     GridBagLayout gridbag = new GridBagLayout();
                     29:     GridBagConstraints c = new GridBagConstraints();
1.5     ! tam        30:     Button button;
1.1       tam        31:
                     32:     //setFont();
                     33:     setLayout(gridbag);
                     34:
                     35:     c.fill = GridBagConstraints.BOTH;
                     36:
                     37:     textarea = new TextArea();
                     38:     textarea.setEditable(false);
                     39:     c.gridwidth = GridBagConstraints.REMAINDER;
                     40:     gridbag.setConstraints(textarea,c);
                     41:     c.gridwidth = 1;
                     42:     add(textarea);
                     43:
                     44:     {
1.5     ! tam        45:       Label label = new Label("poly A:");
1.1       tam        46:       gridbag.setConstraints(label,c);
                     47:       add(label);
                     48:     }
                     49:
1.5     ! tam        50:     button = new Button("generate random polynomial A");
        !            51:     button.addActionListener(this);
        !            52:     gridbag.setConstraints(button,c);
        !            53:     add(button);
1.1       tam        54:
1.5     ! tam        55:     button = new Button("A * B");
        !            56:     button.addActionListener(this);
1.1       tam        57:     c.gridwidth = GridBagConstraints.REMAINDER;
1.5     ! tam        58:     gridbag.setConstraints(button,c);
1.1       tam        59:     c.gridwidth = 1;
1.5     ! tam        60:     add(button);
1.1       tam        61:
                     62:     poly1 = new TextField(20);
1.5     ! tam        63:     poly1.addActionListener(this);
1.1       tam        64:     c.gridwidth = 2;
                     65:     gridbag.setConstraints(poly1,c);
                     66:     c.gridwidth = 1;
                     67:     add(poly1);
                     68:
1.5     ! tam        69:     button = new Button("A % B");
        !            70:     button.addActionListener(this);
1.1       tam        71:     //c.gridx = 2;
                     72:     //c.weightx = 0.0;
1.5     ! tam        73:     gridbag.setConstraints(button,c);
        !            74:     add(button);
1.1       tam        75:
1.5     ! tam        76:     button = new Button("swap A & B");
        !            77:     button.addActionListener(this);
1.1       tam        78:     c.gridwidth = GridBagConstraints.REMAINDER;
1.5     ! tam        79:     gridbag.setConstraints(button,c);
1.1       tam        80:     c.gridwidth = 1;
1.5     ! tam        81:     add(button);
1.1       tam        82:
                     83:     {
1.5     ! tam        84:       Label label = new Label("poly B:");
1.1       tam        85:       gridbag.setConstraints(label,c);
                     86:       add(label);
                     87:     }
                     88:
1.5     ! tam        89:     button = new Button("generate random polynomial B");
        !            90:     button.addActionListener(this);
        !            91:     gridbag.setConstraints(button,c);
        !            92:     add(button);
1.1       tam        93:
1.5     ! tam        94:     button = new Button("poly1 <= poly2");
        !            95:     button.addActionListener(this);
1.1       tam        96:     c.gridwidth = GridBagConstraints.REMAINDER;
1.5     ! tam        97:     gridbag.setConstraints(button,c);
1.1       tam        98:     c.gridwidth = 1;
1.5     ! tam        99:     add(button);
1.1       tam       100:
                    101:     poly2 = new TextField();
                    102:     c.gridwidth = 2;
                    103:     gridbag.setConstraints(poly2,c);
                    104:     c.gridwidth = 1;
                    105:     add(poly2);
1.5     ! tam       106:
        !           107:     button = new Button("quit");
        !           108:     button.addActionListener(this);
        !           109:     c.gridwidth = GridBagConstraints.REMAINDER;
        !           110:     gridbag.setConstraints(button,c);
        !           111:     c.gridwidth = 1;
        !           112:     add(button);
1.1       tam       113:   }
                    114:
1.5     ! tam       115:   public void actionPerformed(ActionEvent e) {
        !           116:     String arg = e.getActionCommand();
1.3       tam       117:
1.5     ! tam       118:     debug("press \""+ arg +"\" button.");
        !           119:
        !           120:     /*
        !           121:       if ("first".equals(arg)) {
        !           122:       ((CardLayout)cards.getLayout()).first(cards);
        !           123:       } else if ("next".equals(arg)) {
        !           124:       ((CardLayout)cards.getLayout()).next(cards);
        !           125:       } else if ("previous".equals(arg)) {
        !           126:       ((CardLayout)cards.getLayout()).previous(cards);
        !           127:       } else if ("last".equals(arg)) {
        !           128:       ((CardLayout)cards.getLayout()).last(cards);
        !           129:       } else {
        !           130:       ((CardLayout)cards.getLayout()).show(cards,(String)arg);
        !           131:       }
        !           132:       */
        !           133:   }
1.3       tam       134:
1.1       tam       135:   public void start(){
                    136:     textarea.append("Connecting to "+ host
                    137:                 +"("+ ControlPort +","+ DataPort +")\n");
                    138:
                    139:     try{
1.2       tam       140:       oxm = new OpenXM(host,ControlPort,DataPort);
1.3       tam       141:       textarea.append("Connected.\n");
1.1       tam       142:     }catch(java.io.IOException e){
                    143:       textarea.append("failed.\n");
                    144:       stop();
                    145:     }
                    146:   }
                    147:
1.5     ! tam       148:   private void debug(String str){
        !           149:     if(debug){
        !           150:       System.out.println(str);
        !           151:     }
        !           152:   }
        !           153:
1.4       tam       154:   private static String usage(){
                    155:     String ret = "";
                    156:
                    157:     ret += "usage\t: java PolyCalc [options]\n";
                    158:     ret += "options\t:\n";
                    159:     ret += "\t -h \t show this message\n";
                    160:     ret += "\t -host hostname \t (default localhost)\n";
                    161:     ret += "\t -data port \t (default 1300)\n";
                    162:     ret += "\t -control port \t (default 1200)\n";
1.5     ! tam       163:     ret += "\t -debug \t display debug message\n";
1.4       tam       164:
                    165:     return ret;
                    166:   }
                    167:
1.1       tam       168:   public static void main(String argv[]){
                    169:     Frame frame = new Frame("Polynomial Calculator");
1.5     ! tam       170:     //Applet applet;
        !           171:     PolyCalc applet;
1.1       tam       172:     String host = "localhost";
                    173:     int DataPort = 1300, ControlPort = 1200;
                    174:
                    175:     for(int i=0;i<argv.length;i++){
                    176:       if(argv[i].equals("-h")){
1.4       tam       177:         System.out.print(usage());
1.1       tam       178:         System.exit(0);
1.5     ! tam       179:       }else if(argv[i].equals("-debug")){
        !           180:        //debug = true;
1.1       tam       181:       }else if(argv[i].equals("-host")){
                    182:         host = argv[++i];
                    183:       }else if(argv[i].equals("-data")){
                    184:         DataPort = Integer.valueOf(argv[++i]).intValue();
                    185:       }else if(argv[i].equals("-control")){
                    186:         ControlPort = Integer.valueOf(argv[++i]).intValue();
                    187:       }else{
1.4       tam       188:         System.err.println("unknown option : "+ argv[i]);
1.5     ! tam       189:         System.err.println("");
1.4       tam       190:         System.err.print(usage());
1.1       tam       191:         System.exit(1);
                    192:       }
                    193:     }
                    194:     applet = new PolyCalc(host,ControlPort,DataPort);
1.5     ! tam       195:     applet.debug = true;
1.1       tam       196:
                    197:     applet.init();
                    198:     frame.add("Center",applet);
                    199:     frame.pack();
                    200:     frame.setSize(frame.getPreferredSize());
                    201:     frame.show();
                    202:     applet.start();
                    203:   }
                    204: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>