you should use the function getText() from the JTextField, the code could be:
private JButton button;
private JTextField textField;
private void initComponents() {
textField = new JTextField ("Type some text here");
button = new JButton("Accept");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = textField.getText();
JOptionPane.showMessageDialog(null, text);
}
});
panel.add(textField);
panel.add(button);
frame.getContentPane().add(panel);
}
So, the logic of the program is: Once the button is pressed, you create a String variable which contains the value of the textfield using the function getText() and then create a Message Dialog with that variable as argument. I hope it works!