Meine Abgabe für das Nachtestat
parent
3717ca0aa4
commit
fb48cbcbca
|
@ -0,0 +1,11 @@
|
|||
package nachtestat;
|
||||
|
||||
public class Fassade {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new GUI();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
package nachtestat;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GUI implements ActionListener{
|
||||
|
||||
|
||||
JFrame jf;
|
||||
JLabel anzeige;
|
||||
JTextArea bildschirm;
|
||||
int numb = 0;
|
||||
String operator = "";
|
||||
|
||||
ArrayList<Integer> memory = new ArrayList<>();
|
||||
|
||||
public GUI(){
|
||||
jf = new JFrame();
|
||||
anzeige = new JLabel();
|
||||
anzeige.setBounds(0, 0, 400, 40);
|
||||
|
||||
bildschirm = new JTextArea();
|
||||
bildschirm.setBounds(0, 0, 380, 38);
|
||||
bildschirm.setVisible(true);
|
||||
anzeige.add(bildschirm);
|
||||
anzeige.setVisible(true);
|
||||
jf.add(anzeige);
|
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
jf.setSize(500, 400);
|
||||
jf.setLocationRelativeTo(null);
|
||||
jf.setVisible(true);
|
||||
|
||||
jf.setLayout(null);
|
||||
|
||||
JButton btnMCR = new JButton("M(CR)");
|
||||
btnMCR.setVisible(true);
|
||||
btnMCR.setSize(60, 40);
|
||||
jf.add(btnMCR);
|
||||
JButton btnMMinus = new JButton("M-");
|
||||
btnMMinus.setVisible(true);
|
||||
//btnMMinus.setSize(60, 40);
|
||||
btnMMinus.setBounds(0, 40, 60, 40);
|
||||
jf.add(btnMMinus);
|
||||
JButton btnMPlus = new JButton("M+");
|
||||
btnMPlus.setVisible(true);
|
||||
btnMPlus.setBounds(0, 80, 60, 40);
|
||||
jf.add(btnMPlus);
|
||||
JButton btnSqrt = new JButton("SQRT");
|
||||
btnSqrt.setVisible(true);
|
||||
btnSqrt.setBounds(0, 120, 60, 40);
|
||||
jf.add(btnSqrt);
|
||||
JButton btnONOFF = new JButton("ON/OFF");
|
||||
btnONOFF.setVisible(true);
|
||||
btnONOFF.setBounds(0, 160, 60, 40);
|
||||
jf.add(btnONOFF);
|
||||
|
||||
JButton btnOne = new JButton("1");
|
||||
btnOne.setBounds(60, 40, 60, 40);
|
||||
btnOne.setVisible(true);
|
||||
|
||||
btnOne.putClientProperty(numb , 1);
|
||||
btnOne.addActionListener(this);
|
||||
jf.add(btnOne);
|
||||
|
||||
JButton btnTwo = new JButton("2");
|
||||
btnTwo.setBounds(60, 80, 60, 40);
|
||||
btnTwo.setVisible(true);
|
||||
|
||||
btnTwo.putClientProperty(numb , 2);
|
||||
btnTwo.addActionListener(this);
|
||||
jf.add(btnTwo);
|
||||
|
||||
|
||||
JButton btnThree = new JButton("3");
|
||||
btnThree.setBounds(60, 120, 60, 40);
|
||||
btnThree.setVisible(true);
|
||||
|
||||
btnThree.putClientProperty(numb, 3);
|
||||
btnThree.addActionListener(this);
|
||||
jf.add(btnThree);
|
||||
|
||||
|
||||
JButton btnfour = new JButton("4");
|
||||
btnfour.setBounds(120, 40, 60, 40);
|
||||
btnfour.setVisible(true);
|
||||
|
||||
btnfour.putClientProperty(numb, 4);
|
||||
btnfour.addActionListener(this);
|
||||
jf.add(btnfour);
|
||||
|
||||
|
||||
JButton btnFive = new JButton("5");
|
||||
btnFive.setBounds(120, 80, 60, 40);
|
||||
btnFive.setVisible(true);
|
||||
|
||||
btnFive.putClientProperty(numb, 5);
|
||||
btnFive.addActionListener(this);
|
||||
jf.add(btnFive);
|
||||
|
||||
JButton btnSix = new JButton("6");
|
||||
btnSix.setBounds(120, 120, 60, 40);
|
||||
btnSix.setVisible(true);
|
||||
|
||||
btnSix.putClientProperty(numb, 6);
|
||||
btnSix.addActionListener(this);
|
||||
jf.add(btnSix);
|
||||
|
||||
JButton btnSeven = new JButton("7");
|
||||
btnSeven.setBounds(180, 40, 60, 40);
|
||||
btnSeven.setVisible(true);
|
||||
|
||||
btnSeven.putClientProperty(numb, 7);
|
||||
btnSeven.addActionListener(this);
|
||||
jf.add(btnSeven);
|
||||
|
||||
JButton btnEight = new JButton("8");
|
||||
btnEight.setBounds(180, 80, 60, 40);
|
||||
btnEight.setVisible(true);
|
||||
|
||||
btnEight.putClientProperty(numb, 8);
|
||||
btnEight.addActionListener(this);
|
||||
jf.add(btnEight);
|
||||
|
||||
|
||||
JButton btnNine = new JButton("9");
|
||||
btnNine.setBounds(180, 120, 60, 40);
|
||||
btnNine.setVisible(true);
|
||||
|
||||
btnNine.putClientProperty(numb, 9);
|
||||
btnNine.addActionListener(this);
|
||||
jf.add(btnNine);
|
||||
|
||||
|
||||
JButton btnPlus = new JButton("+");
|
||||
btnPlus.setBounds(240, 40, 60, 40);
|
||||
btnPlus.setVisible(true);
|
||||
|
||||
btnPlus.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
int a = memory.get(0);
|
||||
int b = memory.get(1);
|
||||
|
||||
addieren(a,b);
|
||||
|
||||
memory.removeAll(memory);
|
||||
}
|
||||
|
||||
});
|
||||
jf.add(btnPlus);
|
||||
|
||||
|
||||
|
||||
|
||||
JButton btnMinus = new JButton("-");
|
||||
btnPlus.setBounds(240, 80, 60, 40);
|
||||
btnPlus.setVisible(true);
|
||||
|
||||
btnPlus.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
int a = memory.get(0);
|
||||
int b = memory.get(1);
|
||||
|
||||
subtrahieren(a,b);
|
||||
|
||||
memory.removeAll(memory);
|
||||
}
|
||||
|
||||
});
|
||||
jf.add(btnPlus);
|
||||
|
||||
}
|
||||
|
||||
public int addieren (int a, int b) {
|
||||
|
||||
System.out.println(a+b);
|
||||
return a +b;
|
||||
}
|
||||
|
||||
public int subtrahieren(int a, int b) {
|
||||
return a -b;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
JButton btn = (JButton) e.getSource();
|
||||
|
||||
bildschirm.add((Component) btn.getClientProperty(numb));
|
||||
|
||||
memory.add((int) btn.getClientProperty(numb));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue