SHARE
TWEET

Untitled

a guest Jun 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. JLabel lblPrimeNumberChecker = new JLabel("Prime number checker");
  2.     lblPrimeNumberChecker.setBounds(160, 11, 117, 14);
  3.     contentPane.add(lblPrimeNumberChecker);
  4.  
  5.  
  6.     JButton btnReset = new JButton("Reset");
  7.     btnReset.addActionListener(new ActionListener() {
  8.         public void actionPerformed(ActionEvent e) {
  9.             textNum.setText(null);
  10.  
  11.         }
  12.     });
  13.     btnReset.setBounds(271, 208, 89, 23);
  14.     contentPane.add(btnReset);
  15.  
  16.     textNum = new JTextField();
  17.     textNum.setBounds(144, 42, 231, 20);
  18.     contentPane.add(textNum);
  19.     textNum.setColumns(10);
  20.  
  21.     JLabel lblNewLabel = new JLabel("Enter number");
  22.     lblNewLabel.setBounds(62, 45, 82, 14);
  23.     contentPane.add(lblNewLabel);
  24.  
  25.     JButton btnCheck = new JButton("Check");
  26.     btnCheck.addMouseListener(new MouseAdapter() {
  27.         @Override
  28.         public void mouseClicked(MouseEvent checkPrime) {
  29.  
  30.         }
  31.         private boolean checkPrime(int n) {
  32.             int num=Integer.parseInt(textNum.getText());
  33.              if(num<2) {
  34.                  return false;
  35.              }
  36.              int h=(int)Math.sqrt(n);
  37.              for(int i=2;i<=h;i++) {
  38.                  if(n%i==0) {
  39.                      return false;
  40.                  }
  41.              }
  42.                     return true;    
  43.  
  44.  
  45.         }
  46.             void button_clicked() {
  47.                 int n=0;
  48.                 boolean isPrime=checkPrime(n);
  49.                 if(isPrime) {
  50.                     JOptionPane.showMessageDialog(btnCheck, "Prime number", "Result", JOptionPane.INFORMATION_MESSAGE);
  51.                 }
  52.                 else {
  53.                     JOptionPane.showMessageDialog(btnCheck, "Not prime number", "Result", JOptionPane.INFORMATION_MESSAGE);
  54.                 }
  55.             }
  56.  
  57.  
  58.             });
  59.     btnCheck.setBounds(62, 208, 89, 23);
  60.     contentPane.add(btnCheck);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top