Advertisement
Robin_Lery

GUI for speech recognition

Mar 10th, 2015
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.41 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();
  33.                     window.frame.setVisible(true);
  34.                 } catch (Exception e) {
  35.                     e.printStackTrace();
  36.                 }
  37.             }
  38.         });
  39.     }
  40.  
  41.     /**
  42.      * Create the application.
  43.      */
  44.     public Frame1() {
  45.         initialize();
  46.     }
  47.  
  48.     /**
  49.      * Initialize the contents of the frame.
  50.      */
  51.     private void initialize() {
  52.         frame = new JFrame();
  53.         frame.getContentPane().setForeground(new Color(50, 205, 50));
  54.         frame.setBounds(100, 100, 525, 295);
  55.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.         frame.getContentPane().setLayout(null);
  57.        
  58.         JButton btnNewButton = new JButton("Start Recognizing");
  59.         btnNewButton.setBackground(UIManager.getColor("Button.background"));
  60.         btnNewButton.setForeground(new Color(34, 139, 34));
  61.         btnNewButton.addActionListener(new ActionListener() {
  62.             public void actionPerformed(ActionEvent arg0) {
  63.                 state.setText("Listening");
  64.                 System.out.println("Started Listening");
  65.                 state.setBackground(new Color(51, 204, 0));
  66.                
  67.             }
  68.         });
  69.         btnNewButton.setBounds(10, 11, 156, 49);
  70.         frame.getContentPane().add(btnNewButton);
  71.        
  72.         JButton btnNewButton_1 = new JButton("Stop Recognizing");
  73.         btnNewButton_1.addActionListener(new ActionListener() {
  74.             public void actionPerformed(ActionEvent e) {
  75.                 state.setText("Not listening");
  76.                 state.setBackground(new Color(204, 0, 51));
  77.                 System.out.println("Stopped Listening");
  78.             }
  79.         });
  80.         btnNewButton_1.setForeground(new Color(204, 0, 0));
  81.         btnNewButton_1.setBackground(UIManager.getColor("Button.background"));
  82.         btnNewButton_1.setBounds(176, 11, 156, 49);
  83.         frame.getContentPane().add(btnNewButton_1);
  84.        
  85.         JButton btnNewButton_2 = new JButton("Show Commands");
  86.         btnNewButton_2.addActionListener(new ActionListener() {
  87.             public void actionPerformed(ActionEvent e) {
  88.                 JOptionPane.showMessageDialog(null, "List\n"
  89.                         + "One\n"
  90.                         + "two");
  91.             }
  92.         });
  93.         btnNewButton_2.setBounds(342, 11, 156, 49);
  94.         frame.getContentPane().add(btnNewButton_2);
  95.        
  96.         state = new JLabel("Not listening");
  97.         state.setForeground(new Color(255, 255, 255));
  98.         state.setBackground(new Color(204, 0, 51));
  99.         state.setHorizontalAlignment(SwingConstants.CENTER);
  100.         state.setBounds(10, 222, 488, 24);
  101.         state.setOpaque(true);
  102.         frame.getContentPane().add(state);
  103.        
  104.        
  105.         JScrollPane scrollPane = new JScrollPane();
  106.         scrollPane.setBounds(10, 66, 488, 145);
  107.         scrollPane.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
  108.         frame.getContentPane().add(scrollPane);
  109.        
  110.         JTextArea textArea = new JTextArea();
  111.         textArea.setBounds(10, 72, 488, 139);
  112.         System.setOut(new PrintStream(new Echo(System.out, textArea)));
  113.         scrollPane.setViewportView(textArea);
  114.        
  115.         frame.getContentPane().add(scrollPane);
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement