4 Replies Latest reply: Jan 6, 2005 11:15 PM by 807596 RSS

    animation

    807596
      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
        • 1. Re: animation
          807596
          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
          • 2. Re: animation
            807596
            Frames are also a possibility, but I'm don't know how to create them. Any help would be great. 10 duke dollars up for grabs.
            • 3. Re: animation
              807596
              http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
              • 4. Re: animation
                807596
                I read the tutorial and I'm lost, how would I fit my program into that? Would I use a panel?