Removing and Adding Components

Hi there,

I've done a lot of programming, but im relatively new to java. I am trying to make a simple java chat program. For the client applet, I am using a simple layout of a label, text field and 'enter' button for a login screen, and a text area and text field for the chat UI.

I am adding the Label, TextField and JButton components for the login screen within the init() function. I would then like to remove these components and add the TextArea and TextField for the chat UI. I have tried to use remove and add, once the 'enter' button is clicked, but i cannot get this to work. Can anyone tell me why or how to do it?

as i long shot i tried putting a repaint(); in the odd place, but that didnt work either hehe

Thanks

publicvoid init()

{

setBackground(Color.black);

lName =new Label("Please Enter Your name:", Label.CENTER);

lName.setBackground(new Color(118, 189, 233));

add(lName);

tfName =new TextField("", 20);

add(tfName);

bEnter =new JButton("Enter");

bEnter.setActionCommand("cmdEnter");

bEnter.addActionListener(this);

bEnter.setToolTipText("Click to enter the chat room!");

add(bEnter);

}

// called on the action event 'cmdEnter'

publicvoid CreateUI()

{

removeAll();

taMsgWindow =new TextArea("", 21, 108);//23

taMsgWindow.setEditable(false);

add(taMsgWindow);

tfMessage =new TextField("Type your message here", 108);

add(tfMessage);

}

[2280 byte] By [genfisha] at [2007-10-3 2:47:21]
# 1

Sounds like a job for CardLayout. Typically anything that looks like a "Wizard" with Next and Back buttons can best be accomplished by creating a card for each screen, in this case a card for the login page, and the a card for the chat screen. When the user logs in, simply switch cards.

Brian

brian@cubik.caa at 2007-7-14 20:36:07 > top of Java-index,Java Essentials,New To Java...
# 2
cool i'll look it up, thanks.anyone know of any good sources of info for this?
genfisha at 2007-7-14 20:36:07 > top of Java-index,Java Essentials,New To Java...
# 3
> anyone know of any good sources of info for this?You must be new to using the Internet as well as new to Java. The polite answer to this question is "Google does."
DrClapa at 2007-7-14 20:36:07 > top of Java-index,Java Essentials,New To Java...
# 4
thats also the cocky answer to any post... does it make u feel good?
genfisha at 2007-7-14 20:36:07 > top of Java-index,Java Essentials,New To Java...