Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Location
    Seattle, WA
    Posts
    35
    Rep Power
    0

    Default Rotating image with an Applet

    I'm trying to rotate an image with Applet, but I'm having some problems.

    Java Code:
    package Cell;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    
    
    public class Shiznit_2 extends Applet implements Runnable {
    
    	private Image ship;
    	int width = 300; 
    	int height = 300; 
    	int x = width/2; 
    	int y = height/2; 
    	int dx; 
    	int dy;
    	double angle= 0.0; 
    	AffineTransform turn;
    
    	BufferedImage bi;
    	Graphics2D bs;
    	Thread t;
    	
    	public void start(){
    
            Thread gameThread = new Thread(this);
            gameThread.start();
    	}
    	
    	public void init() {
    		setSize(300, 300);
    		ship = getImage(getCodeBase(),"Cell/mito_0.gif");
    		dx=ship.getWidth(this);
    		dy=ship.getHeight(this);
    		turn = new AffineTransform();
    		
    		
    		 bi = (BufferedImage)createImage(WIDTH, HEIGHT);
    	        bs = bi.createGraphics();
    	}
    
    
    
    	public void run(){
    		
    		while(true)
    		{
    		
    			angle-=1;
    			
    
    			turn.translate(x, y);
    			turn.rotate(Math.toRadians(angle), (50), (50) );
    	
    		repaint();
    		}
    	}
    
    	public void paint(Graphics g) {
    		
    		update(g);
    		
    
    	}
    	
    	public void update(Graphics g)
    	{
    		Graphics2D g2 = (Graphics2D)g;
            
            bs.clearRect(0, 0, WIDTH, HEIGHT);
    
            bs.drawImage(ship, turn, this);
            g2.drawImage(bi, 0, 0, this);
            
            
           
    		
    	}
    
    	
    }

    Its supposed to spin the image using AffineTransform, but when I run it I just get a blank white screen.

    Some help or tutorials links would be nice!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Rotating image with an Applet

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help with Image Rotating?
    By Leospaceman in forum Java 2D
    Replies: 2
    Last Post: 05-31-2011, 02:48 PM
  2. Problem in rotating an image
    By newtoapplets in forum Java Applets
    Replies: 0
    Last Post: 02-28-2011, 06:12 AM
  3. Rotating Buffered Image distorts image
    By VortexSpin in forum Java 2D
    Replies: 1
    Last Post: 02-13-2011, 05:54 AM
  4. Rotating an image
    By lackofcolor in forum Java 2D
    Replies: 3
    Last Post: 02-27-2009, 11:54 PM
  5. Rotating Image?
    By sciguy77 in forum Java Applets
    Replies: 9
    Last Post: 02-17-2009, 01:47 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
  •