Results 1 to 2 of 2
  1. #1
    D34N0 is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default Problem Setting offscreen background

    Hi

    I'm trying to create an applet with an image moving down the screen which i have been able to do, but when i try to set background of the offscreen image i get the following when compiling : symbol : method setBackground(java.awt.Color). Is there another way to set the offscreen background. Here is the code.
    Many Thanks
    Dean
    PHP Code:
    import java.awt.*;
    
    public class KelvinIndexLogo extends java.applet.Applet implements Runnable {
    	// Define Objects & Variables
    	Image logo, workspace;
    	Graphics offscreen;
    	Thread runner;
    	
    	int logoY = 0;
    	int logoStop;
    	// Background RGB values
    	int backRed   = 221;
    	int backGreen = 221;
    	int backBlue  = 221;
    	boolean firstRun = true;
    
    	
    	public void init() {
    		String imageName = getParameter("logo");
    		setBackground(new Color(backRed, backGreen, backBlue));
    		
    		// Get the logo image if the logo parameter has been specified
    		if(imageName != null) {	
    			logo = getImage(getCodeBase(), imageName);
    		}
    	}
    	
    	public void start() {
    		if(runner == null) {
    			runner = new Thread(this);
    			runner.start(); 
    		}
    	}
    	
    	public void stop() {
    		if(runner != null) {
    			runner = null;
    		}
    	}
    	
    	public void run() {
    		// Move the Logo down from the top of the applet
    		Thread thisThread = Thread.currentThread();
    		while(runner == thisThread) {
    			repaint();
    			try{
    				Thread.sleep(50);
    			}catch(InterruptedException e){}
    			
    			// Would not get the correct image height in the init method
    			// therefore created first run bolean to set the start & Stop points
    			if(firstRun) {
    				logoY    = 0 - logo.getHeight(this);
    				logoStop = getSize().height - logo.getHeight(this); 
    				firstRun = false;
    			}
    			
    			logoY++;
    			if(logoY == logoStop) {
    				runner = null;
    			}
    			
    		}
    	}
    	
    	public void paint(Graphics screen) {
    		// Create the workspace & offscreen objects on each iteration so
    		// image is cleared every time and no black trail appears on text
    		workspace = createImage(getSize().width, getSize().height);
    		offscreen = workspace.getGraphics();
    		
    		offscreen.setBackground(this.getBackground());
    		
    		if(logo != null) {
    			offscreen.drawImage(logo, 0, logoY, null);
    		}
    		
    		// Draw workspace to screen & set background colour
    		
    		screen.drawImage(workspace, 0,0, this);
    		
    	}
    	
    	public void update(Graphics screen) {
    		paint(screen);
    	}
    }

  2. #2
    D34N0 is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default

    Problem Solved...

    Create a filled rectangle the size of the image.

    Thanks to CeciNEstPasUnProgrammeur on the Sun Developer Forums for that one.

Similar Threads

  1. Center background image
    By Floetic in forum AWT / Swing
    Replies: 1
    Last Post: 04-24-2008, 06:50 PM
  2. Replies: 2
    Last Post: 03-24-2008, 06:29 AM
  3. Set the background in Java
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:13 AM
  4. Background image in java
    By toby in forum AWT / Swing
    Replies: 1
    Last Post: 07-29-2007, 08:15 AM
  5. Why this image background is black ?
    By samson in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 05:24 AM

Posting Permissions

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