-
Notifications
You must be signed in to change notification settings - Fork 0
/
L12DecToBinApp.java
53 lines (41 loc) · 1.5 KB
/
L12DecToBinApp.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
47
48
49
50
51
52
53
//Mini Decimal to Binary Converter
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class L12DecToBinApp extends JFrame implements ActionListener {
private JTextField txDecimal;
private JTextField txBinary;
public L12DecToBinApp() {
createUI();
}
private void createUI() {
this.setTitle("Padgett's Decimal to Binary");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
//Create UI Components
txDecimal = new JTextField();
txBinary = new JTextField();
txBinary.setEditable(false);
//Add UI components to JFrame
this.getContentPane().setLayout(new GridLayout(2, 2));
this.add(new JLabel("Decimal"));
this.add(txDecimal);
this.add(new JLabel("Binary"));
this.add(txBinary);
this.pack();
// Link the actionPerformed method to txDecimal
txDecimal.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
System.out.println("Hello World");
String userInput = txDecimal.getText();
int decNumber = Integer.parseInt(userInput);
String binary = Integer.toBinaryString(decNumber);
txBinary.setText(binary);
}
public static void main(String[] args) {
L12DecToBinApp myApp = new L12DecToBinApp();
myApp.setVisible(true);
System.out.println("Starting the program...");
}
}