0

I'm using Netbeans to design a JFrame. Using Cardlayout I created two JFrames in ParentPanel. I want to switch between the panels if the button is pressed.

    MotherPanel.removeAll();
    MotherPanel.add(detailPanel);
    MotherPanel.repaint();
    MotherPanel.revalidate();

    detail();

The method detail() accesses the table in database and set specific values to Jtextfields.

public void detail(){
    doConnect();
    setTitle(cur_categ);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);        
}
public void connection() throws SQLException{
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                ResultSet.CONCUR_UPDATABLE);
    String SQL = String.format("SELECT * FROM %s", cur_categ);
    rs_det = stmt.executeQuery(SQL);
}

public void doConnect(){

    try{
        //Connect to the database
        String host = "jdbc:derby://localhost:1527/Employees";
        String userName = "App";
        String pass = " ";
        con = DriverManager.getConnection(host, userName, pass);
        connection();


        //Move the cursor to the first record and get the data if there is any
        if (rs_det.next()){                
            double exp_dou = rs_det.getDouble("Expense");
            String exp = Double.toString(exp_dou);             
            String desc = rs_det.getString("Description");
            String date = rs_det.getString("Date");

         //Display the records in the text fields
         textExpense1.setText(exp);
         textDescription.setText(desc);
         textDate.setText(date);               
        }                          
    }

    catch ( SQLException err ){
        JOptionPane.showMessageDialog(this, err.getMessage());
    }  
}

There are several tables in the database that the second frame accesses depending on the chosen row in the jtable in the first Jpanel. I can open second Jpanel, but I cannot reopen it when it accesses the table with values in database. However, I can reopen second Jpanel if there is no values in the table. How can I fix it?

Le Cong Binh
  • 11
  • 1
  • 4
  • 1
    Variable names should NOT start with an upper case character. Method names should NOT start with an upper case character. Follow Java conventions. – camickr Mar 07 '17 at 15:31
  • I changed it. Thank you for help – Le Cong Binh Mar 07 '17 at 16:25
  • 1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). Hard code some data to replace the DB. 3) "I changed it"* There are still incorrectly capitalised attributes in the above example. Java nomenclature (naming conventions) are `EachWordUpperCaseClass`, `firstWordLowerCaseMethod()`, `firstWordLowerCaseAttribute` unless it is an `UPPER_CASE_CONSTANT`. – Andrew Thompson Mar 07 '17 at 23:48

0 Answers0