Results 1 to 2 of 2
- 08-27-2012, 08:06 PM #1
Member
- Join Date
- Apr 2012
- Location
- St. Louis, MO
- Posts
- 32
- Rep Power
- 0
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(); c.setBackground(Color.WHITE); xPos=c.getWidth(); yPos=c.getHeight() /2; Timer clock=new Timer(30, this); //fires every 30 milliseconds clock.start(); } //called automatically after a repaint request public void paint (Graphics g) { super.paint(g); g.setColor(Color.black); 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: xPos--; if (xPos<-100) { xPos=c.getWidth(); } //Set the vertical position of the banner: yPos=c.getHeight() /2; repaint(); } }Last edited by HalfAZN; 08-27-2012 at 08:11 PM.
-
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
-
Robot screen capture returns black image
By Jaeela in forum New To JavaReplies: 1Last Post: 11-30-2012, 09:51 AM -
Ball moving across the screen?
By Slicknife in forum New To JavaReplies: 1Last Post: 05-29-2012, 11:53 PM -
problem about Unknown Black Screen
By lawlawlaws in forum Java 2DReplies: 1Last Post: 02-02-2012, 02:08 AM -
Problem about Black Screen
By lawlawlaw in forum New To JavaReplies: 2Last Post: 01-26-2012, 04:18 PM -
Moving an icon on screen?
By TP-Oreilly in forum New To JavaReplies: 5Last Post: 12-28-2011, 11:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks