Report#6(Java)
��.����������������������(GUIaa)��������������������������������
��.����������������������������
��.����������������������������������GUI����������������������������������������
��.����������������������������������������������������������������������
��.��������������������������������������������
������
����������������������(GUIaa)��������������������������������
��GUIaa.java��������������
import java.awt.*;
import java.awt.event.*; // GUI������������������������������������
public class GUIaa extends Frame { // Frame������������
Button b0 = new Button("Even/Odd?"); //GUI������Button��������������
Label x0 = new Label("Type a number and press..."); //GUI������Label��������������
TextField t0 = new TextField(); //GUI������TextField��������������
public GUIaa() { //������������������������������������
setLayout(null); //��������������������0FF��������
add(t0); t0.setBounds(10, 40, 90, 30); // ��������������������������x/y����������������
add(b0); b0.setBounds(110, 40, 80, 30); // ����������������
add(x0); x0.setBounds(10, 80, 180, 30); // ����������������
b0.addActionListener(new ActionListener() { //��������������������
public void actionPerformed(ActionEvent evt) {
int i = (new Integer(t0.getText())).intValue(); //TextField����������������
t0.setText(""); //TextField��������
if(i % 2 == 0) { //i��2��������������(��������)
x0.setText(i + " is Even"); //Label��2is Even"������
} else { //��������������(��������)
x0.setText(i + " is Odd"); //Label��Odd������
}
}
});
}
public static void main(String[] args) { //main��������������
Frame win = new GUIaa(); //��������������������������win��������������
win.setSize(200, 150); win.setVisible(true); //��������������������������������
win.addWindowListener(new WindowAdapter() { //��������������������
public void windowClosing(WindowEvent evt) { //��������������������������������
System.exit(0); //������������������
}
});
}
}
|
������������
����������������
|
����������
|
����������
|
GUI��������������
Graphical User Interface ����������������������������������������������������������
��������������
����������������������������������������������������������������������������������������
����������������
GUI��������������������������������������������������������
��������������������������������������������������������������������������������������������
����������������������������������������������������������������������������
����GUIaa����������������Button��Label��TextField����������������
GUI�������������������������������� java������������������������������������������������
��������Checkbox��List��Menu����������GUI������������
GUI������������������
����������
| Frame
|
��������������������
| Dialog
|
������
| Button
|
����������������
| CheckBox
|
��������������������
| TextField
|
��������������������
| TextArea
|
��������������
| Scrollbar
|
������������
| MenuBar
|
��������������
| List
|
������
| Label
|
��������
| Choice
|
������
| Scrollpanel
|
Panel
|
Canvas
|
��������������������
| PupupMenu
|
��2��
����������������������������
������������
��������
����������������������������������������������������������������
������������������������������������������������������������������������
����������������������������
����������������������������������������������������������������������
�������������������������������� ��
class test {
public static void main(String args[]) {
System.out.println(10 / 0);
}
}
|
���������� ��
[Daigo-WAKATSU:~/sites/java/Repo_6] j03064% javac test.java
[Daigo-WAKATSU:~/sites/java/Repo_6] j03064% java test
Exception in thread "main" java.lang.ArithmeticException: / by zero
at test.main(test.java:3)
|
0��������������������������������������������������
java.lang.ArithmeticException����������������������������
������������������������������������������������������������
������������������������������������������������������������������������������������������
��������������������������������������������������������������������������
����������������������������������������������������������������������������������������
������������try��������������������������������������������
try {
statements...;
}
try��������������������������������������������������������
����������������������������������������catch��������������������
catch����������try��������������������������������������
catch (ErrType1 param) {
statements...;
}
catch����������������������������������������������
ErrType����������������������������������
param������������������������������������
��������������������������������������������������catch������������������������
����������������catch����������������������try��������������
������finally����������������������������������������������
finally����������������������������������������������
finally {
statements...;
}
��try��������������������������catch����������finally��������������������������������������������
(��������������������������������������������������)
������������������������������������
class test2 {
public static void main(String args[]) {
try {
System.out.println(10 / 0);
}
catch (ArithmeticException err) {
System.out.println("������ :" + err);
}
finally {
System.out.println("������");
}
}
}
|
���������� ��
[nw0364:~/sites/java/Repo_6] j03064% java test2
������ :java.lang.ArithmeticException: / by zero
������
|
������������catch��������������������������finally��������������������������
������������������������������
try
����������������������������������������������
try��������������������catch������finally��������������������������
catch����������������������������������������������������������������
��������������
catch
��������������������������������������������������������������������
����������������������������������������������������������������
finally
try������catch������������������finally����������������
finally��������������try����������������������������������������������
������������������catch����������������catch������������finally������
��������
��������������������������finally��������
��3��
����������������������������������GUI����������������������������������������
��GUI����������������
��������������������������
import java.awt.*;
import java.awt.event.*; // GUI������������������������������������
public class Circle extends Frame { // Frame������������
static double total;
Button b0 = new Button("Calculate"); //GUI������Button��������������
Label x0 = new Label("_/_/_/Size of area circle & Circumferential length of circle_/_/_/");
Label x1 = new Label("(Type a number and choice and press...)");
Label x2 = new Label("Input Radius length R="); //GUI������Label��������������
Label x3 = new Label("Answer");
Label x4 = new Label(" ");
Label x5 = new Label(" ");
Choice c0 = new Choice(); //GUI������Choice��������������
TextField t0 = new TextField(); //GUI������TextField��������������
TextField t1 = new TextField();
public Circle() { //������������������������������������
setLayout(null); //��������������������0FF��������
add(t0); t0.setBounds(200, 150, 90, 30); //��������������������������x/y����������������
add(t1); t1.setBounds(200, 230, 90, 30);
add(b0); b0.setBounds(110, 190, 100, 30); //����������������
add(c0); c0.setBounds(30, 100, 200, 30); //������������������
c0.add("Size of area circle"); c0.add("Circumferential lentgh");
add(x0); x0.setBounds(10, 40, 400, 30); //����������������
add(x1); x1.setBounds(65, 70, 180, 30);
add(x2); x2.setBounds(30, 150, 180, 30);
add(x3); x3.setBounds(60, 230, 180, 30);
add(x4); x4.setBounds(160, 230, 180, 30);
add(x5); x5.setBounds(125, 270, 180, 30);
b0.addActionListener(new ActionListener() { //��������������������
public void actionPerformed(ActionEvent e) {
int a = c0.getSelectedIndex();
try{
int i = new
Integer(t0.getText()).intValue();
if (a == 0){
total = i*i*3.14; //������������������������
x4.setText("S="); //������ x4 ��S=��������
} else {
total = 2*3.14*i;
x4.setText("L="); //������ x4 ��S=��������
}
t1.setText(total+""); //������ t1 ��total������������
} catch(Exception ex) { //����������
x5.setText("InputError!"); } //������ t1 ��InputError!��������
}
});
}
public static void main(String[] args) { //main��������������
Frame win = new Circle(); //��������������������������win��������������
win.setSize(420, 310); win.setVisible(true); //��������������������������������
win.addWindowListener(new WindowAdapter() { //��������������������
public void windowClosing(WindowEvent evt) { //��������������������������������
System.exit(0); //������������������
}
});
}
}
|
������������
����������������
|
��������������������
|
����������������������
|
����������
��������������������
|
��������������������
|
��4��
��������������������������������������������������������������������
����������������������
import java.awt.*;
import java.awt.event.*;// GUI������������������������������������
public class Temp1 extends Frame { // Frame������������
static int total;
Button b0 = new Button("Calculate"); //GUI������Button��������������
Label x0 = new Label("Changing machine"),
x1 = new Label("(before)"), //GUI������Label��������������
x2 = new Label("(after)"),
x3 = new Label("");
TextField t0 = new TextField(), //GUI������TextField��������������
t1 = new TextField();
Choice c0 = new Choice(); //GUI������Choice��������������
public Temp1() { //������������������������������������
setLayout(null); //��������������������0FF��������
add(t0); t0.setBounds(10, 130, 90, 30); //��������������������������x/y����������������
add(t1); t1.setBounds(210, 130, 90, 30);
add(c0); c0.setBounds(35, 70, 125, 30); //������������������
c0.add("Sesshi >>> Kashi"); c0.add("Kashi >>> Sesshi");
add(b0); b0.setBounds(105, 130, 100, 30); //����������������
add(x0); x0.setBounds(10, 40, 180, 30); //����������������
add(x1); x1.setBounds(10, 110, 80, 30);
add(x2); x2.setBounds(210, 110, 80,30);
add(x3); x3.setBounds(10, 170, 130, 30);
b0.addActionListener(new ActionListener() { //��������������������
public void actionPerformed(ActionEvent e) {
int a = c0.getSelectedIndex();
try {
int i = new
Integer(t0.getText()).intValue();
if (a == 0) {
total = i*9/5+32; //����������������i*1.8+32��������
x3.setText("");
} else {
total = (i-32)*5/9; //����������������(i-32)/1.8��������
x3.setText("");
}
t1.setText(total+"");//��������total������������
} catch(Exception ex) {//����������
x3.setText("InputError!"); } //������x3�� InputError!��������
}
});
}
public static void main(String[] args) { //main����������
Frame win = new Temp1(); //������������������������win����������������
win.setSize(340, 250); //����������������������������������
win.setVisible(true);
win.addWindowListener(new WindowAdapter() { //��������������������
public void windowClosing(WindowEvent evt) {//������������������������������
System.exit(0); //������������������
}
});
}
}
|
������������
����������������
|
����������������������
|
����������������������
|
������������������������������������������������������������������
��5��
������������������������������������������������������
��Calculate.java��������������
import java.awt.*;
import java.awt.event.*; // GUI������������������������������������
public class Calculate extends Frame { //Frame������������
Button b0 = new Button("a+b"); //GUI������Button��������������
Button b1 = new Button("a-b");
Button b2 = new Button("a/b");
Button b3 = new Button("a*b");
Button b5 = new Button("AC");
Label x0 = new Label(""); //GUI������Label��������������
Label x1 = new Label("_/_/_/_/_/ Calculating Machine _/_/_/_/_/");
Label x2 = new Label("");
Label x3 = new Label("( a )");
Label x4 = new Label("( b )");
TextField t0 = new TextField(); //GUI������TextField��������������
TextField t1 = new TextField();
TextField t2 = new TextField();
public Calculate() { //������������������������������������
setLayout(null); //����������������
add(t0); t0.setBounds(30, 90, 100, 30); //TextField����������
add(t1); t1.setBounds(165, 90, 100, 30);
add(t2); t2.setBounds(70, 205, 200, 30);
add(b0); b0.setBounds(75, 135, 60, 30); //����������������
add(b1); b1.setBounds(150, 135, 60, 30);
add(b2); b2.setBounds(150, 170, 60, 30);
add(b3); b3.setBounds(75, 170, 60, 30);
add(b5); b5.setBounds(110, 250, 80, 30);
add(x0); x0.setBounds(10, 205, 90, 50); //����������������
add(x1); x1.setBounds(10, 40, 200, 30);
add(x2); x2.setBounds(30, 253, 200, 30);
add(x3); x3.setBounds(60, 70, 90, 50);
add(x4); x4.setBounds(190, 70, 90, 50);
b0.addActionListener(new ActionListener() { //Button+��������������������������
public void actionPerformed(ActionEvent evt) {
try {
int i = (new
Integer(t0.getText())).intValue();
int j = (new
Integer(t1.getText())).intValue();
x0.setText("Result");
t2.setText("" + (i+j) + "");
}catch(NumberFormatException ne) { //��������������������������������
x0.setText("Error");
}
}
});
b1.addActionListener(new ActionListener() { //-��������������������������
public void actionPerformed(ActionEvent evt) {
try {
int i = (new
Integer(t0.getText())).intValue();
int j = (new
Integer(t1.getText())).intValue();
x0.setText("Result");
t2.setText("" + (i-j) + "");
}catch(NumberFormatException ne) { //��������������������������������
x0.setText("Error");
}
}
});
b2.addActionListener(new ActionListener() { //-��������������������������
public void actionPerformed(ActionEvent evt) {
try { //��������
int i = (new
Integer(t0.getText())).intValue();
int j = (new
Integer(t1.getText())).intValue();
x0.setText("Relult");
t2.setText("" + i/j + "");
}catch(NumberFormatException ne) { //��������������������������������
x0.setText("Error");
}
}
});
b3.addActionListener(new ActionListener() { //*��������������������������
public void actionPerformed(ActionEvent evt) {
try { //��������
int i = (new
Integer(t0.getText())).intValue();
int j = (new
Integer(t1.getText())).intValue();
x0.setText("Result");
t2.setText("" + i*j + "");
}catch(NumberFormatException ne){ //��������������������������������
x0.setText("Error");
}
}
});
b5.addActionListener(new ActionListener() { //AC��������������������������
public void actionPerformed(ActionEvent evt) {
x2.setText("ALL CLAER");
t0.setText("");
t1.setText("");
t2.setText("");
}
});
}
public static void main(String[] args) { //main��������
Frame win = new Calculate(); //������������������������
win.setSize(300, 300); win.setVisible(true); //����������
win.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { //������������������������������������
System.exit(0);
}
});
}
}
|
������������
����������������
|
��123*321������
|
��123-321������
|
������������������������
|
��AC(ALL CREAR)
|
��������
����������������GUI��������������������������������������...������������
��������������������������������������
��������������������������������������...��������Java��������������������������������
������������URL��
��������������Java ��������������������
(http://msugai.fc2web.com/java/#objective)
��JAVA��������
(http://black.sakura.ne.jp/~third/programming/java/java.html)
��Java����
(http://www5c.biglobe.ne.jp/~ecb/java/java00.html)