The Forum Site - Join the conversation
Forums: Technology & Internet:
Programming

Java

Reply to Topic
AuthorMessage
tonkz On February 13, 2014




Croydon, United Kingdom
#1New Post! Nov 04, 2009 @ 13:28:38
i know this is proper simple java. It's only practise stuff for if statements with Joptionpane, but what puzzles me is why does the program compile when i'm using 'System.out.println' but does not compile when im using the 'JOptionPane.showMessageDialog'


For example (from code below)=
________________________________
if (input1.equals ("M" ))
{
JOptionPane.showMessageDialog("Monday" )
}
________________________________
instead of the 'System.out.println("Monday" ) being where JOptionPane.showMessageDialog is (in code above)



Code as stands = compiles fine
_____________________________________
import javax.swing.JOptionPane;
public class DaysOfWeek
{
public static void main(String[] args)
{

String input1 = JOptionPane.showInputDialog("Enter your input" ) ;

if (input1.equals ("M" ))
{
System.out.println ("Monday" ) ;
}
else if (input1.equals ("Tu" ))
{
System.out.println ("Tuesday" ) ;
}
else if (input1.equals ("W" ))
{
System.out.println ("Wednesday" ) ;
}
else if (input1.equals ("Th" ))
{
System.out.println ("Thursday" ) ;
}
else if (input1.equals ("F" ))
{
System.out.println ("Friday" ) ;
}
else if (input1.equals ("Sa" ))
{
System.out.println ("Saturday" ) ;
}
else if (input1.equals ("Su" ))
{
System.out.println ("Sunday" ) ;
}
else
{
System.out.println ("Enter the shortcut codes 'M' 'Tu' etc" ) ;
}

}
}
_____________________

sorry about the faces LOL
tonkz On February 13, 2014




Croydon, United Kingdom
#2New Post! Nov 25, 2009 @ 09:05:16
The answer is =


with a JOptionPane u have to display your output as =

if (input1.equals ("M " )
{
JOptionPane.showMessageDialog(null, "Monday" );
}

code is missing the null.

I cannot believe i had to answer my own question just in future LMAO
tonkz On February 13, 2014




Croydon, United Kingdom
#3New Post! Nov 25, 2009 @ 09:06:38
pro
cmh0114 On January 14, 2014




,
#4New Post! Jan 10, 2010 @ 21:00:03
That's good that you can answer your own question. It's very helpful to be able to do that.
However, this isn't exactly a site dedicated to programming, so you might have some trouble finding help here, if you can't answer your own question. Here are some pretty good programming collaboration resources:
daniweb.com
dreamincode.net
javaprogrammingforums.com
tonkz On February 13, 2014




Croydon, United Kingdom
#5New Post! Jan 25, 2010 @ 14:04:20
Thanks very much m8

The problem I had in this post was soooooooo easy compared to others I came across. I just seem to muddle through changing code, compiling thousands of times etc.

I will save the resources you have given. Thanks again
Iceman778 On December 19, 2010




Hyderabad, India
#6New Post! Apr 02, 2010 @ 15:49:24
i need to tell u that u really have a problem and the problem was you did not understand wat problem is
tonkz On February 13, 2014




Croydon, United Kingdom
#7New Post! Jan 30, 2012 @ 21:44:24
Oh, I understood what the problem was; It didn't compile = the problem.

I did not understand what the solution was.

Although good attempt at writing a sweet 1 liner :P although not particularly accurate.
Reply to Topic<< Previous Topic | Next Topic >>

1 browsing (0 members - 1 guest)

Quick Reply
Be Respectful of Others

      
Subscribe to topic prefs

Similar Topics
    Forum Topic Last Post Replies Views
New posts   Rants & Raves
Thu Nov 23, 2023 @ 19:51
21 8932
New posts   Religion
Sat Jun 09, 2012 @ 03:36
10 8233
New posts   US Elections
Fri Jul 24, 2020 @ 23:24
77 25057
New posts   Television
Mon Jan 21, 2013 @ 22:31
25 9007
New posts   Poetry
Sun Sep 16, 2012 @ 15:40
16 6692