Advertisement
Dar954826

MCD e mcm[ITA].java

Mar 9th, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.58 KB | None | 0 0
  1. import java.awt.EventQueue;
  2. import javax.swing.JFrame;
  3. import javax.swing.JPanel;
  4. import javax.swing.JTextField;
  5. import java.awt.Font;
  6. import javax.swing.JButton;
  7. import javax.swing.JLabel;
  8. import javax.swing.border.EmptyBorder;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.Color;
  12.  
  13. public class Mcm extends JFrame {
  14.     private static final long serialVersionUID = 1L;
  15.     private JPanel contentPane;
  16.     private JTextField textField;
  17.     private JTextField textField_1;
  18.     private JLabel lblInserisciSecondoNumero;
  19.     private JLabel lblNewLabel_1;
  20.     private JLabel lblNewLabel_2;
  21.     private JLabel lblNewLabel_3;
  22.     private JLabel lblNewLabel_4;
  23.  
  24.     public static void main(String[] args) {
  25.         EventQueue.invokeLater(new Runnable() {
  26.             public void run() {
  27.                 try {
  28.                     Mcm frame = new Mcm();
  29.                     frame.setVisible(true);
  30.                 } catch (Exception e) {
  31.                     e.printStackTrace();
  32.                 }
  33.             }
  34.         });
  35.     }
  36.  
  37.     public Mcm() {
  38.         setTitle("MCD e mcm");
  39.         setForeground(new Color(0, 255, 255));
  40.         setBackground(new Color(0, 0, 0));
  41.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42.         setBounds(100, 100, 316, 300);
  43.         contentPane = new JPanel();
  44.         contentPane.setForeground(new Color(0, 255, 255));
  45.         contentPane.setBackground(new Color(0, 0, 0));
  46.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  47.         setContentPane(contentPane);
  48.         contentPane.setLayout(null);
  49.  
  50.         lblInserisciSecondoNumero = new JLabel("Inserisci secondo numero");
  51.         lblInserisciSecondoNumero.setForeground(new Color(0, 255, 255));
  52.         lblInserisciSecondoNumero.setBackground(new Color(0, 0, 0));
  53.         lblInserisciSecondoNumero.setFont(new Font("Tahoma", Font.PLAIN, 17));
  54.         lblInserisciSecondoNumero.setEnabled(false);
  55.         lblInserisciSecondoNumero.setBounds(50, 84, 192, 31);
  56.         contentPane.add(lblInserisciSecondoNumero);
  57.  
  58.         JLabel lblNewLabel = new JLabel("Inserisci primo numero");
  59.         lblNewLabel.setForeground(new Color(0, 255, 255));
  60.         lblNewLabel.setBackground(new Color(0, 0, 0));
  61.         lblNewLabel.setEnabled(false);
  62.         lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 17));
  63.         lblNewLabel.setBounds(55, 26, 179, 31);
  64.         contentPane.add(lblNewLabel);
  65.  
  66.         textField = new JTextField();
  67.         textField.setForeground(new Color(0, 255, 255));
  68.         textField.setBackground(new Color(0, 0, 0));
  69.         textField.setFont(new Font("Tahoma", Font.PLAIN, 20));
  70.         textField.setBounds(42, 25, 200, 31);
  71.         contentPane.add(textField);
  72.         textField.setColumns(10);
  73.  
  74.         textField_1 = new JTextField();
  75.         textField_1.setForeground(new Color(0, 255, 255));
  76.         textField_1.setBackground(new Color(0, 0, 0));
  77.         textField_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
  78.         textField_1.setColumns(10);
  79.         textField_1.setBounds(42, 83, 200, 31);
  80.         contentPane.add(textField_1);
  81.  
  82.         JButton btnNewButton = new JButton("Calcola MCD e mcm");
  83.         btnNewButton.setForeground(new Color(0, 255, 255));
  84.         btnNewButton.setBackground(new Color(0, 0, 0));
  85.         btnNewButton.addMouseListener(new MouseAdapter() {
  86.             @Override
  87.             public void mouseClicked(MouseEvent arg0) {
  88.                 int num = 2;
  89.                 int a = Integer.parseInt(textField.getText());
  90.                 int b = Integer.parseInt(textField_1.getText());
  91.  
  92.                 while (a % num != 0 | b % num != 0) {
  93.                     num++;
  94.                 }
  95.                 lblNewLabel_1.setText(Integer.toString(num));
  96.                 num = 2;
  97.                 while (num % a != 0 | num % b != 0) {
  98.                     num++;
  99.                 }
  100.                 lblNewLabel_2.setText(Integer.toString(num));
  101.             }
  102.         });
  103.         btnNewButton.setBounds(74, 125, 143, 43);
  104.         contentPane.add(btnNewButton);
  105.  
  106.         lblNewLabel_1 = new JLabel("");
  107.         lblNewLabel_1.setForeground(new Color(0, 255, 255));
  108.         lblNewLabel_1.setBackground(new Color(0, 0, 0));
  109.         lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 20));
  110.         lblNewLabel_1.setBounds(97, 164, 101, 59);
  111.         contentPane.add(lblNewLabel_1);
  112.  
  113.         lblNewLabel_2 = new JLabel("");
  114.         lblNewLabel_2.setForeground(new Color(0, 255, 255));
  115.         lblNewLabel_2.setBackground(new Color(0, 0, 0));
  116.         lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 20));
  117.         lblNewLabel_2.setBounds(97, 232, 101, 19);
  118.         contentPane.add(lblNewLabel_2);
  119.  
  120.         lblNewLabel_3 = new JLabel("MCD");
  121.         lblNewLabel_3.setForeground(new Color(0, 255, 255));
  122.         lblNewLabel_3.setBackground(new Color(0, 0, 0));
  123.         lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 20));
  124.         lblNewLabel_3.setBounds(10, 157, 53, 72);
  125.         contentPane.add(lblNewLabel_3);
  126.  
  127.         lblNewLabel_4 = new JLabel("mcm");
  128.         lblNewLabel_4.setForeground(new Color(0, 255, 255));
  129.         lblNewLabel_4.setBackground(new Color(0, 0, 0));
  130.         lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD, 20));
  131.         lblNewLabel_4.setBounds(10, 229, 53, 24);
  132.         contentPane.add(lblNewLabel_4);
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement