0

Java Code:

private void AddUserActionPerformed(java.awt.event.ActionEvent evt) {                                        
    try{
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://localhost/MyPOS","root","");
        Statement stmt = (Statement)conn.createStatement();

        String fname = fld_fname.getText();
        String lname = fld_lname.getText();
        String role = cmb_role.getSelectedItem().toString();
        String uname = fld_username.getText();
        String pass = fld_password.getText();

        String add = "INSERT INTO admin (firstname, lastname, role, username, password) VALUES('"+fname+"', '"+lname+"', '"+role+"', '"+uname+"', '"+pass+"');";
        stmt.executeUpdate(add);
        conn.close();
        JOptionPane.showMessageDialog(this,"Personnel Added","Add Personnel",JOptionPane.OK_OPTION);

    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR",JOptionPane.ERROR_MESSAGE);
        System.out.println(e.getMessage());
    }

I have this Java code for my POS System, Im wondering why is there a this in the JOptionPane.showMessageDialog(this,...,...)

Also, how do I display it on a table with the corresponding columns?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Which part are you battling with, with regards to putting it in a table? How far did you get? – Evan Knowles Feb 08 '16 at 06:08
  • take a look at this link http://stackoverflow.com/questions/15124904/populating-jtable-using-database-data or google your idea – Kumaresan Perumal Feb 08 '16 at 06:08
  • *"Also, how do I display.."* SO is a Q&A site, not a help desk. As such, different problems should be broken off into different question threads, and each thread should include a single specific, clear question. Voting to close as 'too broad'. – Andrew Thompson Feb 08 '16 at 09:15

1 Answers1

1

As described by the JavaDocs

Parameters:
parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used

This allows the JOptionPane to find the parent frame of the component showing the dialog, this helps with, among other things, to allow the dialog to be positioned relative to the component. In some cases, you don't have a component reference, in which case, it's fine to use null

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366