How to perform action on OK of JOptionPane.showMessageDialog

Malwaregeek picture Malwaregeek · Jul 31, 2013 · Viewed 31.9k times · Source

I am working on my first desktop based Java project. I have 2 questions actually

1) How to perform action on OK button of JOptionPane.showMessageDialog.I want to navigate to a new Jframe say x.java on clicking ok.

2) I have a table named as user. This table has 8 columns userid (Primary Key), name, password,emailid, dob, mobileno ,city, date. Four column entries has to be fetched from a Jframe x and remaining four from other Jframe y.

I wrote the following code

For Frame X

PreparedStatement stm = con.prepareStatement("insert into user  

(userrid,name,password,emailid))values (?,?,?,?) ");

      stm.setString(1,id); // id is a public variable
      stm.setString(2,name);
      stm.setString(3,ps);
      stm.setString(4,email);
     stm.executeUpdate();

And for Frame Y. (userid is primary key)

public class Y extends javax.swing.JFrame
{  
    X o = new X(); // to access id variable from frame X

} 



PreparedStatement stm = con.prepareStatement(" update user set  dob ='? ', mobileno 
='?' ,city='?', date='?'  where userid= 'o.id' ");  

It keeps throwing exceptions for the above sql query

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

Answer

Eng.Fouad picture Eng.Fouad · Jul 31, 2013

1) How to perform action on OK button of JOptionPane.showMessageDialog.I want to navigate to a new Jframe say x.java on clicking ok.

int input = JOptionPane.showOptionDialog(null, "Hello World", "The title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);

if(input == JOptionPane.OK_OPTION)
{
    // do something
}