Welcome to Dream.In.Code
Become a Java Expert!

Join 149,491 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,291 people online right now. Registration is fast and FREE... Join Now!




Start Screen

 
Reply to this topicStart new topic

Start Screen

Help Me Learn Java
22 Mar, 2007 - 09:22 PM
Post #1

New D.I.C Head
*

Joined: 17 Dec, 2006
Posts: 6


My Contributions
Okay...I am trying to create a Start Screen...I want a dialog box to come up and it does, but then when the user clicks Yes, I would like a frame to open...this is my code so far...

CODE
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class StartScreen {

    public static void main(String[] args) {
        JOptionPane.showConfirmDialog(null, "Would you like to create a new room?", "New", JOptionPane.YES_NO_OPTION);
        
    }
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("FrameDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel emptyLabel = new JLabel("Booooo");
        emptyLabel.setPreferredSize(new Dimension(200, 100));
        frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

        //Display the window.
        frame.pack();
        frame.setVisible(true);

        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}


Thank you!
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Start Screen
23 Mar, 2007 - 04:47 AM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
JOptionpane returns an int value, try looking it up in the documentation for the exact values, but in this case a 1 and 0 based on the result. Thus your setup in your main should be something like:
CODE

public static void main(String[] args) {
        int result = JOptionPane.showConfirmDialog(null, "Would you like to create a new room?", "New", JOptionPane.YES_NO_OPTION);
        if(result == 1){
           //1 code
        }
        else{
           //other code
        }
    }

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 05:37PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month