-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal.java
More file actions
120 lines (98 loc) · 3.29 KB
/
Copy pathFinal.java
File metadata and controls
120 lines (98 loc) · 3.29 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import java.awt.*;
public class Final extends javax.swing.JFrame{
public Final() {
gcdFinder();
}
private void gcdFinder() {
Container pane = getContentPane();
setLayout(null);
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1.setText("Get GCD");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextField1.setEnabled(true);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField2.setEnabled(true);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
jTextField3.setEnabled(false);
jLabel1.setText("Enter one positive integer in the two boxes");
jLabel2.setText("Press enter after you type each number.");
jButton1.setSize(75, 50);
jTextField1.setSize(50, 50);
jTextField2.setSize(50, 50);
jTextField3.setSize(50, 50);
jLabel1.setSize(300, 50);
jLabel2.setSize(300, 50);
jTextField1.setLocation(150, 70);
jTextField2.setLocation(250, 70);
jLabel1.setLocation(100, 1);
jLabel2.setLocation(100,20);
jButton1.setLocation(50, 120);
jTextField3.setLocation(200, 120);
add(jTextField1);
add(jTextField2);
add(jButton1);
add(jLabel1);
add(jLabel2);
add(jTextField3);
setSize(450, 200);
setVisible(true);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}
String input1 = "";
String input2 = "";
int a = 0;
int b = 0;
int GCD;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
GCD = calcGCD(a, b);
jTextField3.setText(Integer.toString(GCD));
}//end button1
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
//take input of first pos int
input1 = jTextField1.getText();
a = Integer.parseInt(input1);
if(a < 0) {
a = a * (-1);
}
}//end textField1
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
//take input of second pos int
input2 = jTextField2.getText();
b = Integer.parseInt(input2);
if(b < 0) {
b = b * (-1);
}
}//end textField2
private static int calcGCD(int i, int j) {
if (j == 0) {
return i;
}
return calcGCD(j, i % j);
}// end calcGCD
public static void main(String[] args) {
Final gcdFinder = new Final();
}//end main
private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
}//end class