
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;

class Opgave11_4Oplossing extends JFrame implements ActionListener {

    private JButton add, clear;
    private JTextField entry, sum;
    private double totaalbedrag=0.0;

    public static void main(String[] args) {
        Opgave11_4Oplossing frame = new Opgave11_4Oplossing();
        frame.setSize(200,150);
        frame.createGUI();
        frame.show();
    }

    private void createGUI() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container window = getContentPane();
        window.setLayout(new FlowLayout() );

        entry = new JTextField(10);
        window.add(entry);

        add = new JButton("add");
        window.add(add);
        add.addActionListener(this);

        sum = new JTextField("0", 10);
        window.add(sum);

        clear = new JButton("clear");
        window.add(clear );
        clear .addActionListener(this);

    }

    public void actionPerformed(ActionEvent event) {
       //vul hier de code aan
       if (event.getSource()==add) {
       	 totaalbedrag = totaalbedrag + Double.parseDouble(entry.getText());
       }
       if (event.getSource()==clear) {
       	 totaalbedrag = 0.0;
       	 entry.setText("");
       }
       DecimalFormat formatter = new DecimalFormat("##.##");
       sum.setText(formatter.format(totaalbedrag));      
    }
}

