Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Swing2;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Okno_11 extends JFrame{
- JTextField pole1 = new JTextField(3);
- JTextField pole2 = new JTextField(3);
- JTextField pole3 = new JTextField(5);
- private final String dzail[] = {"+","-","*","/"};
- final DefaultComboBoxModel model = new DefaultComboBoxModel(dzail);
- JComboBox lista = new JComboBox(model);
- JButton b = new JButton("Oblicz!");
- public Okno_11 (){
- super("Zad 11");
- setLayout(new FlowLayout());
- add(pole1);
- add(lista);
- add(pole2);
- add(b);
- add(pole3);
- pole3.setEditable(false);
- Nasluch n = new Nasluch();
- b.addActionListener(n);
- setSize(500,300);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- }
- class Nasluch implements ActionListener {
- public void actionPerformed(ActionEvent e){
- String a = pole1.getText();
- String b = pole2.getText();
- String c = (String)lista.getSelectedItem();
- if (c == "-")
- pole3.setText((Integer.parseInt(a) - Integer.parseInt(b)) + " ");
- else if (c == "+")
- pole3.setText((Integer.parseInt(a) + Integer.parseInt(b)) + " ");
- else if (c == "*")
- pole3.setText((Integer.parseInt(a) * Integer.parseInt(b)) + " ");
- else if (c == "/")
- pole3.setText((Integer.parseInt(a) / Integer.parseInt(b)) + " ");
- }
- }
- public static void main (String args[]){
- new Okno_11();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement