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