Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Frames - Using and creating (+another question)

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Re: Moar Questions! (By Sea)

    Firstly let me introduce myself:
    Hello Fellow Java-ers :P

    Now that its out of the way () let me start:
    I have seen a GOOD programmer do his Ludum Dare challenge in java. It inspired me to start writing in java, and as i love coding and programming (many things with actionscript 2) i thought it would be a good start to learn java (naturally...

    I will post in this thread with continual questions

    Thanks and much appreciated ^^
    Last edited by 12sea21; September 1st, 2011 at 12:58 AM. Reason: title etc.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Frames - Using and creating (+another question)

    public static void main(String[] args)
    is a method called 'main'. It has a 'void' return type which means it doesn't return anything, so can't be used on the RHS (Right Hand Side) of assignments - you can't say "x = main(...)". It is 'static' meaning that you do not have to instantiate (create a new object) its class in order to use it. If it was declared in a class called "MyApp", you would invoke it as "MyApp.main(...)". While you can invoke a static method on an instance of a class, it is regarded as bad practice. It's 'public' so that any code from anywhere which can load your class can invoke main(...).

    The method 'signature' above is the specific method the JVM looks for when you start your Java code with "java MyApp". The JVM loads, then loads your MyApp class, then it invokes MyApp.main(...). The 'String[]' is the type of the only argument to main - args - an 'array of Strings'. If you start your JVM like this: "java MyApp apple orange 42" then args willl be an array of length 3. args[0] will be "apple", args[1] will be "orange" and args[2] will be "42". Note that "42" is a String of two characters, not a number.

    What is the double xx, double yy, double zz. (examples)
    One question at a time!
    Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)

  3. The Following User Says Thank You to Sean4u For This Useful Post:

    12sea21 (August 23rd, 2011)

  4. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Frames - Using and creating (+another question)

    You might not like this, but the best advice I can give you is to start slower. Work your way through the basic tutorials, which will explain methods and classes and Objects and data types, and only when you really understand that stuff, then think about working on the GUI.

    If I were you, I'd start here: The Java™ Tutorials
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #4
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Frames - Using and creating (+another question)

    Olla guys! I have returned with MOAR question(s):
    My question is, what is the difference between printf and println (i know that f stands for formatted)

    SOLVERED: Print Ln is print line
    Last edited by 12sea21; August 28th, 2011 at 03:58 AM.

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Frames - Using and creating (+another question)

    What did the API tell you?

    Recommended reading: PrintStream (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Frames - Using and creating (+another question)

    Thank you sir

    I have another question (you like how i keep my questions in one thread?):
    I have a program that tells the person to type in a number, this number with another one will be summed and printed to the user.

    I would like to restrict the person such as when they type a letter it would say "Please type a valid number!"
    I used the switch(number) and i want case(1-999). What i really want is "Type a number from #1 TO #999" and if they do not i would do
    default:
        System.out.println("Please input a valid number!");
        break;
    which prints "Enter a valid number!"

    How do i do this 'To' ?

  8. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: Frames - Using and creating (+another question)

    You will need a loop.
    loop {
        prompt user for input;
        if input is valid {
            break loop
        }
    }
    Improving the world one idiot at a time!

  9. #8
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Frames - Using and creating (+another question)

    Hmm.. ok ill try that when i get to my learning stage with loops cheers Junky! ^^

  10. #9
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Frames - Using and creating (+another question)

    @Junky: Thanks, but i did it as such:
    if(fnum>=1 && fnum<= 999){
    And it works

    I have another question, if i want to call back on this method because the user has inputed an invalid argument, how do i do that? because it was hard to call my main class which calls my secondary, and i cant use my main to test the secondary's method.
    This is the general code:
    if(fnum>=1 && fnum<= 999){
     
    			System.out.println("And a second number please, same restrictions");
    			snum = name.nextDouble();
    			Math.round(snum);
    			if(snum>=1 && snum<=999){
     
    				tot = snum + fnum;
    				prod = snum*fnum;
     
    				System.out.print("Thanks " + sea + ". I will now take both your numbers, " + fnum);
    				System.out.println(" and " + snum + ", and add them. ");
    				System.out.println(tot + " is the sum of both numbers; " + prod + " is the product of the two :D");
    				System.out.println("Thank you," + sea + ", for using SillyDodo(tm) Media! Enjoy the rest of your day!");
    				System.out.println("To restart type in 'Restart' without the inverted commas!");
    				rest = restart.nextLine();
     
    			} else {
    				System.out.println("Game Over... mate!");
    			}
    		} else {
    			System.out.println("Game Over... mate!");
    		}
    and i want to restart when the user types 'Restart'.

    Another question:
    How do I check if the inputted argument is a number or not?
    For
    System.out.println("And a second number please, same restrictions");
    			snum = name.nextDouble();
    			Math.round(snum);
    			if(snum>=1 && snum<=999){
    I want to check if snum is also a number or not... do i do
    if(snum != double){
    System.out.println("You need a valid number! Letters are not numbers!");

    Thank you I appreciate your support.

    p.s. is it annoying that im asking so many questions?
    Last edited by 12sea21; September 1st, 2011 at 01:01 AM.

  11. #10
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: Frames - Using and creating (+another question)

    Same advice as above. Use a loop.
    Improving the world one idiot at a time!

  12. #11
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Frames - Using and creating (+another question)

    How do i check if they entered a string or a double/integer ?

Similar Threads

  1. Creating and implementing class for creating a calendar object
    By kumalh in forum Object Oriented Programming
    Replies: 3
    Last Post: July 29th, 2011, 09:40 AM
  2. Creating New File types question.
    By GodspeedPR in forum Java Theory & Questions
    Replies: 1
    Last Post: July 1st, 2011, 10:05 AM
  3. Creating subsequent frames in java with Jframe
    By bondage in forum AWT / Java Swing
    Replies: 3
    Last Post: April 11th, 2011, 08:28 AM
  4. Switching between frames from a seperate class
    By kurt-hardy in forum AWT / Java Swing
    Replies: 4
    Last Post: February 14th, 2011, 04:19 AM
  5. GIF frames
    By vsector in forum AWT / Java Swing
    Replies: 0
    Last Post: April 15th, 2010, 06:25 PM