Advertisement
Robin_Lery

GUI

Mar 11th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. package demo.sphinx.helloworld;
  2. import java.awt.Color;
  3. import java.awt.EventQueue;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.PrintStream;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JOptionPane;
  12. import javax.swing.JScrollPane;
  13. import javax.swing.ScrollPaneConstants;
  14. import javax.swing.SwingConstants;
  15. import javax.swing.UIManager;
  16. import javax.swing.JTextArea;
  17.  
  18. public class Frame1 {
  19.  
  20.     JFrame frame;
  21.     private JLabel state;
  22.    
  23.  
  24.     /**
  25.      * Launch the application.
  26.      */
  27.     public static void main(String[] args) {
  28.        
  29.         EventQueue.invokeLater(new Runnable() {
  30.             public void run() {
  31.                 try {
  32.                     Frame1 window = new Frame1(args);
  33.                     window.frame.setVisible(true);
  34.                    
  35.                 } catch (Exception e) {
  36.                     e.printStackTrace();
  37.                 }
  38.             }
  39.         });
  40.     }
  41.  
  42.     /**
  43.      * Create the application.
  44.      * @param args
  45.      */
  46.     public Frame1(String[] args) {
  47.         initialize(args);
  48.     }
  49.  
  50.     /**
  51.      * Initialize the contents of the frame.
  52.      * @param args
  53.      */
  54.     private void initialize(String[] args) {
  55.         frame = new JFrame();
  56.         frame.getContentPane().setForeground(new Color(50, 205, 50));
  57.         frame.setBounds(100, 100, 525, 295);
  58.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  59.         frame.getContentPane().setLayout(null);
  60.        
  61.         JButton btnNewButton = new JButton("Start Recognizing");
  62.         btnNewButton.setBackground(UIManager.getColor("Button.background"));
  63.         btnNewButton.setForeground(new Color(34, 139, 34));
  64.         btnNewButton.addActionListener(new ActionListener() {
  65.             public void actionPerformed(ActionEvent arg0) {
  66.                 state.setText("Listening");
  67.                 System.out.println("Started Listening");
  68.                 state.setBackground(new Color(51, 204, 0));
  69.                 HelloWorld obj = new HelloWorld();
  70.                 obj.main(args);
  71.             }
  72.         });
  73.         btnNewButton.setBounds(10, 11, 156, 49);
  74.         frame.getContentPane().add(btnNewButton);
  75.        
  76.         JButton btnNewButton_1 = new JButton("Stop Recognizing");
  77.         btnNewButton_1.addActionListener(new ActionListener() {
  78.             public void actionPerformed(ActionEvent e) {
  79.                 state.setText("Not listening");
  80.                 state.setBackground(new Color(204, 0, 51));
  81.                 System.out.println("Stopped Listening");
  82.             }
  83.         });
  84.         btnNewButton_1.setForeground(new Color(204, 0, 0));
  85.         btnNewButton_1.setBackground(UIManager.getColor("Button.background"));
  86.         btnNewButton_1.setBounds(176, 11, 156, 49);
  87.         frame.getContentPane().add(btnNewButton_1);
  88.        
  89.         JButton btnNewButton_2 = new JButton("Show Commands");
  90.         btnNewButton_2.addActionListener(new ActionListener() {
  91.             public void actionPerformed(ActionEvent e) {
  92.                 JOptionPane.showMessageDialog(null, "List\n"
  93.                         + "One\n"
  94.                         + "two");
  95.             }
  96.         });
  97.         btnNewButton_2.setBounds(342, 11, 156, 49);
  98.         frame.getContentPane().add(btnNewButton_2);
  99.        
  100.         state = new JLabel("Not listening");
  101.         state.setForeground(new Color(255, 255, 255));
  102.         state.setBackground(new Color(204, 0, 51));
  103.         state.setHorizontalAlignment(SwingConstants.CENTER);
  104.         state.setBounds(10, 222, 488, 24);
  105.         state.setOpaque(true);
  106.         frame.getContentPane().add(state);
  107.        
  108.        
  109.         JScrollPane scrollPane = new JScrollPane();
  110.         scrollPane.setBounds(10, 66, 488, 145);
  111.         scrollPane.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
  112.         frame.getContentPane().add(scrollPane);
  113.        
  114.         JTextArea textArea = new JTextArea();
  115.         textArea.setBounds(10, 72, 488, 139);
  116.         System.setOut(new PrintStream(new Echo(System.out, textArea)));
  117.         scrollPane.setViewportView(textArea);
  118.        
  119.         frame.getContentPane().add(scrollPane);
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement