Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Visualisierung extends JFrame {
- private JPanel contentPane;
- private JTextField textField;
- private double ZahlEins;
- private double ZahlZwei;
- private boolean hatZahlEins;
- private boolean hatZahlZwei;
- char Rechenart;
- boolean hatRechenart;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Visualisierung frame = new Visualisierung();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Visualisierung() {
- setTitle("Bujkoffer\u00B4s Rechner");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 400, 314);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- contentPane.setLayout(new BorderLayout(0, 0));
- setContentPane(contentPane);
- JPanel panel = new JPanel();
- contentPane.add(panel, BorderLayout.CENTER);
- panel.setLayout(null);
- JButton btnNewButton_1 = new JButton("2");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(2);
- }
- });
- btnNewButton_1.setBounds(84, 180, 47, 23);
- panel.add(btnNewButton_1);
- JButton btnNewButton = new JButton("8");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(8);
- }
- });
- btnNewButton.setBounds(84, 112, 47, 23);
- panel.add(btnNewButton);
- JButton btnNewButton_2 = new JButton("1");
- btnNewButton_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(1);
- }
- });
- btnNewButton_2.setBounds(26, 180, 48, 23);
- panel.add(btnNewButton_2);
- JButton btnNewButton_3 = new JButton("3");
- btnNewButton_3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(3);
- }
- });
- btnNewButton_3.setBounds(141, 180, 44, 23);
- panel.add(btnNewButton_3);
- JButton btnNewButton_4 = new JButton("6");
- btnNewButton_4.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(6);
- }
- });
- btnNewButton_4.setBounds(141, 146, 44, 23);
- panel.add(btnNewButton_4);
- JButton btnNewButton_5 = new JButton("5");
- btnNewButton_5.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(5);
- }
- });
- btnNewButton_5.setBounds(84, 146, 47, 23);
- panel.add(btnNewButton_5);
- JButton btnNewButton_6 = new JButton("9");
- btnNewButton_6.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(9);
- }
- });
- btnNewButton_6.setBounds(141, 112, 44, 23);
- panel.add(btnNewButton_6);
- JButton btnNewButton_7 = new JButton("4");
- btnNewButton_7.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(4);
- }
- });
- btnNewButton_7.setBounds(26, 146, 48, 23);
- panel.add(btnNewButton_7);
- JButton btnNewButton_8 = new JButton("0");
- btnNewButton_8.setBounds(26, 220, 159, 23);
- panel.add(btnNewButton_8);
- JButton btnNewButton_9 = new JButton("7");
- btnNewButton_9.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- eingabeZahl(7);
- }
- });
- btnNewButton_9.setBounds(26, 112, 48, 23);
- panel.add(btnNewButton_9);
- JButton btnNewButton_10 = new JButton("/");
- btnNewButton_10.setBounds(214, 220, 51, 23);
- panel.add(btnNewButton_10);
- JButton btnNewButton_11 = new JButton("*");
- btnNewButton_11.setBounds(214, 180, 51, 23);
- panel.add(btnNewButton_11);
- JButton btnNewButton_12 = new JButton("-");
- btnNewButton_12.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnNewButton_12.setBounds(214, 146, 51, 23);
- panel.add(btnNewButton_12);
- JButton button = new JButton("+");
- button.setBounds(214, 112, 51, 23);
- panel.add(button);
- JButton button_1 = new JButton("=");
- button_1.setBounds(275, 220, 89, 23);
- panel.add(button_1);
- textField = new JTextField();
- textField.setBounds(100, 26, 172, 53);
- panel.add(textField);
- textField.setColumns(10);
- }
- public void eingabeRechenart (char rechenart) {
- if(!hatRechenart) {
- Rechenart = rechenart;
- }
- }
- public void eingabeZahl (double zahl) {
- if(!hatZahlEins) {
- ZahlEins = zahl;
- hatZahlEins = true;
- } else if(!hatZahlZwei) {
- ZahlZwei = zahl;
- hatZahlZwei = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement