Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kolos4_A;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.BorderFactory;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class MainFrame extends JFrame implements Runnable{
- private JPanel panel;
- private JTextField liczba_1, liczba_2;
- private JComboBox<String> akcja = new JComboBox(new String[] {"Plus", "Minus", "Razy"});
- private JLabel wynik;
- private JButton wykonaj;
- public MainFrame(String Tytul) {
- super(Tytul);
- Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
- setSize(new Dimension(dim.width/2, dim.height/2));
- panel = new JPanel();
- panel.setBorder(BorderFactory.createRaisedBevelBorder());
- add(panel, BorderLayout.NORTH);
- liczba_1 = new JTextField(10);
- liczba_2 = new JTextField(10);
- panel.add(liczba_1);
- panel.add(liczba_2);
- panel.add(akcja);
- wykonaj = new JButton("Wykonaj");
- panel.add(wykonaj);
- wynik = new JLabel();
- panel.add(wynik);
- wykonaj.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Double a = Double.parseDouble(get_A());
- Double b = Double.parseDouble(get_B());
- if(get_akcja() == "Plus") {
- Double w = a + b;
- wynik.setText("Wynik: " + w);
- }
- else if(get_akcja() == "Minus") {
- Double w = a - b;
- wynik.setText("Wynik: " + w);
- }
- else {
- Double w = a * b;
- wynik.setText("Wynik: " + w);
- }
- }
- });
- }
- @Override
- public void run() {
- setVisible(true);
- }
- public String get_A() {
- return liczba_1.getText();
- }
- public String get_B() {
- return liczba_2.getText();
- }
- public String get_akcja() {
- return akcja.getSelectedItem().toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement