The Artima Developer Community
Sponsored Link

Java Answers Forum
removing panels...

1 reply. Most recent reply: Mar 23, 2002 12:31 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 1 reply on 1 page
Mary

Posts: 7
Nickname: dj
Registered: Mar, 2002

removing panels... Posted: Mar 23, 2002 3:00 AM
Reply to this message Reply
I have tried to remove panels using the remove method in the Action performed event. I have used the repaint() method, revalidate() method and frame.pack() method. Nothing seems to be working.

public void actionPerformed(ActionEvent evt)
{
if (evt.getSource()== hardwareBtn)
{
controlArea.remove(lampPanel, kettlePanel, ovenPanel, microwavePanel);
content.repaint();

}
}

also i was just wondering if you can verify both a username and password in the one if statement. We can username verification working but can't get the two working together

public void actionPerformed(ActionEvent e)
{
if (e.getSource()==loginBtn)
{
String s = nameTxt.getText();
String t = passwordTxt.getText();
if (s.equals ("tange") && t.equals("100045713"))
{
JOptionPane.showMessageDialog(null,"Welcome " +nameTxt.getText());
}
}


Re: removing panels... Posted: Mar 23, 2002 12:31 PM
Reply to this message Reply
Posted by: Charles Bell    Posts: 519 / Nickname: charles / Registered: Feb, 2002
the remove method is a Container method from which
Panel, and JPanel inherit from:


remove

public void remove(Component?comp)

Removes the specified component from this container.

Parameters:
comp - the component to be removed


if your panel object is named controlArea as your code indicates, then try the following:

controlArea.remove(lampPanel);
controlArea.remove(kettlePanel);
con trolArea.remove(ovenPanel);
controlArea.remove(microwavePanel);

then

controlArea.validate();

validate() causes a container to lay out its subcomponents again after the components it contains have been added to or modified, i.e. in your case removed.


On your username and password validation line that looks like:

if (s.equals ("tange") && t.equals("100045713"))

change it to:
if ((s.compareTo("tange")==0) && (t.compareTo("100045713")==0))


Topic: JTABLE Previous Topic   Next Topic Topic: Network Programming with TCP

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use