Advertisement
cd62131

Text Box

Feb 15th, 2014
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.94 KB | None | 0 0
  1. import java.awt.Dimension;
  2. import java.awt.FlowLayout;
  3. import java.awt.event.MouseAdapter;
  4. import java.awt.event.MouseEvent;
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.JTextField;
  8.  
  9. public class TextBox {
  10.   JFrame frame;
  11.   JTextField text;
  12.   JButton b;
  13.  
  14.   public TextBox() {
  15.     frame = new JFrame("TextBox");
  16.     frame.setSize(new Dimension(300, 100));
  17.     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18.     frame.setLayout(new FlowLayout());
  19.     text = new JTextField();
  20.     text.setColumns(20);
  21.     frame.add(text);
  22.     b = new JButton("Submit");
  23.     b.addMouseListener(new MouseAdapter() {
  24.       @Override
  25.       public void mouseClicked(MouseEvent e) {
  26.         text_print();
  27.       }
  28.     });
  29.     frame.add(b);
  30.     frame.setVisible(true);
  31.   }
  32.  
  33.   public void text_print() {
  34.     System.out.println(text.getText());
  35.   }
  36.  
  37.   public static void main(String[] args) {
  38.     new TextBox();
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement