Results 1 to 2 of 2
  1. #1
    HalfAZN is offline Member
    Join Date
    Apr 2012
    St. Louis, MO
    Rep Power

    Question Help with moving a black fillRect across the screen (Applet)

    My code compiles and runs perfectly, however nothing appears on the screen when I run the applet. Here is the code:
    Java Code:
    //This applet displays a message moving horizontally
    //across the screen.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Bannerz extends JApplet
      implements ActionListener
      private int xPos, yPos; //hold the coordinates of the banner
      public void init()
        Container c=getContentPane();
        yPos=c.getHeight() /2;
        Timer clock=new Timer(30, this); //fires every 30 milliseconds
      //called automatically after a repaint request
      public void paint (Graphics g)
        g.fillRect(80, 40, xPos, yPos);
      //called automatically when the timer fires
      public void actionPerformed (ActionEvent e)
          Container c=getContentPane();
          //Adjust the horizontal position of the banner:
          if (xPos<-100)
           //Set the vertical position of the banner:
           yPos=c.getHeight() /2;
    Last edited by HalfAZN; 08-27-2012 at 08:11 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Help with moving a black fillRect across the screen (Applet)

    Don't draw directly in the JApplet but rather draw in a JPanel's paintComponent method and have the JApplet display the JPanel in its contentPane.

Similar Threads

  1. Robot screen capture returns black image
    By Jaeela in forum New To Java
    Replies: 1
    Last Post: 11-30-2012, 10:51 AM
  2. Ball moving across the screen?
    By Slicknife in forum New To Java
    Replies: 1
    Last Post: 05-29-2012, 11:53 PM
  3. problem about Unknown Black Screen
    By lawlawlaws in forum Java 2D
    Replies: 1
    Last Post: 02-02-2012, 03:08 AM
  4. Problem about Black Screen
    By lawlawlaw in forum New To Java
    Replies: 2
    Last Post: 01-26-2012, 05:18 PM
  5. Moving an icon on screen?
    By TP-Oreilly in forum New To Java
    Replies: 5
    Last Post: 12-29-2011, 12:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts