Advertisement
droidus

gui

Jan 28th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.50 KB | None | 0 0
  1. import java.awt.Dimension;
  2. import java.awt.FlowLayout;
  3. import java.awt.Insets;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JOptionPane;
  11. import javax.swing.JScrollPane;
  12. import javax.swing.JSeparator;
  13. import javax.swing.JTextArea;
  14. import javax.swing.JTextField;
  15. import javax.swing.JWindow;
  16. import javax.swing.SwingConstants;
  17.  
  18. public class gui {
  19.  
  20.     JLabel jLabInstruction, jLaberror, copyright;
  21.     JLabel curStatus = new JLabel("");
  22.     JTextField uI;
  23.     Object fileExists;
  24.     boolean file;
  25.     JTextArea textArea;
  26.     JButton jbtnSubmit;
  27.     Object results;
  28.     String[] diagResults;
  29.     boolean check;
  30.     JScrollPane areaScrollPane;
  31.  
  32.     // Run the splash screen
  33.     public void runSplash() {
  34.         JWindow window = new JWindow();
  35.         window.getContentPane().add(
  36.                 new JLabel("Loading TaskManager...", SwingConstants.CENTER));
  37.         window.setBounds(200, 200, 200, 100);
  38.         window.setVisible(true);
  39.         try {
  40.             Thread.sleep(5000);
  41.         } catch (InterruptedException e) {
  42.             e.printStackTrace();
  43.         }
  44.         window.setVisible(false);
  45.         JFrame frame = new JFrame();
  46.         frame.add(new JLabel("Welcome"));
  47.         frame.setVisible(true);
  48.         frame.setSize(300, 100);
  49.         window.dispose();
  50.     }
  51.  
  52.     // Set up the GUI end for the user
  53.     public void startGUI() { // <---- SHOULD ACTUALLY BE CONSTRUCTOR!!
  54.         // These are all essential GUI pieces
  55.         copyright = new JLabel("");
  56.         uI = new JTextField("");
  57.         uI = new JTextField(25);
  58.         new JTextArea("");
  59.  
  60.         final JFrame jfrm = new JFrame(
  61.                 "my app");
  62.         jfrm.setLayout(new FlowLayout());
  63.         jfrm.setSize(300, 300);
  64.         jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  65.         textArea = new JTextArea(5, 20);
  66.         textArea.setEditable(false);
  67.         textArea.setLineWrap(true);
  68.         textArea.setWrapStyleWord(true);
  69.         jLabInstruction = new JLabel("SYSTEM: Please type in a command: ");
  70.         jbtnSubmit = new JButton("Submit");
  71.         jLaberror = new JLabel("");
  72.         textArea.setMargin(new Insets(10, 10, 10, 10));
  73.        
  74.         areaScrollPane = new JScrollPane(textArea); //ADDED
  75.         areaScrollPane.setVerticalScrollBarPolicy(
  76.                 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //ADDED
  77.         areaScrollPane.setPreferredSize(new Dimension(250, 150)); //ADDED
  78.  
  79.         jfrm.add(jLaberror);
  80.         jfrm.add(curStatus);
  81.         jfrm.add(areaScrollPane);
  82.         jfrm.add(jLabInstruction);
  83.         jfrm.add(uI);
  84.         jfrm.add(jbtnSubmit);
  85.         jfrm.add(copyright);
  86.         jfrm.setVisible(true);
  87.     }
  88.  
  89.     // Writes to the text area
  90.     public void writeToTextArea(char annotation, String userInputText) {
  91.         if(annotation=='s') {
  92.             textArea.append("\nSYSTEM: " + userInputText);
  93.         }
  94.         else if (annotation=='n') {
  95.             textArea.append(userInputText.toUpperCase());
  96.         }
  97.         else {
  98.             {
  99.                 textArea.append("\nUSER: " + userInputText.toUpperCase());
  100.             }
  101.         }
  102.     }
  103.  
  104.     // Ask the user for input
  105.     public String askGetInput(String outText) {
  106.         // Update textArea with question
  107.         writeToTextArea('s', outText);
  108.        
  109.         String str = JOptionPane.showInputDialog(null, outText,
  110.                 "my app", 1);
  111.         if(str != null && str != "") {
  112.               writeToTextArea('u', str);
  113.               return str;
  114.         }
  115.         else
  116.               JOptionPane.showMessageDialog(null, "You pressed the cancel button.",
  117.             "my app", 1);
  118.         return "";
  119.     }
  120.    
  121.     public void setCurStatus(String inCurStatus) {
  122.         curStatus.setText(inCurStatus);
  123.         curStatus.setVisible(true);
  124.     }
  125.    
  126.     public void terminateProgram (int status) {
  127.         if(status == 1) {
  128.             uI.setEditable(false);
  129.             jbtnSubmit.setEnabled( false );
  130.         }
  131.     }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement