madhawaseeeee

odd_even

Aug 15th, 2015
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package kip;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5.  
  6. public class Kip2 extends JFrame {
  7.  
  8.     private JTextField one;
  9.     private JTextField two;
  10.     int number;
  11.     String text;
  12.  
  13.     public Kip2() {
  14.         super("Title");
  15.         setLayout(new FlowLayout());
  16.         one = new JTextField(10);
  17.         add(one);
  18.         two = new JTextField("Enter a number: ");
  19.         two.setEditable(false);
  20.         add(two);
  21.  
  22.         hand handler = new hand();
  23.         one.addActionListener(handler);
  24.         two.addActionListener(handler);
  25.     }
  26.  
  27.     public class hand implements ActionListener {
  28.  
  29.         public void actionPerformed(ActionEvent event) {
  30.             String msg = "";
  31.  
  32.             if (event.getSource() == one) {
  33.                 text = one.getText();
  34.                 number = Integer.parseInt(text);
  35.                 if (number % 2 == 0) {
  36.                     msg = msg.format("%s is even!", text);
  37.                 } else {
  38.                     msg = msg.format("%s is not even!", text);
  39.  
  40.                 }
  41.                 JOptionPane.showMessageDialog(null, msg);
  42.             }
  43.  
  44.         }
  45.     }
  46.  
  47.     public static void main(String[] args) {
  48.         new Kip2().setVisible(true);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment