Applets..


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Applets..

  1. #1
    Join Date
    Sep 2004
    Posts
    37

    Applets..

    I need to draw a few hundred asterisks at random places and in random colors, then write my name over the top. I need to pass in my name to the applet as a PARAM from the html page. I think I know how to do this but I have no idea how to draw the random asterisks in random colors. ONce again any help would be much appreciated, everyone has been great so far.


    Steve

  2. #2
    Join Date
    Sep 2004
    Posts
    37
    O.K, here is what I have so far:

    import java.awt.*;
    import java.applet.*;

    public class NameInLights extends Applet
    {
    Font header= new Font("SanSerif",Font.BOLD,24);
    String text;

    public void init()
    {
    text= getParameter("message");
    if(text==null)
    text="nothing to say";
    }

    public void paint(Graphics g)
    {
    g.setFont(header);

    for(int i=0;i<100;i++);
    {
    int x = (int)(Math.random() * 399);
    int y = (int)(Math.random() * 399);

    int red = (int)(Math.random() * 256); //random rgb values
    int green = (int)(Math.random() * 256);
    int blue = (int)(Math.random() * 256);
    Color asterisk = new Color(red,green,blue);
    g.setColor(asterisk);
    g.drawString("*",x,y);
    }

    g.drawString(text, 100,100);

    }


    };

    And here is my HTML code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD>

    <BODY>


    Applet output:</P>


    APPLET CODE="NameInLights" WIDTH="400" HEIGHT="400">
    <PARAM NAME = message VALUE="STEVE">
    </APPLET></P>
    </BODY>
    </HTML>

    ------------------------------------

    It all compiles O.K but I get this message in my MSDOS window:

    Warning: <Param> tag outside <applet> ... </applet>.

    Does anyone know what this means and how I could possibly get my program to work. Thanks for your time.
    Cheers
    Steve

  3. #3
    Join Date
    Sep 2004
    Posts
    37
    Problem solved!
    Cheers
    Steve

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