import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
public static void main(String[] args) {
JFrame window = new JFrame(); // Создали окно
window.setBounds(100, 100, 600, 400); // Размеры и положение окна
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // чтобы останавливалось
window.setLayout(null);
JTextField textField1 = new JTextField();
textField1.setBounds(10, 10, 100, 30);
window.add(textField1);
JTextField textField2 = new JTextField();
textField2.setBounds(10, 50, 100, 30);
window.add(textField2);
JLabel label = new JLabel("0");
label.setBounds(10, 90, 100, 30);
window.add(label);
JButton buttonPlus = new JButton("+");
buttonPlus.setBounds(10, 130, 100, 30);
buttonPlus.addActionListener(e -> {
try {
int value1 = Integer.parseInt(textField1.getText());
int value2 = Integer.parseInt(textField2.getText());
label.setText(String.valueOf(value1 + value2));
} catch (Exception exception) {
label.setText("Ошибка!");
}
});
window.add(buttonPlus);
JButton buttonDiv = new JButton("/");
buttonDiv.setBounds(120, 130, 100, 30);
buttonDiv.addActionListener(e -> {
try {
int value1 = Integer.parseInt(textField1.getText());
int value2 = Integer.parseInt(textField2.getText());
label.setText(String.valueOf(value1 / value2));
} catch (ArithmeticException exception) {
label.setText("Ошибка арифметическая");
} catch (Exception exception) {
label.setText("Ошибка!");
}
});
window.add(buttonDiv);
window.setVisible(true); // Показать окно (Обязательно в конце!)
}
}