import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.SwingConstants;
public class gui {
JLabel jLabInstruction, jLaberror, copyright;
JLabel curStatus = new JLabel("");
JTextField uI;
Object fileExists;
boolean file;
JTextArea textArea;
JButton jbtnSubmit;
Object results;
String[] diagResults;
boolean check;
JScrollPane areaScrollPane;
// Run the splash screen
public void runSplash() {
JWindow window = new JWindow();
window.getContentPane().add(
new JLabel("Loading TaskManager...", SwingConstants.CENTER));
window.setBounds(200, 200, 200, 100);
window.setVisible(true);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
window.setVisible(false);
JFrame frame = new JFrame();
frame.add(new JLabel("Welcome"));
frame.setVisible(true);
frame.setSize(300, 100);
window.dispose();
}
// Set up the GUI end for the user
public void startGUI() { // <---- SHOULD ACTUALLY BE CONSTRUCTOR!!
// These are all essential GUI pieces
copyright = new JLabel("");
uI = new JTextField("");
uI = new JTextField(25);
new JTextArea("");
final JFrame jfrm = new JFrame(
"my app");
jfrm.setLayout(new FlowLayout());
jfrm.setSize(300, 300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textArea = new JTextArea(5, 20);
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
jLabInstruction = new JLabel("SYSTEM: Please type in a command: ");
jbtnSubmit = new JButton("Submit");
jLaberror = new JLabel("");
textArea.setMargin(new Insets(10, 10, 10, 10));
areaScrollPane = new JScrollPane(textArea); //ADDED
areaScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //ADDED
areaScrollPane.setPreferredSize(new Dimension(250, 150)); //ADDED
jfrm.add(jLaberror);
jfrm.add(curStatus);
jfrm.add(areaScrollPane);
jfrm.add(jLabInstruction);
jfrm.add(uI);
jfrm.add(jbtnSubmit);
jfrm.add(copyright);
jfrm.setVisible(true);
}
// Writes to the text area
public void writeToTextArea(char annotation, String userInputText) {
if(annotation=='s') {
textArea.append("\nSYSTEM: " + userInputText);
}
else if (annotation=='n') {
textArea.append(userInputText.toUpperCase());
}
else {
{
textArea.append("\nUSER: " + userInputText.toUpperCase());
}
}
}
// Ask the user for input
public String askGetInput(String outText) {
// Update textArea with question
writeToTextArea('s', outText);
String str = JOptionPane.showInputDialog(null, outText,
"my app", 1);
if(str != null && str != "") {
writeToTextArea('u', str);
return str;
}
else
JOptionPane.showMessageDialog(null, "You pressed the cancel button.",
"my app", 1);
return "";
}
public void setCurStatus(String inCurStatus) {
curStatus.setText(inCurStatus);
curStatus.setVisible(true);
}
public void terminateProgram (int status) {
if(status == 1) {
uI.setEditable(false);
jbtnSubmit.setEnabled( false );
}
}
}