lee

          專注技術,關心民生.

          BlogJava 聯系 聚合 管理
            2 Posts :: 0 Stories :: 1 Comments :: 0 Trackbacks

          2005年12月17日 #

          import java.awt.*;
          import java.awt.event.*;
          import java.util.*;
          class wenben extends Frame implements TextListener,ActionListener{
           Button butExit = null;
           TextArea text1 = null; //輸入文件域
           TextArea text2 = null;  //結果輸出的文件域
           public wenben(){
            butExit = new Button();
            add(butExit);
            butExit.addActionListener(this);
             setLayout(null);    //設置界面的格式
            setBounds(35,35,280,250);
            butExit.setBounds(50,200,180,20);
            butExit.setLabel("離開");
             text1 = new TextArea(" ",10,10);
             text1.setBounds(40,50,100,100);
              text2 = new TextArea(" ",10,10);
             text2.setBounds(150,50,100,100);
             add(text1);
             text1.addTextListener(this);
              add(text2);
             text2.setEditable(false);
             text2.addTextListener(this);
              setVisible(true);
          }
            public void actionPerformed(ActionEvent e){
             System.exit(-1);
            }
           public void textValueChanged(TextEvent e)
            {
             double averge = 0; //均值
             double result = 0;  // 和
             int i = 0;
             if(e.getSource()==text1)
              {
               String str = text1.getText();
               StringTokenizer detect = new StringTokenizer(str); //stringtokenizer很用的類,對字符的處理功能強大
               int n = detect.countTokens();
               double[] dou = new double[n]; //也可分配一靜態的數組,這樣不用每次分配空間,但是數組的長度的變化缺少靈活性
               for(i = 0;i<n; i++)
               {
                String temp = detect.nextToken();
                dou[i]=Double.valueOf(temp).doubleValue();
                result = result+dou[i];
               }
               text2.setText(""+result+'\n'+(result/i));
               }
            }
            public static void main(String[] args){
             wenben wb = new wenben();
            } 
          }
          posted @ 2005-12-17 01:17 lee 閱讀(226) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 昌邑市| 元谋县| 宁武县| 依兰县| 台中市| 蒲江县| 托克逊县| 石城县| 华宁县| 平南县| 佛坪县| 灵寿县| 乌鲁木齐县| 和政县| 景洪市| 怀化市| 阜阳市| 阳新县| 奉化市| 昌江| 武城县| 准格尔旗| 玛曲县| 信阳市| 平凉市| 湖口县| 西吉县| 曲阜市| 隆子县| 化德县| 太康县| 子长县| 丰镇市| 鹤峰县| 呈贡县| 崇信县| 高雄市| 西贡区| 宜兰县| 梁河县| 沐川县|