15 April 2016

Get text & JTextArea in Eclipse Swing

Get text
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SwingGet {

 private JFrame frame;
 private JTextField textField;

 /**
  * Launch the application.
  */
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     SwingGet window = new SwingGet();
     window.frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
 }

 /**
  * Create the application.
  */
 public SwingGet() {
  initialize();
 }

 /**
  * Initialize the contents of the frame.
  */
 private void initialize() {
  frame = new JFrame();
  frame.setBounds(100, 100, 252, 171);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(null);
  
  textField = new JTextField();
  textField.setBounds(39, 25, 158, 26);
  frame.getContentPane().add(textField);
  textField.setColumns(10);
  
  JButton btnGet = new JButton("Get");
  btnGet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) { textField.setText("Hello World"); textField.getText(); } }); btnGet.setBounds(69, 78, 89, 23); frame.getContentPane().add(btnGet); } }
JTextArea in Eclipse



0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang