I'm designing a simple GUI ( Using WindowBuilder Pro in Eclipse) that just shows "Hello World" in the textArea
after pressing the button (Testing).
However, when I press the button, it doesn't show up in the text area! Can somebody adjust the code or at least tell me what to do?
public class TextA {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TextA window = new TextA();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public TextA() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JTextArea textArea = new JTextArea();
textArea.setBounds(113, 44, 226, 96);
frame.getContentPane().add(textArea);
JButton btnTesting = new JButton("Testing");
btnTesting.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JTextArea textArea = new JTextArea();
textArea.setText("Hello World!");
}
});
btnTesting.setBounds(168, 167, 117, 29);
frame.getContentPane().add(btnTesting);
}
}