-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.java
More file actions
69 lines (60 loc) · 1.76 KB
/
Window.java
File metadata and controls
69 lines (60 loc) · 1.76 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
//Author: Ryan Miller
//Created on: 10/17/2013
//E-mail: ryanmillera@gmail.com
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.apache.commons.codec.binary.Base64;
import javax.swing.*;
public class Window
{
JTextField inputArea = new JTextField();
JTextField outputArea = new JTextField();
JButton action = new JButton("Encode");
Window()
{
//Create components
JFrame frame = new JFrame("Base64 Encoder");
JPanel panel = new JPanel();
JLabel input = new JLabel("Input:");
JLabel output = new JLabel("Output:");
//Create ActionListeners
action.addActionListener(new actionListener());
//Layout
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(input)
.addComponent(inputArea)
.addComponent(output)
.addComponent(outputArea)
.addComponent(action)
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addComponent(input)
.addComponent(inputArea)
.addComponent(output)
.addComponent(outputArea)
.addComponent(action)
);
//Create frame
frame.setSize(500, 200);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
class actionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String input = inputArea.getText();
byte[] encodedBytes = Base64.encodeBase64(input.getBytes());
outputArea.setText(new String(encodedBytes));
}
}
}