Results 1 to 5 of 5
Thread: If Statement return
- 10-31-2010, 09:11 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
If Statement return
Hello..I'm new to java and have been trying to figure this out for couple of hours now. I'm trying to use the If statement in one of my methods to make my JOptionpanes appear when my second JFrame is visible. I managed to get it to work by using the following code but the problem is I can't return the userName. I get the error "missing return statement" when compiling. If there is anybody who can give me a solution or a better way of doing this please help me out...I just want to be able to make my JOptionpanes appear when my secondJFrame is visible..I'm using action listener to run this method when a JButton is clicked. But I need the userName to be returned so I can use it on my other methods. This method is in my main and thanks to the If statement I put its showing the JOptionpanes when my second JFrame shows up just can't return my userName...
Sorry for the crappy code paste...I'm still new to this :(Java Code:public String WelcomeDialog() //JOPtionpane dialog { if (secondJPanel.isVisible()) //IF starts Here { //welcome message String welcome = "<html><font size=\"5\" face" + "=\"SimHei\">" + "Welcome to Final Escape VIII !" + " <br>Please enter your name below " + "to continue!" + "</font></html>"; //Get usersname userName = (String)JOptionPane.showInputDialog (null, ""+welcome+"", "Final Escape VIII", JOptionPane.PLAIN_MESSAGE, auron, null, "Type your name here!"); // Burpback String welcome2 = "<html><font size=\"5\" face" + "=\"SimHei\">" + "Thank you for entering your name "+userName+"!" + "</font></html>"; //Game Info String gameinfo = "<html><font size=\"5\" face" + "=\"Baskerville Old Faceei\">" + "Hello "+userName+" and welcome to my escape game! " + "<br>In my game you'll take control of the main character " + "<br>named Squall. He is a character from FinalFantasy VIII" + "<br>a playstation one game that was released in 1998." + "<br>The goal of my game will be to control Squall and guide him " + "<br>escape from a dungeon from his original game. In order to do so you will" + "<br>need the key item in this game which will be his main weapon from " + "<br>his original game. The reason you'll need this key item is to defeat " + "<br>the boss who is guarding the exit to the dungeon. Your goal is to find " + "<br>the key item first and then navigate through the dungeon and defeat the " + "<br>boss to escape!" + "</font></html>"; //Registration info String registration = "<html><font size=\"6\" face" + "=\"Baskerville Old Faceei\">" + "The regestration fees for Final Escape VIII are as follows" + "<br><li>$2.50 for a Beginner Player (age under 4)" + "<br><li>$5.00 for a Average Player (ages 4 - 12) " + "<br><li>$7.50 for a Advanced Player (ages 13 - 17)" + "<br><li>$9.75 for a Veteran Player(ages 18 and above)" + "<br><li>$1.25 for each additional feature: a “teamate”, “boss” “extra key weapon”" + "</font></html>"; //Underconstruction message String alert = "<html><font size=\"5\" face" + "=\"SimHei\">" + "Now that you've seen the fees and read about the game proceed by clicking on" + "<br>on the continue button to proceed to the registration form" + "</font></html>"; ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// //welcome message JOptionPane.showMessageDialog( null,""+welcome2+"", "Final Escape VIII", JOptionPane.WARNING_MESSAGE, squall2 ); //Game information JOptionPane.showMessageDialog( null,""+gameinfo+"", "Final Escape VIII", JOptionPane.WARNING_MESSAGE, squall); //Registration fees JOptionPane.showMessageDialog( null,""+registration+"", "Final Escape VIII", JOptionPane.WARNING_MESSAGE, cloud ); //Under Construction JOptionPane.showMessageDialog( null,""+alert+"", "Registration alert!", JOptionPane.WARNING_MESSAGE, choco ); return userName; //need this returned! } } //need to return here as well?
- 10-31-2010, 10:32 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,370
- Blog Entries
- 7
- Rep Power
- 17
Basically this is what your code looks like:
Think what would happen if secondJPanel is not visible; the entire if-statement is skipped and nothing is returned; the compiler doesn't like that because you state that your method returns a String; always.Java Code:if (secondJPanel.isVisible()) { // a whole lot of code here ... return userName; } } // end of method
kind regards,
JosLast edited by JosAH; 10-31-2010 at 10:36 AM.
- 10-31-2010, 06:03 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
Thank you for your reply so I can not use an if statement in this situation...Any suggestions on what do use though to control when my JOptionpane dialogs will show up? Can you put one in a JFrame so when the JFrame is visible so will the JOptionpane?
- 10-31-2010, 07:21 PM #4
Recommended reading:
Code Conventions for the Java(TM) Programming Language: Contents
db
- 11-01-2010, 11:43 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Return statement error
By Exothesis in forum New To JavaReplies: 2Last Post: 10-13-2010, 01:56 AM -
Return Statement and Boolean Help
By GhostShaman in forum New To JavaReplies: 8Last Post: 03-09-2010, 11:15 AM -
problem while using return statement
By shaluchandran in forum New To JavaReplies: 10Last Post: 12-12-2008, 06:29 PM -
there is no return statement
By gabriel in forum New To JavaReplies: 17Last Post: 12-03-2008, 04:55 PM -
[SOLVED] return statement
By Nakira in forum New To JavaReplies: 8Last Post: 11-12-2008, 11:00 PM


LinkBack URL
About LinkBacks


Bookmarks