-
Notifications
You must be signed in to change notification settings - Fork 0
/
RateMyClassView.java~
88 lines (68 loc) · 3.25 KB
/
RateMyClassView.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
// Rate My Class View
package RateMyClass;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.util.ArrayList;
public class RateMyClassView extends JPanel implements ActionListener {
public static String courseQuestion = RateMyClassDriver.courseQuestion;
public static String text; // used to save the text that the user has entered
protected JTextField textField; // controls the text field - where user types text - is editable
protected JTextArea textArea; // controls the text Area - where text is displayed
public static int binder = 0;
private static ArrayList<String> realArray = new ArrayList<String>();
private static int counter = 0;
public RateMyClassView() {
super(new GridBagLayout());
textArea = new JTextArea(courseQuestion, 20, 80); // adds a new text area w/ dimensions -- args = # rows
textArea.setEditable(false); // doesn't allow the text area to be editable by the user. It just displays text
JScrollPane scrollPane = new JScrollPane(textArea); // allows the text area to be scrolled through.
textField = new JTextField(80); // adds new text field - where users can type -- arg = # of columns
textField.addActionListener(this); //adds action listener, which allows me to know what the user clicks on or types
textArea.setMargin(new Insets(15,20,20,20)); //sets margin
// font
Font font = new Font("Century Gothic", Font.BOLD, 16);
textArea.setFont(font);
textArea.setLineWrap(true); //wraps lines if the window is too small
GridBagConstraints gridcon = new GridBagConstraints(); // the window w/ the same dimensions that were specified above
gridcon.gridwidth = GridBagConstraints.REMAINDER;
gridcon.fill = GridBagConstraints.BOTH;
gridcon.weightx = 1.0; // allows users to pull the constraints and change the size of the window
gridcon.weighty = 1.0;
add(scrollPane, gridcon); // allows text area to be displayed
add(textField, gridcon); // allows text field to be displayed
}
public void actionPerformed(ActionEvent evt) { // controls action listener
text = textField.getText(); //gets and saves text that the user types in
textField.selectAll();
String newText = text.toLowerCase(); // sets text to lowercase
realArray = RateMyClassDriver.getText(newText);
for (int i = 0; i < realArray.size(); i++) {
if (counter == 0) {
textArea.setText("");
counter++;
System.out.println("hi");
}
else {
textArea.append(realArray.get(i)+"\n");
}
}
counter = 0;
}
private static void createAndShowGUI() { // creates the GUI
JFrame frame = new JFrame("Rate My Class Application"); // creates a window and labels it Rate My Class
// allows all the windows and stuff above to be seen
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new RateMyClassView());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) { // just displays the GUI like in grid world how it has to say "Show grid"
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}