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

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

1.2     ! tam         1: /**
        !             2:  * PolyCalc.java $OpenXM$
        !             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:
                     98:   public void start(){
                     99:     textarea.append("Connecting to "+ host
                    100:                 +"("+ ControlPort +","+ DataPort +")\n");
                    101:
                    102:     try{
1.2     ! tam       103:       oxm = new OpenXM(host,ControlPort,DataPort);
1.1       tam       104:     }catch(java.io.IOException e){
                    105:       textarea.append("failed.\n");
                    106:       stop();
                    107:       return;
                    108:     }
                    109:     textarea.append("Connected.\n");
                    110:   }
                    111:
                    112:   public static void main(String argv[]){
                    113:     Frame frame = new Frame("Polynomial Calculator");
                    114:     Applet applet;
                    115:     String host = "localhost";
                    116:     int DataPort = 1300, ControlPort = 1200;
                    117:
                    118:     for(int i=0;i<argv.length;i++){
                    119:       if(argv[i].equals("-h")){
                    120:         System.out.println("");
                    121:         System.exit(0);
                    122:       }else if(argv[i].equals("-host")){
                    123:         host = argv[++i];
                    124:       }else if(argv[i].equals("-data")){
                    125:         DataPort = Integer.valueOf(argv[++i]).intValue();
                    126:       }else if(argv[i].equals("-control")){
                    127:         ControlPort = Integer.valueOf(argv[++i]).intValue();
                    128:       }else{
                    129:         System.err.println("unknown option :"+ argv[i]);
                    130:         System.exit(1);
                    131:       }
                    132:     }
                    133:     applet = new PolyCalc(host,ControlPort,DataPort);
                    134:
                    135:     applet.init();
                    136:     frame.add("Center",applet);
                    137:     frame.pack();
                    138:     frame.setSize(frame.getPreferredSize());
                    139:     frame.show();
                    140:     applet.start();
                    141:   }
                    142: }

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