version 1.2, 1999/11/02 14:54:37 |
version 1.5, 1999/11/02 15:58:11 |
|
|
/** |
/** |
* PolyCalc.java $OpenXM$ |
* $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.4 1999/11/02 15:10:31 tam Exp $ |
*/ |
*/ |
|
|
import JP.ac.kobe_u.math.tam.OpenXM.*; |
import JP.ac.kobe_u.math.tam.OpenXM.*; |
import java.applet.*; |
import java.applet.*; |
|
import java.awt.event.*; |
import java.awt.*; |
import java.awt.*; |
|
|
class PolyCalc extends Applet{ |
class PolyCalc extends Applet implements ActionListener{ |
private String host; |
private String host = "localhost"; |
int ControlPort,DataPort; |
private int ControlPort = 1200,DataPort = 1300; |
private OpenXM oxm; |
private OpenXM oxm; |
private Button random1_button,random2_button; |
//private Button random1_button,random2_button; |
private Button mul_button,remainder_button,swap_button,set_button; |
//private Button mul_button,remainder_button,swap_button,set_button; |
private TextField poly1,poly2; |
private TextField poly1,poly2; |
private TextArea textarea; |
private TextArea textarea; |
|
private boolean debug = false; |
//private Text |
//private Text |
|
|
PolyCalc(String host,int ControlPort,int DataPort){ |
PolyCalc(String host,int ControlPort,int DataPort){ |
Line 25 class PolyCalc extends Applet{ |
|
Line 27 class PolyCalc extends Applet{ |
|
public void init(){ |
public void init(){ |
GridBagLayout gridbag = new GridBagLayout(); |
GridBagLayout gridbag = new GridBagLayout(); |
GridBagConstraints c = new GridBagConstraints(); |
GridBagConstraints c = new GridBagConstraints(); |
|
Button button; |
|
|
//setFont(); |
//setFont(); |
setLayout(gridbag); |
setLayout(gridbag); |
Line 39 class PolyCalc extends Applet{ |
|
Line 42 class PolyCalc extends Applet{ |
|
add(textarea); |
add(textarea); |
|
|
{ |
{ |
Label label = new Label("poly 1:"); |
Label label = new Label("poly A:"); |
gridbag.setConstraints(label,c); |
gridbag.setConstraints(label,c); |
add(label); |
add(label); |
} |
} |
|
|
random1_button = new Button("generate random polynomial"); |
button = new Button("generate random polynomial A"); |
gridbag.setConstraints(random1_button,c); |
button.addActionListener(this); |
add(random1_button); |
gridbag.setConstraints(button,c); |
|
add(button); |
|
|
mul_button = new Button("poly1 * poly2"); |
button = new Button("A * B"); |
|
button.addActionListener(this); |
c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
gridbag.setConstraints(mul_button,c); |
gridbag.setConstraints(button,c); |
c.gridwidth = 1; |
c.gridwidth = 1; |
add(mul_button); |
add(button); |
|
|
poly1 = new TextField(20); |
poly1 = new TextField(20); |
|
poly1.addActionListener(this); |
c.gridwidth = 2; |
c.gridwidth = 2; |
gridbag.setConstraints(poly1,c); |
gridbag.setConstraints(poly1,c); |
c.gridwidth = 1; |
c.gridwidth = 1; |
add(poly1); |
add(poly1); |
|
|
remainder_button = new Button("poly1 % poly2"); |
button = new Button("A % B"); |
|
button.addActionListener(this); |
//c.gridx = 2; |
//c.gridx = 2; |
//c.weightx = 0.0; |
//c.weightx = 0.0; |
gridbag.setConstraints(remainder_button,c); |
gridbag.setConstraints(button,c); |
add(remainder_button); |
add(button); |
|
|
swap_button = new Button("swap poly1 & poly2"); |
button = new Button("swap A & B"); |
|
button.addActionListener(this); |
c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
gridbag.setConstraints(swap_button,c); |
gridbag.setConstraints(button,c); |
c.gridwidth = 1; |
c.gridwidth = 1; |
add(swap_button); |
add(button); |
|
|
{ |
{ |
Label label = new Label("poly 2:"); |
Label label = new Label("poly B:"); |
gridbag.setConstraints(label,c); |
gridbag.setConstraints(label,c); |
add(label); |
add(label); |
} |
} |
|
|
random2_button = new Button("generate random polynomial"); |
button = new Button("generate random polynomial B"); |
gridbag.setConstraints(random2_button,c); |
button.addActionListener(this); |
add(random2_button); |
gridbag.setConstraints(button,c); |
|
add(button); |
|
|
set_button = new Button("poly1 <= poly2"); |
button = new Button("poly1 <= poly2"); |
|
button.addActionListener(this); |
c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
gridbag.setConstraints(set_button,c); |
gridbag.setConstraints(button,c); |
c.gridwidth = 1; |
c.gridwidth = 1; |
add(set_button); |
add(button); |
|
|
poly2 = new TextField(); |
poly2 = new TextField(); |
c.gridwidth = 2; |
c.gridwidth = 2; |
gridbag.setConstraints(poly2,c); |
gridbag.setConstraints(poly2,c); |
c.gridwidth = 1; |
c.gridwidth = 1; |
add(poly2); |
add(poly2); |
|
|
|
button = new Button("quit"); |
|
button.addActionListener(this); |
|
c.gridwidth = GridBagConstraints.REMAINDER; |
|
gridbag.setConstraints(button,c); |
|
c.gridwidth = 1; |
|
add(button); |
} |
} |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
String arg = e.getActionCommand(); |
|
|
|
debug("press \""+ arg +"\" button."); |
|
|
|
/* |
|
if ("first".equals(arg)) { |
|
((CardLayout)cards.getLayout()).first(cards); |
|
} else if ("next".equals(arg)) { |
|
((CardLayout)cards.getLayout()).next(cards); |
|
} else if ("previous".equals(arg)) { |
|
((CardLayout)cards.getLayout()).previous(cards); |
|
} else if ("last".equals(arg)) { |
|
((CardLayout)cards.getLayout()).last(cards); |
|
} else { |
|
((CardLayout)cards.getLayout()).show(cards,(String)arg); |
|
} |
|
*/ |
|
} |
|
|
public void start(){ |
public void start(){ |
textarea.append("Connecting to "+ host |
textarea.append("Connecting to "+ host |
+"("+ ControlPort +","+ DataPort +")\n"); |
+"("+ ControlPort +","+ DataPort +")\n"); |
|
|
try{ |
try{ |
oxm = new OpenXM(host,ControlPort,DataPort); |
oxm = new OpenXM(host,ControlPort,DataPort); |
|
textarea.append("Connected.\n"); |
}catch(java.io.IOException e){ |
}catch(java.io.IOException e){ |
textarea.append("failed.\n"); |
textarea.append("failed.\n"); |
stop(); |
stop(); |
return; |
|
} |
} |
textarea.append("Connected.\n"); |
|
} |
} |
|
|
|
private void debug(String str){ |
|
if(debug){ |
|
System.out.println(str); |
|
} |
|
} |
|
|
|
private static String usage(){ |
|
String ret = ""; |
|
|
|
ret += "usage\t: java PolyCalc [options]\n"; |
|
ret += "options\t:\n"; |
|
ret += "\t -h \t show this message\n"; |
|
ret += "\t -host hostname \t (default localhost)\n"; |
|
ret += "\t -data port \t (default 1300)\n"; |
|
ret += "\t -control port \t (default 1200)\n"; |
|
ret += "\t -debug \t display debug message\n"; |
|
|
|
return ret; |
|
} |
|
|
public static void main(String argv[]){ |
public static void main(String argv[]){ |
Frame frame = new Frame("Polynomial Calculator"); |
Frame frame = new Frame("Polynomial Calculator"); |
Applet applet; |
//Applet applet; |
|
PolyCalc applet; |
String host = "localhost"; |
String host = "localhost"; |
int DataPort = 1300, ControlPort = 1200; |
int DataPort = 1300, ControlPort = 1200; |
|
|
for(int i=0;i<argv.length;i++){ |
for(int i=0;i<argv.length;i++){ |
if(argv[i].equals("-h")){ |
if(argv[i].equals("-h")){ |
System.out.println(""); |
System.out.print(usage()); |
System.exit(0); |
System.exit(0); |
|
}else if(argv[i].equals("-debug")){ |
|
//debug = true; |
}else if(argv[i].equals("-host")){ |
}else if(argv[i].equals("-host")){ |
host = argv[++i]; |
host = argv[++i]; |
}else if(argv[i].equals("-data")){ |
}else if(argv[i].equals("-data")){ |
Line 126 class PolyCalc extends Applet{ |
|
Line 185 class PolyCalc extends Applet{ |
|
}else if(argv[i].equals("-control")){ |
}else if(argv[i].equals("-control")){ |
ControlPort = Integer.valueOf(argv[++i]).intValue(); |
ControlPort = Integer.valueOf(argv[++i]).intValue(); |
}else{ |
}else{ |
System.err.println("unknown option :"+ argv[i]); |
System.err.println("unknown option : "+ argv[i]); |
|
System.err.println(""); |
|
System.err.print(usage()); |
System.exit(1); |
System.exit(1); |
} |
} |
} |
} |
applet = new PolyCalc(host,ControlPort,DataPort); |
applet = new PolyCalc(host,ControlPort,DataPort); |
|
applet.debug = true; |
|
|
applet.init(); |
applet.init(); |
frame.add("Center",applet); |
frame.add("Center",applet); |