To close / hide a dialog through code you have to have a reference to it. Unfortunately, the static methods of JOptionPane do not give you the dialog itself.
Now you can create your own dialog like Ko Wey did, or you can create a JOptionPane, use that to call createDialog, and use that reference to close / hide after 30 seconds. Ko Wey's code shows you how to.
One thing to think about: what do you do when the user closes the dialog manually? Is there a way to cancel the thread / timer? Or is it not important because you might only close the already closed dialog?
And what will be your return value (if any) from the JOptionPane dialog?
(Probably the answers will be quite simple, but just think about it for a while
)