Displaying images

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mike131
    New Member
    • Sep 2007
    • 12

    #1

    Displaying images

    first i am sorry if my english is not that good,
    i have a little question. i have begun to teech myself Java just few monthes ago and i have a little problem...
    how can i print chickweeds on the screen? i mean how can i let the user who uses my application trace the number of the chickweeds that he wants to print on the screen (and than the computer would print them for him)???

    thanks alot!
    mike
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by mike131
    first i am sorry if my english is not that good,
    i have a little question. i have begun to teech myself Java just few monthes ago and i have a little problem...
    how can i print chickweeds on the screen? i mean how can i let the user who uses my application trace the number of the chickweeds that he wants to print on the screen (and than the computer would print them for him)???

    thanks alot!
    mike
    Your English vocabulary is way better than mine: I didn't even know what
    'chickweed' was, I had to look it up. Do you want to show their image on the
    screen? Have you looked at the Icon and JLabel classes?

    kind regards,

    Jos

    Comment

    • mike131
      New Member
      • Sep 2007
      • 12

      #3
      Originally posted by JosAH
      Your English vocabulary is way better than mine: I didn't even know what
      'chickweed' was, I had to look it up. Do you want to show their image on the
      screen? Have you looked at the Icon and JLabel classes?

      kind regards,

      Jos
      hoo hii!
      thanks alot (for your quick asnwer)...
      well i havnt looked there yet, and mmm yes i mean to show their picture on the screen i belive that for the picture itself i just need to use "*"... but the problem is how can the user trace their amount??
      i thought that i can use a loop, (for loop):

      bla bla bla bla...... // The lines before my main example LOL
      int amount;
      amount = info.nextInt();
      for (i=0;i<amount;i ++)
      {
      System.out.prin t("*");
      }
      am i wrong??

      actually i "came" from the Macromedia/Adobe "flash world", so my ActionScript is perfect but Java is annoing!! (LOL :))

      Comment

      • mike131
        New Member
        • Sep 2007
        • 12

        #4
        Originally posted by mike131
        hoo hii!
        thanks alot (for your quick asnwer)...
        well i havnt looked there yet, and mmm yes i mean to show their picture on the screen i belive that for the picture itself i just need to use "*"... but the problem is how can the user trace their amount??
        i thought that i can use a loop, (for loop):

        bla bla bla bla...... // The lines before my main example LOL
        int amount;
        amount = info.nextInt();
        for (i=0;i<amount;i ++)
        {
        System.out.prin t("*");
        }
        am i wrong??

        actually i "came" from the Macromedia/Adobe "flash world", so my ActionScript is perfect but Java is annoing!! (LOL :))
        oh my god! it's alive!!!!!!!!
        can i write here the final script??

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by mike131
          oh my god! it's alive!!!!!!!!
          can i write here the final script??
          Of course you can if you want. Just try to wrap the code in code tags when you do so.

          P.S Changed the thread title.

          Comment

          • mike131
            New Member
            • Sep 2007
            • 12

            #6
            hye everyone...
            well,here is one of my first Java applications:

            Code:
            import java.util.Scanner;
            public class Card
            {
            public static void main(String[] args)
            {
            	Scanner info = new Scanner(System.in); 
            	int i; 
            	int amount; 
            	String name; 
            	String nameLast; 
            	int phone; 
            	String adress; 
            	int adressNum; 
            		
            	System.out.println("please insert your first name");
            	name = info.next(); 
            		
            	System.out.println("please insert your last name");
            	nameLast = info.next(); 
            		
            	System.out.println("please insert your phone number");
            	phone = info.nextInt(); 
            		
            	System.out.println("please insert your adress");
            	adress = info.next(); 
            		
            	System.out.println("please insert the number of your house");
            	adressNum = info.nextInt(); 
            		
            	String nameAndLast = "My name is: " + name + " " + nameLast;
            	int nameAndLastName = nameAndLast.length(); 
            		
            	System.out.println(nameAndLast);
            	System.out.println("phone number: " + phone);
            	System.out.println("Adress: " + adress + " " + adressNum);
            
            	amount = nameAndLastName + 3; 
            		
            
            	for(i=0;i<amount;i++)
            	{
            	System.out.print("*");
            	}
            		
            }
            }
            do you have suggestion for making this clumsy script shorter??

            thanks alot!
            mike

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Does it work? Did you try to compile and run it?

              kind regards,

              Jos

              Comment

              • mike131
                New Member
                • Sep 2007
                • 12

                #8
                ohh yes! i forgot to say :)
                it works perfectly!

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  You can start by declaring variables closest to where they are used.
                  Why do
                  [CODE=java]String name;
                  ....
                  name = info.next(); [/CODE]

                  When you can simply do

                  [CODE=java]String name = info.next(); [/CODE]

                  That "declare all variables first" is only required in C. In Java you can declare variables as and when you need them.
                  That should make the code considerably shorter.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Also, instead of cramming everything in one single method think of separate
                    methods that do just one single task, i.e. instead of the statement combination
                    for prompting the user for something:

                    [code=java]
                    System.out.prin tln("please insert your first name");
                    name = info.next();
                    [/code]

                    Think of something like this:

                    [code=java]
                    String prompt(Scanner scanner, String prompt) {
                    System.out.prin tln(prompt);
                    return scanner.next();
                    }
                    ...
                    name= prompt(info, "please insert your first name");
                    [/code]

                    This won't necessarily reduce the line count of your code but it certainly structures
                    the functionality of it all quite a bit more.

                    kind regards,

                    Jos

                    Comment

                    • mike131
                      New Member
                      • Sep 2007
                      • 12

                      #11
                      thank you all!
                      i have never seen so supporting guys like you before!

                      Comment

                      Working...