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);
}

