0

updating a panel I am designing a program for my assignment using java. I have made a log on box where user enters name and password and clicks on submit or register. Once clicked, an optionpane is brought

upEX.(JOptionPane.showMessageDialog(null, "Account registered", "Account", 
    JOptionPane.INFORMATION_MESSAGE);)

I was wondering how can I add an action listener to the OK button in the option pane that would remove all contents (username,pass,2btns) and replaces it with something else? I found this link: updating a panel which basically just says to use frame.remove and then add.

Another question: My java file looks something like this

class MainFrame extends JFrame {

  public MainFrame() {
    // All the log in panels buttons are here, etc
  }
}

I was wondering if it would be efficient to add the new box details in the same area or make a new class?

Community
  • 1
  • 1
Marwan Fikrat
  • 137
  • 1
  • 8

1 Answers1

1

I was wondering how can I add an actionlistener to the OK button in the option pane that would remove all contents (username,pass,2btns) and replaces it with something else? I found this link: updating a panel which basically just says to use frame.remove and then add.

Don't. Allow the dialog to close, ascertain the action the user took, show another dialog...

Better yet, create you own JPanel, use a CardLayout, add all your views to it and navigate between them. Place this on an instance of a JFrame...

See How to Use CardLayout for more details

I was wondering if it would be efficent to add the new box details in the same area or make a new class?

It would depend. A Class should be a self contained unit of work, focused on accomplishing it's designed task...if your main class is doing more work then it should, then yes, separate the logic into separate class

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366