Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import java.awt.Font;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.border.EmptyBorder;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.Color;
- public class Lcm extends JFrame {
- private static final long serialVersionUID = 1L;
- private JPanel contentPane;
- private JTextField textField;
- private JTextField textField_1;
- private JLabel lblInserisciSecondoNumero;
- private JLabel lblNewLabel_1;
- private JLabel lblNewLabel_2;
- private JLabel lblNewLabel_3;
- private JLabel lblNewLabel_4;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Lcm frame = new Lcm();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Lcm() {
- setTitle("GCD and lcm");
- setForeground(new Color(0, 255, 255));
- setBackground(new Color(0, 0, 0));
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 316, 300);
- contentPane = new JPanel();
- contentPane.setForeground(new Color(0, 255, 255));
- contentPane.setBackground(new Color(0, 0, 0));
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- lblInserisciSecondoNumero = new JLabel("Insert second number");
- lblInserisciSecondoNumero.setForeground(new Color(0, 255, 255));
- lblInserisciSecondoNumero.setBackground(new Color(0, 0, 0));
- lblInserisciSecondoNumero.setFont(new Font("Tahoma", Font.PLAIN, 17));
- lblInserisciSecondoNumero.setEnabled(false);
- lblInserisciSecondoNumero.setBounds(50, 84, 192, 31);
- contentPane.add(lblInserisciSecondoNumero);
- JLabel lblNewLabel = new JLabel("Insert first number");
- lblNewLabel.setForeground(new Color(0, 255, 255));
- lblNewLabel.setBackground(new Color(0, 0, 0));
- lblNewLabel.setEnabled(false);
- lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 17));
- lblNewLabel.setBounds(55, 26, 179, 31);
- contentPane.add(lblNewLabel);
- textField = new JTextField();
- textField.setForeground(new Color(0, 255, 255));
- textField.setBackground(new Color(0, 0, 0));
- textField.setFont(new Font("Tahoma", Font.PLAIN, 20));
- textField.setBounds(42, 25, 200, 31);
- contentPane.add(textField);
- textField.setColumns(10);
- textField_1 = new JTextField();
- textField_1.setForeground(new Color(0, 255, 255));
- textField_1.setBackground(new Color(0, 0, 0));
- textField_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
- textField_1.setColumns(10);
- textField_1.setBounds(42, 83, 200, 31);
- contentPane.add(textField_1);
- JButton btnNewButton = new JButton("Calculate GCD and lcm");
- btnNewButton.setForeground(new Color(0, 255, 255));
- btnNewButton.setBackground(new Color(0, 0, 0));
- btnNewButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- int num = 2;
- int a = Integer.parseInt(textField.getText());
- int b = Integer.parseInt(textField_1.getText());
- while (a % num != 0 | b % num != 0) {
- num++;
- }
- lblNewLabel_1.setText(Integer.toString(num));
- num = 2;
- while (num % a != 0 | num % b != 0) {
- num++;
- }
- lblNewLabel_2.setText(Integer.toString(num));
- }
- });
- btnNewButton.setBounds(60, 126, 163, 43);
- contentPane.add(btnNewButton);
- lblNewLabel_1 = new JLabel("");
- lblNewLabel_1.setForeground(new Color(0, 255, 255));
- lblNewLabel_1.setBackground(new Color(0, 0, 0));
- lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 20));
- lblNewLabel_1.setBounds(97, 164, 101, 59);
- contentPane.add(lblNewLabel_1);
- lblNewLabel_2 = new JLabel("");
- lblNewLabel_2.setForeground(new Color(0, 255, 255));
- lblNewLabel_2.setBackground(new Color(0, 0, 0));
- lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 20));
- lblNewLabel_2.setBounds(97, 232, 101, 19);
- contentPane.add(lblNewLabel_2);
- lblNewLabel_3 = new JLabel("GCD");
- lblNewLabel_3.setForeground(new Color(0, 255, 255));
- lblNewLabel_3.setBackground(new Color(0, 0, 0));
- lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 20));
- lblNewLabel_3.setBounds(10, 157, 53, 72);
- contentPane.add(lblNewLabel_3);
- lblNewLabel_4 = new JLabel("lcm");
- lblNewLabel_4.setForeground(new Color(0, 255, 255));
- lblNewLabel_4.setBackground(new Color(0, 0, 0));
- lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD, 20));
- lblNewLabel_4.setBounds(10, 229, 53, 24);
- contentPane.add(lblNewLabel_4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement