[SOLVED] Confused by the textField
I'm just having a look at ways to input and retrieve a string from a text field.
I've got confused somewhere along the way now I get an exception thrown and my components are missing from the JFrame (Plus It won't setBounds)
Any help would be appreciated, Das code:
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ActionExample extends JFrame
{
Button goButton;
TextField tField;
public void ActionExample()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0,0,200,200);
Container c = getContentPane();
c.setLayout(new FlowLayout());
tField = new TextField("*Enter your text here*",35);
goButton = new Button("Go");
c.add(tField);
c.add(goButton);
goButton.addActionListener
(
new ActionListener()
{
public void actionPerformed( ActionEvent evt )
{
repaint();
}
}
);
}
public static void main(String args[])
{
ActionExample ae = new ActionExample();
ae.setVisible(true);
}
public void paint(Graphics g)
{
g.drawString(tField.getText(),20,100);
}
}
Cheers :{p