don't know how to put images


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: don't know how to put images

  1. #1
    Join Date
    Jan 2005
    Posts
    4

    Question don't know how to put images

    I'm doing a project for class and I have a few questions
    1. I need code to output an image to the screen in a "ready to program" type of thing(console)?
    2. how would you convert these lines from an applet to be able to be used in an HSA console application template?

    import javax.swing.*;

    public class AnimationApplet extends JApplet
    {
    public void init ()
    {
    ImageIcon icon = new ImageIcon ("images/rolling.gif"); // animated gif
    getContentPane ().add (new JLabel (icon));
    }
    }

    Thank you

  2. #2
    Join Date
    Jan 2005
    Posts
    4
    ok well unfortunately I found out that you can't put images using a console. so I need some help converting a program from a console type syntax to an applet type syntax. Here is my program

    import java.awt.*;
    import hsa.Console;

    public class License
    {
    static Console c; // The output console

    public static void main (String[] args)
    {
    c = new Console ();

    //variable declarations
    String license, day, anykey;
    String contin = " ";
    int month, year, sex;

    //text color and background color
    c.fillRect (1, 1, 800, 800);
    c.setTextBackgroundColor (Color.black);
    c.setColor (Color.black);
    c.setTextBackgroundColor (Color.black);
    c.setTextColor (Color.white);

    //Intro Screen
    c.print (" ", 40 - "Analysis of a Driver's License Number".length () / 2);
    c.println ("Analysis of a Driver's License Number");
    c.setColor (Color.black);
    c.println ("");
    c.println ("This program will analyze your driver's license and give you a wealth of ");
    c.println ("information. It will tell you whethere you are old enough to actually own a");
    c.println ("license. It will also determine the year you were born. This is done using the");
    c.println ("10th and 11th digits of your license number. The date of your birth is found by");
    c.println ("using the last two digits in your license number. The month is determined by");
    c.println ("the 12th and 13th digits. Your sex can also be determined using the 12th digit.");
    c.println ("");

    //go to next screen
    c.println ("Please type a letter and press 'Enter' to continue.");
    anykey = c.readString ();
    c.clear ();

    while (true)
    {
    //prompt screen
    c.print (" ", 40 - "Enter Information".length () / 2);
    c.println ("Enter Information");
    c.println ("");
    c.println ("Please enter your license number exactly as it appears on your license:");
    license = c.readString ();
    c.println ("");

    //go to next screen
    c.println ("Please type a letter and press 'Enter' to continue.");
    anykey = c.readString ();
    c.clear ();

    //variable conversions
    year = Integer.parseInt ("19" + license.substring (9, 11));
    day = license.substring (13);
    sex = Integer.parseInt (license.substring (11, 12));
    month = Integer.parseInt (license.substring (12, 13));

    c.print (" ", 40 - "Your Information".length () / 2);
    c.println ("Your Information");
    c.println ("");
    if (2005 - year < 16)
    {
    c.println ("You are not old enough to have a valid Driver's license.");
    c.println ("");
    }
    else
    {
    c.println ("You are old enough to have a license.");
    switch (sex)
    {
    case 0:
    c.println ("You are male.");
    switch (month)
    {
    case 1:
    c.println ("You were born in January.");
    break;
    case 2:
    c.println ("You were born in February.");
    break;
    case 3:
    c.println ("You were born in March.");
    break;
    case 4:
    c.println ("You were born in April.");
    break;
    case 5:
    c.println ("You were born in May.");
    break;
    case 6:
    c.println ("You were born in June.");
    break;
    case 7:
    c.println ("You were born in July.");
    break;
    case 8:
    c.println ("You were born in August.");
    break;
    case 9:
    c.println ("You were born in September.");
    break;
    }
    break;
    case 1:
    c.println ("You are male.");
    switch (month)
    {
    case 0:
    c.println ("You were born in October.");
    break;
    case 1:
    c.println ("You were born in November.");
    break;
    case 2:
    c.println ("You were born in December.");
    break;
    }
    break;
    case 5:
    c.println ("You are female.");
    switch (month)
    {
    case 1:
    c.println ("You were born in January.");
    break;
    case 2:
    c.println ("You were born in February.");
    break;
    case 3:
    c.println ("You were born in March.");
    break;
    case 4:
    c.println ("You were born in April.");
    break;
    case 5:
    c.println ("You were born in May.");
    break;
    case 6:
    c.println ("You were born in June.");
    break;
    case 7:
    c.println ("You were born in July.");
    break;
    case 8:
    c.println ("You were born in August.");
    break;
    case 9:
    c.println ("You were born in September.");
    break;
    }
    break;
    case 6:
    c.println ("You are female.");
    switch (month)
    {
    case 0:
    c.println ("You were born in October.");
    break;
    case 1:
    c.println ("You were born in November.");
    break;
    case 2:
    c.println ("You were born in December.");
    break;
    }
    break;
    }
    c.println ("You were born on the " + day + ".");
    c.println ("You were born during " + year + ".");
    c.println ("");
    }
    c.println ("Would you like to continue? Type 'N' to exit.");
    contin = c.readString ();
    if (contin.equals ("No"))
    break;
    c.clear ();
    }

    // Place your program here. 'c' is the output console
    } // main method
    } // License class

  3. #3
    Join Date
    Jan 2005
    Posts
    4
    Frames are also a possibility, but I'm don't know how to create them. Any help would be great.

  4. #4
    Join Date
    Sep 2004
    Posts
    150
    I'm not huge on graphics, but they do have various types of documents that can accomodate text and graphics.

    You should use a JTextPane or a JEditorPane.

    Here is a tutorial on them with an example program and pictures:




    http://java.sun.com/docs/books/tutor...ents/text.html

  5. #5
    Join Date
    Jan 2005
    Posts
    4
    i went through the tutorial and well I still need to know a few things, I'm not exactly sure how to put images and how do I manipulate the text?

  6. #6
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Here is at least the "how to boil an egg" -version of a JFrame for
    selecting and displaying images
    Attached Files Attached Files
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center