001:// コマンドラインの数値の四則演算
002:
003:import java.awt.* ;
004:import javax.swing.* ;
005:
006:public class Compute2 {
007:
008:    public static void main(String[] args) {
009:
010:        JFrame frame = new JFrame("2数の計算");           // ウィンドウの作成
011:        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
012:        Container pane = frame.getContentPane();
013:        pane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
014:
015:        int arg1 = 0;                                      // コマンドラインの読込み
016:        if(args.length>0) arg1 = Integer.parseInt(args[0]);
017:        int arg2 = 0;
018:        if(args.length>1) arg2 = Integer.parseInt(args[1]);
019:
020:        pane.add(new JLabel("和:"+ (arg1+arg2)));         // 計算と編集
021:        pane.add(new JLabel("差:"+ (arg1-arg2)));
022:        pane.add(new JLabel("積:"+ (arg1*arg2)));
023:        if(arg2 == 0) pane.add(new JLabel("商:−"));
024:        else          pane.add(new JLabel("商:"+ (arg1/arg2)));
025:
026:        frame.pack();                                      // ウィンドウの表示
027:        frame.setVisible(true);
028:    }
029:}