TextField not displayed
How come TextField "name" is not displayed when button "mem" is clicked?
public class Test extends Applet implements ActionListener
Font Title = new Font("Arial",Font.BOLD,40);
Font Normal = new Font("Arial",Font.PLAIN,20);
JButton mem, nonmem;
public void init()
Color background = new Color(179,50,55);
mem = new JButton("I am an existing member");
nonmem = new JButton("I am new");
name = new TextField("Please Enter Your Name Here");
public void actionPerformed(ActionEvent e)
String source = e.getActionCommand();
else if (source.equals(nonmem))
else if (source.equals(name))
public void stop()
public void paint (Graphics g)
g.drawString("Welcome to Movie2Go Kiosk Services",250,50);
Why are you comparing a String with JButton's and JTextField's in the actionPerformed method?
1. You need to decide whether you are creating an AWT or Swing applet. I would suggest you spend your time learning Swing since that is what most developers use these days. This means don't mix component JButton is Swing. Applet, TextField are AWT. Swing components have a "J" at the beginning.
2. There is no good reason to override the paint() method of the top level container like a JApplet, JFrame or JDialog. If fact I don't see any reason for doing the custom painting. You add the button and the text field to the applet, so why don't you just add a JLabel as well?
3. Adding a component will not show the component. You need to tell Swing that a component has been added to the panel by using panel.revalidate().
revalidate() is for Swing. validate() is for AWT.
Whoa, I have never seen the revalidate() method. Thanks :)
thanks for your help. I'm redoing my code as Swing.