I have main JFrame called frame and in that frame I have few JButtons. For every JButton there is ActionPerformed and when I click specific button function setContent switch to new JPanel. Let's say that i use one JPanel for adding values to the db. When I finish my job with adding values I want to disable that JPanel and I want to see only main JFrame.
Here is my code for JFrame
public class MainForm extends JFrame {
public MainForm() {
initComponents();}
public void switchPanel(JPanel pnl){
setContentPane(pnl);
revalidate();
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEventevt){
switchPanel(new AddPlesac());} }
Here is my code for JPanel.
public class AddPlesac extends JPanel {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Repository dbRepo = Repository.getInstance();
dbRepo.addUserwithValidation(tfname.getText(),tfprezime.getText(),p);
}}
So in my code, I make connection to DB via dbRepo, importing values to the table via function addUserValidation, and now my work is finished with this AddPlesac(JPanel)!How to disable AddPlesac and see only MainForm JFrame?! Thanks in advance!