Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- public class TextBox {
- JFrame frame;
- JTextField text;
- JButton b;
- public TextBox() {
- frame = new JFrame("TextBox");
- frame.setSize(new Dimension(300, 100));
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLayout(new FlowLayout());
- text = new JTextField();
- text.setColumns(20);
- frame.add(text);
- b = new JButton("Submit");
- b.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- text_print();
- }
- });
- frame.add(b);
- frame.setVisible(true);
- }
- public void text_print() {
- System.out.println(text.getText());
- }
- public static void main(String[] args) {
- new TextBox();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement