Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2007, 04:38 PM
Member
 
Join Date: Jul 2007
Posts: 2
D34N0 is on a distinguished road
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 logoworkspace;
    
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(backRedbackGreenbackBlue));
        
        
// 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    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().widthgetSize().height);
        
offscreen workspace.getGraphics();
        
        
offscreen.setBackground(this.getBackground());
        
        if(
logo != null) {
            
offscreen.drawImage(logo0logoYnull);
        }
        
        
// Draw workspace to screen & set background colour
        
        
screen.drawImage(workspace0,0this);
        
    }
    
    public 
void update(Graphics screen) {
        
paint(screen);
    }

Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-14-2007, 12:46 PM
Member
 
Join Date: Jul 2007
Posts: 2
D34N0 is on a distinguished road
Problem Solved...

Create a filled rectangle the size of the image.

Thanks to CeciNEstPasUnProgrammeur on the Sun Developer Forums for that one.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Center background image Floetic AWT / Swing 1 04-24-2008 06:50 PM
GUI... setting my background to an image, im using a JFrame newtojava7 New To Java 2 03-24-2008 06:29 AM
Set the background in Java barney New To Java 1 08-07-2007 08:13 AM
Background image in java toby AWT / Swing 1 07-29-2007 08:15 AM
Why this image background is black ? samson Java 2D 1 07-17-2007 05:24 AM


All times are GMT +3. The time now is 10:48 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org