* 沒有實做 ActionListener 的抽象方法 public void actionPerformed(ActionEvent e)
* 然後 JTextArea並沒有 JTextArea(int) 這個建構子
* public void windowClosing(WindowEvent e) { System.exit(0); } 跟 
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 的意義可以說是一樣 留一種就好了
* 還有就是....縮排阿!! 

 (如果用[TAB]鍵可能會被吃掉 請用3~4個空白來替代)
參考看看
複製程式
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//拿掉沒用到的 import
public class NewSun extends JFrame implements ActionListener {
    //static String datamem[] = new String[10]; //沒用到
    JLabel lb1, lb2, lb3;
    JButton bt1, bt2;
    JTextField tx1, tx2, tx3, tx4; // tx4 由 JTextArea 改為 JTextField
    //static int i = 1; //沒用到
    public NewSun() {
        setLayout(null);
        lb1 = new JLabel("簡易計算機");
        lb1.setForeground(Color.red);
        lb1.setSize(240, 40);
        lb1.setLocation(10, 20);
        add(lb1);
        lb2 = new JLabel("輸入數字:");
        lb2.setForeground(Color.black);
        lb2.setSize(240, 40);
        lb2.setLocation(10, 95);
        add(lb2);
        lb3 = new JLabel("=");
        lb3.setForeground(Color.black);
        lb3.setSize(240, 40);
        lb3.setLocation(435, 95);
        add(lb3);
        tx1 = new JTextField(10);
        tx1.setForeground(Color.red);
        tx1.setSize(100, 30);
        tx1.setLocation(75, 100);
        add(tx1);
        tx2 = new JTextField(10);
        tx2.setForeground(Color.blue);
        tx2.setSize(100, 30);
        tx2.setLocation(200, 100);
        add(tx2);
        tx3 = new JTextField(10);
        tx3.setForeground(Color.red);
        tx3.setSize(100, 30);
        tx3.setLocation(325, 100);
        add(tx3);
        tx4 = new JTextField(15); //由 JTextArea 改為 JTextField
        tx4.setForeground(Color.blue);
        tx4.setSize(100, 30);
        tx4.setLocation(450, 100);
        add(tx4);
        bt1 = new JButton("計算");
        bt1.setSize(100, 30);
        bt1.setLocation(135, 200);
        //bt1.setBorderPainted(true); //預設就是這個狀態了
        //bt1.setEnabled(true); //預設就是這個狀態了
        add(bt1);
        bt2 = new JButton("離開");
        bt2.setSize(100, 30);
        bt2.setLocation(380, 200);
        //bt1.setBorderPainted(true); //預設就是這個狀態了
        //bt1.setEnabled(true); //預設就是這個狀態了
        add(bt2);
        bt1.addActionListener(this);
        bt2.addActionListener(this);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(600, 300);
        setVisible(true);
    }
    /*public void setBackground(Color c) {
    getContentPane().setBackground(c);
    }// 沒用到*/
    /**
     * 實作 ActionListener 比需要複寫的抽象方法
     * 元件對this註冊要處理action事件後
     * 執行期間一旦元件被action就會呼叫這個副程式起來執行
     * 參數:e是整個action事件的內容, 當中包含一些觸發這個事件的資訊
     *     像是"哪個元件觸發這事件"之類的
     */
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(bt1)) { //從事件包中的"來源"判斷該做得事
            double src1 = Double.parseDouble(tx1.getText()),
                    src2 = Double.parseDouble(tx3.getText());
            if (tx2.getText().equals("+")) {
                tx4.setText(String.valueOf(src1 + src2));
            } else if (tx2.getText().equals("-")) {
                tx4.setText(String.valueOf(src1 - src2));
            } else if (tx2.getText().equals("*")) {
                tx4.setText(String.valueOf(src1 * src2));
            } else if (tx2.getText().equals("/")) {
                tx4.setText(String.valueOf(src1 / src2));
            }
        } else if (e.getSource().equals(bt2)) {
            System.exit(0);
        }
    }
    public static void main(String[] args) {
        NewSun sun = new NewSun();
        /*sun.addWindowListener(
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            }
         );// 跟 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) 功能重複*/
    }
}