All pastes #941300 Raw Edit

Untitled

public java v1 · immutable
·published 2008-03-13 16:47 UTC
rendered paste body
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package huiswerk3;import java.awt.FlowLayout;import javax.swing.*;import java.awt.event.*;/** * * @author s1001191 */public class Rekenmachine extends JFrame implements ActionListener {        private JPanel paneel;    private JButton knopNul;    private JButton knopEen;    private JButton knopTwee;    private JButton knopDrie;    private JButton knopVier;    private JButton knopVijf;    private JButton knopZes;    private JButton knopZeven;    private JButton knopAcht;    private JButton knopNegen;    private JButton knopPlus;    private JButton knopMin;    private JButton knopDelen;    private JButton knopKeer;    private JButton knopIs;    private JTextField tekstveld;    private JButton knopClear;    private int invoer;    private int uitvoer;    private boolean plus;    private boolean min;    private boolean delen;    private boolean keer;        public Rekenmachine(){                paneel = new JPanel();        tekstveld = new JTextField(15);        knopNul = new JButton("0");        knopEen = new JButton("1");        knopTwee = new JButton("2");        knopDrie = new JButton("3");        knopVier = new JButton("4");        knopVijf = new JButton("5");        knopZes = new JButton("6");        knopZeven = new JButton("7");        knopAcht = new JButton("8");        knopNegen = new JButton("9");        knopPlus = new JButton("+");        knopMin = new JButton("-");        knopDelen = new JButton("/");        knopKeer = new JButton("x");        knopIs = new JButton("=");        knopClear = new JButton("C");                        knopNul.addActionListener(this);        knopEen.addActionListener(this);        knopTwee.addActionListener(this);        knopDrie.addActionListener(this);        knopVier.addActionListener(this);        knopVijf.addActionListener(this);        knopZes.addActionListener(this);        knopZeven.addActionListener(this);        knopAcht.addActionListener(this);        knopNegen.addActionListener(this);        knopPlus.addActionListener(this);        knopMin.addActionListener(this);        knopDelen.addActionListener(this);        knopKeer.addActionListener(this);        knopIs.addActionListener(this);        knopClear.addActionListener(this);                paneel.add(tekstveld);        paneel.add(knopZeven);        paneel.add(knopAcht);        paneel.add(knopNegen);        paneel.add(knopPlus);        paneel.add(knopVier);        paneel.add(knopVijf);        paneel.add(knopZes);        paneel.add(knopMin);        paneel.add(knopEen);        paneel.add(knopTwee);        paneel.add(knopDrie);        paneel.add(knopKeer);        paneel.add(knopNul);        paneel.add(knopDelen);        paneel.add(knopClear);        paneel.add(knopIs);                tekstveld.setEnabled(false);                setContentPane(paneel);        setLayout(new FlowLayout());                boolean plus = false;        boolean min = false;        boolean delen = false;        boolean keer = false;    }        public static void main(String[] args) {        JFrame frame = new Rekenmachine();        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);        frame.setSize( 200, 210 );        frame.setTitle("Rekenmachine van Robin");        frame.setVisible(true);                    }    public void actionPerformed(ActionEvent e) {        String rekentekst = tekstveld.getText();                if (e.getSource() == knopNul){            tekstveld.setText(rekentekst +"0");        }        if (e.getSource() == knopEen){            tekstveld.setText(rekentekst +"1");        }        if (e.getSource() == knopTwee){            tekstveld.setText(rekentekst +"2");        }        if (e.getSource() == knopDrie){            tekstveld.setText(rekentekst +"3");        }        if (e.getSource() == knopVier){            tekstveld.setText(rekentekst +"4");        }        if (e.getSource() == knopVijf){            tekstveld.setText(rekentekst +"5");        }        if (e.getSource() == knopZes){            tekstveld.setText(rekentekst +"6");        }        if (e.getSource() == knopZeven){            tekstveld.setText(rekentekst +"7");        }        if (e.getSource() == knopAcht){            tekstveld.setText(rekentekst +"8");        }        if (e.getSource() == knopNegen){            tekstveld.setText(rekentekst +"9");        }                if (e.getSource() == knopPlus){            invoer = Integer.parseInt(rekentekst);            plus = true;            min = false;            keer = false;            delen = false;            tekstveld.setText("");            rekentekst = "";        }        if (e.getSource() == knopMin){            invoer = Integer.parseInt(rekentekst);            plus = false;            min = true;            keer = false;            delen = false;            tekstveld.setText("");            rekentekst = "";        }        if (e.getSource() == knopKeer){            invoer = Integer.parseInt(rekentekst);            plus = false;            min = false;            keer = true;            delen = false;            tekstveld.setText("");            rekentekst = "";        }        if (e.getSource() == knopDelen){            invoer = Integer.parseInt(rekentekst);            plus = false;            min = false;            keer = false;            delen = true;            tekstveld.setText("");            rekentekst = "";        }                if (e.getSource() == knopIs){            uitvoer = Integer.parseInt(rekentekst);            if (plus == true){                int uitkomst = invoer + uitvoer;                String uitkomsttekst = ""+uitkomst;                tekstveld.setText(uitkomsttekst);            }            if (min == true){                int uitkomst = invoer - uitvoer;                String uitkomsttekst = ""+uitkomst;                tekstveld.setText(uitkomsttekst);            }            if (keer == true){                int uitkomst = invoer * uitvoer;                String uitkomsttekst = ""+uitkomst;                tekstveld.setText(uitkomsttekst);            }            if (delen == true){                int uitkomst = invoer / uitvoer;                String uitkomsttekst = ""+uitkomst;                tekstveld.setText(uitkomsttekst);            }        }        if (e.getSource() == knopClear){            invoer = 0;            uitvoer = 0;            tekstveld.setText("");            rekentekst="";        }    }}