-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadder.java
More file actions
97 lines (73 loc) · 2.36 KB
/
adder.java
File metadata and controls
97 lines (73 loc) · 2.36 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// A Java program to demonstrate random number generation
// using java.util.Random;
import java.util.Random;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
public class adder{
String s1="";
String s2="";
int[] sum= new int[3];
adder(){
for(int i=0;i<3;i++)
{
// create instance of Random class
Random rand = new Random();
// Generate random integers in range 0 to 99
int rand_int1 = rand.nextInt(100);
int rand_int2 = rand.nextInt(100);
sum[i]=rand_int1+rand_int2;
s1=s1+Integer.toString(rand_int1)+"\t"+Integer.toString(rand_int2)+"\n";
s2=s2+Integer.toString(rand_int1)+"\t"+Integer.toString(rand_int2)+"\t"+Integer.toString(sum[i])+"\n";
// Print random integers
}
}
public void print(String n){
try {
PrintWriter fout;
fout = new PrintWriter("Data.xls");
fout.write("A"+"\t"+"B"+"\n");
fout.write(n);
fout.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public void print1(String n1) {
try {
PrintWriter fout;
fout = new PrintWriter("Data.xls");
fout.write("A"+"\t"+"B"+"\t"+"SUM"+"\n");
fout.write(n1);
fout.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public static void main(String args[])
{
adder a=new adder();
JFrame f=new JFrame("Button Example");
JButton b=new JButton("Generate");
JButton b1=new JButton("Sum");
b.setBounds(50,100,95,30);
b1.setBounds(50,200,95,30);
f.add(b);
f.add(b1);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
a.print(a.s1);
}
});
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
a.print(a.s2);
}
});
}
}