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?

3
  • Which part are you battling with, with regards to putting it in a table? How far did you get? Commented Feb 8, 2016 at 6:08
  • take a look at this link stackoverflow.com/questions/15124904/… or google your idea Commented Feb 8, 2016 at 6: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'. Commented Feb 8, 2016 at 9:15

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.