Facebook
From Synaj, 4 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 215
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. public class Kalkulator extends JFrame implements ActionListener {
  7.  
  8.     public Kalkulator() {
  9.         // frame
  10.         super("Kalkulator liczb zespolonych");
  11.         setSize(500, 500);
  12.         setLayout(new GridLayout(6, 1));
  13.         setVisible(true);
  14.         //input
  15.         JLabel plus = new JLabel("+");
  16.         plus.setHorizontalAlignment(JLabel.CENTER);
  17.         JLabel i = new JLabel("i");
  18.         i.setHorizontalAlignment(JLabel.CENTER);
  19.         JPanel input = new JPanel();
  20.         input.setLayout(new GridLayout(1, 4));
  21.         JTextField real = new JTextField();
  22.         JTextField imaginary = new JTextField();
  23.         input.add(real);
  24.         input.add(plus);
  25.         input.add(imaginary);
  26.         input.add(i);
  27.         add(input);
  28.         //space
  29.         JPanel space = new JPanel();
  30.         JLabel nothing = new JLabel(" ");
  31.         add(space);
  32.         //operations
  33.         JPanel operations1 = new JPanel();
  34.         operations1.setLayout(new GridLayout(1, 4));
  35.         JButton add = new JButton("+");
  36.         operations1.add(add);
  37.         JButton substract = new JButton("-");
  38.         operations1.add(substract);
  39.         JButton multiply = new JButton("*");
  40.         operations1.add(multiply);
  41.         JButton divide = new JButton("/");
  42.         operations1.add(divide);
  43.         add(operations1);
  44.         JPanel operations2 = new JPanel();
  45.         operations2.setLayout(new GridLayout(1, 4));
  46.         JButton arg = new JButton("ARG");
  47.         operations2.add(arg);
  48.         JButton module = new JButton("MOD");
  49.         operations2.add(module);
  50.         JButton exponentialForm = new JButton("PW");
  51.         operations2.add(exponentialForm);
  52.         JButton trigonometricForm = new JButton("PT");
  53.         operations2.add(trigonometricForm);
  54.         add(operations2);
  55.         JPanel calculate = new JPanel();
  56.         JButton calculateButton = new JButton("OBLICZ");
  57.         calculate.add(calculateButton);
  58.         add(space);
  59.         add(calculate);
  60.         JPanel result = new JPanel();
  61.         JLabel res = new JLabel("Wynik: ");
  62.         result.add(res);
  63.         JTextField resValue = new JTextField();
  64.         resValue.setEditable(false);
  65.         result.add(resValue);
  66.         add(result);
  67.  
  68.     }
  69.  
  70.     @Override
  71.     public void actionPerformed(ActionEvent e){
  72.  
  73.     }
  74.  
  75.     public static void main(String[] args) {
  76.         EventQueue.invokeLater(new Runnable() {
  77.             @Override
  78.             public void run() {
  79.                 new Kalkulator();
  80.             }
  81.         });
  82.     }
  83. }