-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnippetGUI.java
90 lines (71 loc) · 2.74 KB
/
SnippetGUI.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
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
package registry;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class SnippetGUI implements ActionListener{
final int MAX_CHARS = 20;
JFrame frame;
public String inputSnip;
private String snippetLog;
private JPanel snipPanel;
private JPanel textPanel;
private JLabel snipLabel;
private JLabel textLabel1;
private JLabel textLabel2;
private JEditorPane snipEditPane;
private JScrollPane snipLogPane;
private JTextArea snipTextArea;
private JTextField textField;
private JButton sendButton;
public void startGUI() {
frame = new JFrame("SnippetGUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(640, 640);
snipPanel = new JPanel();
snipLabel = new JLabel("Snippet Log");
snipEditPane = new JEditorPane();
snipEditPane.setEditable(false);
snipLogPane = new JScrollPane(snipEditPane);
snipLogPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
snipLogPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
snipLogPane.setPreferredSize(new Dimension(380, 480));
snipLogPane.setMinimumSize(new Dimension(125, 180));
snipPanel.add(snipLogPane);
snipTextArea = new JTextArea();
textPanel = new JPanel();
textLabel1 = new JLabel("Enter snippet");
textLabel2 = new JLabel("You entered: ");
textField = new JTextField(MAX_CHARS);
sendButton = new JButton("Send");
sendButton.addActionListener(this);
textPanel.add(textLabel1);
textPanel.add(textField);
textPanel.add(sendButton);
textPanel.add(textLabel2);
frame.getContentPane().add(BorderLayout.NORTH, snipLabel);
frame.getContentPane().add(BorderLayout.CENTER, snipPanel);
frame.getContentPane().add(BorderLayout.SOUTH, textPanel);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// set text of test label to field text
inputSnip = textField.getText();
textLabel2.setText("You entered: " + inputSnip);
textField.setText(" ");
// then we must send the input snip to be added to the SnippetList
}
public void updateSnippetLog() {
snipTextArea.setText(snippetLog);
snipLogPane.setViewportView(snipTextArea);
}
public void closeGUI() {
frame.dispose();
}
public void setSnippetLog (String snippetLog) {
this.snippetLog = snippetLog;
}
public String getInputSnip () {
return inputSnip;
}
}