Advertisement
Bujkoffer

Untitled

Jan 12th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.41 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JTextField;
  8. import javax.swing.JButton;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.Color;
  12.  
  13.  
  14. public class Visualisierung extends JFrame {
  15.  
  16.     private JPanel contentPane;
  17.     private JTextField textField;
  18.    
  19.     private double ZahlEins;
  20.     private double ZahlZwei;
  21.    
  22.     private boolean hatZahlEins;
  23.     private boolean hatZahlZwei;
  24.    
  25.     char Rechenart;
  26.     boolean hatRechenart;
  27.    
  28.  
  29.     /**
  30.      * Launch the application.
  31.      */
  32.     public static void main(String[] args) {
  33.         EventQueue.invokeLater(new Runnable() {
  34.             public void run() {
  35.                 try {
  36.                     Visualisierung frame = new Visualisierung();
  37.                     frame.setVisible(true);
  38.                 } catch (Exception e) {
  39.                     e.printStackTrace();
  40.                 }
  41.             }
  42.         });
  43.     }
  44.  
  45.     /**
  46.      * Create the frame.
  47.      */
  48.     public Visualisierung() {
  49.         setBackground(Color.YELLOW);
  50.         setTitle("Bujkoffer\u00B4s Rechner");
  51.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52.         setBounds(100, 100, 400, 314);
  53.         contentPane = new JPanel();
  54.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  55.         contentPane.setLayout(new BorderLayout(0, 0));
  56.         setContentPane(contentPane);
  57.        
  58.         JPanel panel = new JPanel();
  59.         panel.setBackground(Color.YELLOW);
  60.         contentPane.add(panel, BorderLayout.CENTER);
  61.        
  62.         JButton btnNewButton_1 = new JButton("2");
  63.         btnNewButton_1.setBounds(84, 180, 47, 23);
  64.         btnNewButton_1.addActionListener(new ActionListener() {
  65.             public void actionPerformed(ActionEvent arg0) {
  66.                 eingabeZahl(2);
  67.             }
  68.         });
  69.         panel.setLayout(null);
  70.         panel.add(btnNewButton_1);
  71.        
  72.         JButton btnNewButton = new JButton("8");
  73.         btnNewButton.setBounds(84, 112, 47, 23);
  74.         btnNewButton.addActionListener(new ActionListener() {
  75.             public void actionPerformed(ActionEvent arg0) {
  76.                 eingabeZahl(8);
  77.             }
  78.         });
  79.         panel.add(btnNewButton);
  80.        
  81.         JButton btnNewButton_2 = new JButton("1");
  82.         btnNewButton_2.setBounds(26, 180, 48, 23);
  83.         btnNewButton_2.addActionListener(new ActionListener() {
  84.             public void actionPerformed(ActionEvent arg0) {
  85.                 eingabeZahl(1);
  86.             }
  87.         });
  88.         panel.add(btnNewButton_2);
  89.        
  90.         JButton btnNewButton_3 = new JButton("3");
  91.         btnNewButton_3.setBounds(141, 180, 44, 23);
  92.         btnNewButton_3.addActionListener(new ActionListener() {
  93.             public void actionPerformed(ActionEvent arg0) {
  94.                 eingabeZahl(3);
  95.             }
  96.         });
  97.         panel.add(btnNewButton_3);
  98.        
  99.        
  100.         JButton btnNewButton_4 = new JButton("6");
  101.         btnNewButton_4.setBounds(141, 146, 44, 23);
  102.         btnNewButton_4.addActionListener(new ActionListener() {
  103.             public void actionPerformed(ActionEvent arg0) {
  104.                 eingabeZahl(6);
  105.             }
  106.         });
  107.         panel.add(btnNewButton_4);
  108.        
  109.         JButton btnNewButton_5 = new JButton("5");
  110.         btnNewButton_5.setBounds(84, 146, 47, 23);
  111.         btnNewButton_5.addActionListener(new ActionListener() {
  112.             public void actionPerformed(ActionEvent arg0) {
  113.                 eingabeZahl(5);
  114.             }
  115.         });
  116.         panel.add(btnNewButton_5);
  117.        
  118.         JButton btnNewButton_6 = new JButton("9");
  119.         btnNewButton_6.setBounds(141, 112, 44, 23);
  120.         btnNewButton_6.addActionListener(new ActionListener() {
  121.             public void actionPerformed(ActionEvent arg0) {
  122.                 eingabeZahl(9);
  123.             }
  124.         });
  125.         panel.add(btnNewButton_6);
  126.        
  127.         JButton btnNewButton_7 = new JButton("4");
  128.         btnNewButton_7.setBounds(26, 146, 48, 23);
  129.         btnNewButton_7.addActionListener(new ActionListener() {
  130.             public void actionPerformed(ActionEvent arg0) {
  131.                 eingabeZahl(4);
  132.             }
  133.            
  134.         });
  135.         panel.add(btnNewButton_7);
  136.        
  137.         JButton btnNewButton_8 = new JButton("0");
  138.         btnNewButton_8.setBounds(26, 220, 159, 23);
  139.         panel.add(btnNewButton_8);
  140.        
  141.         JButton btnNewButton_9 = new JButton("7");
  142.         btnNewButton_9.setBounds(26, 112, 48, 23);
  143.         btnNewButton_9.addActionListener(new ActionListener() {
  144.             public void actionPerformed(ActionEvent arg0) {
  145.                 eingabeZahl(7);
  146.             }
  147.         });
  148.         panel.add(btnNewButton_9);
  149.        
  150.         JButton btnNewButton_10 = new JButton("/");
  151.         btnNewButton_10.setBounds(214, 220, 51, 23);
  152.         panel.add(btnNewButton_10);
  153.        
  154.         JButton btnNewButton_11 = new JButton("*");
  155.         btnNewButton_11.setBounds(214, 180, 51, 23);
  156.         panel.add(btnNewButton_11);
  157.        
  158.         JButton btnNewButton_12 = new JButton("-");
  159.         btnNewButton_12.setBounds(214, 146, 51, 23);
  160.         btnNewButton_12.addActionListener(new ActionListener() {
  161.             public void actionPerformed(ActionEvent arg0) {
  162.             }
  163.         });
  164.         panel.add(btnNewButton_12);
  165.        
  166.         JButton button = new JButton("+");
  167.         button.setBounds(214, 112, 51, 23);
  168.         panel.add(button);
  169.        
  170.         JButton button_1 = new JButton("=");
  171.         button_1.setBounds(275, 220, 89, 23);
  172.         button_1.addActionListener(new ActionListener() {
  173.             public void actionPerformed(ActionEvent arg0) {
  174.             }
  175.         });
  176.         panel.add(button_1);
  177.        
  178.         textField = new JTextField();
  179.         textField.setBounds(100, 26, 172, 53);
  180.         panel.add(textField);
  181.         textField.setColumns(10);
  182.     }
  183.    
  184.     public void eingabeRechenart (char rechenart) {
  185.         if(!hatRechenart) {
  186.             Rechenart = rechenart;
  187.             aktualisiereText();
  188.             }
  189.     }
  190.    
  191.     public void eingabeZahl (double zahl) {
  192.        
  193.         if(!hatZahlEins) {
  194.             ZahlEins = zahl;
  195.             hatZahlEins = true;
  196.         } else if(!hatZahlZwei) {
  197.             ZahlZwei = zahl;
  198.             hatZahlZwei = true;
  199.         }
  200.        
  201.          aktualisiereText();
  202.     }
  203.     public void aktualisiereText(){
  204.        
  205.         String text = "";
  206.         textField.setText("Tobias");
  207.         if (hatZahleins) {
  208.             text += ZahlEins;
  209.            
  210.         }
  211.     }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement