java applet simple question

Discussion in 'OT Technology' started by doggfather, May 27, 2006.

  1. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    public class test {
    public static void main(String[] args) {
    drawImage("google.gif",0,0,200,200);
    }
    }

    I want to write an applet that displays an image "google.gif" in this case with height of 200 and width of 200 starting from the origin at 0,0
     
  2. Joe_Cool

    Joe_Cool Moderator

    Joined:
    Jun 30, 2003
    Messages:
    313,267
    Likes Received:
    6,083
    Here's a skeleton for an applet. You do your drawing in paint(), and start() and init() are for startup and pre-run initialization, respectively. It's more complicated than that, but I can't really get into the details right now. :o

    Code:
    /*
     * SampleApplet.java
     */
    
    import javax.swing.JApplet;
    import java.awt.Graphics;
    
    public class ShapesApplet extends JApplet
    {
    	//Graphics g;
    
    	public void init()
    	{
    	}
    
    	public void start()
    	{
    	}
    
    	public void paint(Graphics g)
    	{
    	}
    }
    
     
  3. hsmith

    hsmith OT Supporter

    Joined:
    Feb 24, 2002
    Messages:
    131,430
    Likes Received:
    9,122
    Location:
    Your mother.
    applets are so 1997
     
  4. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    import javax.swing.JApplet;
    import java.awt.Graphics;
    public class ShapesApplet extends JApplet
    {
    public void init()
    {
    }
    public void start()
    {
    }
    public void paint(Graphics g)
    {
    g.setBackground(255,255,0);
    }
    }



    how come this wont compile?

    i want the background of the applet to have the color 255,255,0
     
  5. Joe_Cool

    Joe_Cool Moderator

    Joined:
    Jun 30, 2003
    Messages:
    313,267
    Likes Received:
    6,083
    Make sure the name of the class and the filename are the same. I accidentally left my program name as the class name, but changed the filename in the comment at the top. :noes:
     
  6. codemartinet

    codemartinet lucky strikes

    Joined:
    May 25, 2006
    Messages:
    95
    Likes Received:
    0
    Location:
    Newark, DE
    you might want to look into Servlets and JSP pages if all you want to do is display a static image.

    what is it that you eventually want to do?
     

Share This Page