Advertisement
Guest User

11

a guest
Apr 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package Swing2;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8.  
  9.  
  10. public class Okno_11 extends JFrame{
  11.  
  12.     JTextField pole1 = new JTextField(3);
  13.     JTextField pole2 = new JTextField(3);
  14.     JTextField pole3 = new JTextField(5);
  15.  
  16.     private final String dzail[] = {"+","-","*","/"};
  17.     final DefaultComboBoxModel model = new DefaultComboBoxModel(dzail);
  18.     JComboBox lista = new JComboBox(model);
  19.  
  20.     JButton b = new JButton("Oblicz!");
  21.  
  22.  
  23.     public Okno_11 (){
  24.         super("Zad 11");
  25.  
  26.         setLayout(new FlowLayout());
  27.  
  28.         add(pole1);
  29.         add(lista);
  30.         add(pole2);
  31.         add(b);
  32.         add(pole3);
  33.  
  34.         pole3.setEditable(false);
  35.  
  36.         Nasluch n = new Nasluch();
  37.  
  38.         b.addActionListener(n);
  39.         setSize(500,300);
  40.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  41.         setVisible(true);
  42.  
  43.     }
  44.  
  45.     class Nasluch implements ActionListener {
  46.  
  47.         public void actionPerformed(ActionEvent e){
  48.             String a = pole1.getText();
  49.             String b = pole2.getText();
  50.             String c = (String)lista.getSelectedItem();
  51.  
  52.             if (c == "-")
  53.                 pole3.setText((Integer.parseInt(a) - Integer.parseInt(b)) + " ");
  54.             else if (c == "+")
  55.                 pole3.setText((Integer.parseInt(a) + Integer.parseInt(b)) + " ");
  56.             else if (c == "*")
  57.                 pole3.setText((Integer.parseInt(a) * Integer.parseInt(b)) + " ");
  58.             else if (c == "/")
  59.                 pole3.setText((Integer.parseInt(a) / Integer.parseInt(b)) + " ");
  60.  
  61.         }
  62.  
  63.     }
  64.  
  65.     public static void main (String args[]){
  66.         new Okno_11();
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement