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

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

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

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