Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kip;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Kip2 extends JFrame {
- private JTextField one;
- private JTextField two;
- int number;
- String text;
- public Kip2() {
- super("Title");
- setLayout(new FlowLayout());
- one = new JTextField(10);
- add(one);
- two = new JTextField("Enter a number: ");
- two.setEditable(false);
- add(two);
- hand handler = new hand();
- one.addActionListener(handler);
- two.addActionListener(handler);
- }
- public class hand implements ActionListener {
- public void actionPerformed(ActionEvent event) {
- String msg = "";
- if (event.getSource() == one) {
- text = one.getText();
- number = Integer.parseInt(text);
- if (number % 2 == 0) {
- msg = msg.format("%s is even!", text);
- } else {
- msg = msg.format("%s is not even!", text);
- }
- JOptionPane.showMessageDialog(null, msg);
- }
- }
- }
- public static void main(String[] args) {
- new Kip2().setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment