-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddEvenGUI.java
More file actions
43 lines (42 loc) · 1.23 KB
/
OddEvenGUI.java
File metadata and controls
43 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class OddEvenGUI extends JFrame implements ActionListener{
JButton ok;
JLabel noLabel;
JTextField noField;
static long no, checker;
OddEvenGUI(){
super("Odd or Even");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane=new JPanel();
noField= new JTextField(10);
noLabel= new JLabel("Enter a Number");
ok=new JButton("OK");
ok.setBackground(Color.RED);
ok.addActionListener(this);
pane.add(noLabel);
pane.add(noField);
pane.add(ok);
add(pane);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent evt){
Object source=evt.getSource();
if (source == ok){
no=Long.parseLong(noField.getText());
noField.setText("");
checker=no%2;
if (checker==0)
JOptionPane.showMessageDialog(null, "The number"+" "+no+" "+"is an even number", "Answer", JOptionPane.PLAIN_MESSAGE);
else if (checker!=0)
JOptionPane.showMessageDialog(null, "The number"+" "+no+" "+"is an odd number", "Answer", JOptionPane.PLAIN_MESSAGE);
}
repaint();
}
public static void main(String[] args) throws NumberFormatException{
OddEvenGUI oegui=new OddEvenGUI();
}
}