-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.java
46 lines (43 loc) · 910 Bytes
/
random.java
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
44
45
46
import java.util.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
class demo extends JFrame implements ActionListener
{
JLabel l1;
JTextField t1;
JButton b1;
demo()
{
setVisible(true);
setSize(500,500);
setLayout(new FlowLayout());
l1=new JLabel("Enter Number");
add(l1);
t1=new JTextField(10);
add(t1);
b1=new JButton("OK");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ar)
{
if(ar.getSource()==b1)
{
int n=Integer.parseInt(t1.getText());
if(n%2==0)
JOptionPane.showMessageDialog(this,"Number is Even");
else
JOptionPane.showMessageDialog(this,"Number is Odd");
Random r=new Random();
int a=r.nextInt(100);
int b=r.nextInt(100);
JOptionPane.showMessageDialog(this,"Value 1 = "+a+"\nValue 2 = "+b);
}
}
public static void main(String ar[])
{
new demo();
}
}