Computer Science Java Help?
Author |
Message |
jMarie
|
Posted: Sun Apr 24, 2011 10:06 pm Post subject: Computer Science Java Help? |
|
|
I have a project in which i don't get.. I have been working on it for days..
we are supposed to make the thing move around the frame for a number of times( eg. 5), then it will move diagonally (certain # of times) then across and down the centre of the frame then around a circle in the middle..
pls help..
here is my code so far:
import java.awt.*;
import javax.swing.*;
import java.awt.geom.AffineTransform;
public class NAME extends JApplet implements Runnable{
private double currentAngle;
int xRot;
int yrot;
int i=0;
final int N=50;
Image ImageBuffer=null;
Graphics GraImage=null;
int x=0;
int y=0;
//double angle;
public void init(){
//setBackground(Color.white);
}
public void start()
{
Thread th=new Thread(this);
//Thread starts
th.start ();
}
//square rotation around the frame
public void run()
{
//Thread Priority
Thread.currentThread().setPriority(Threa?
for(int countime=0;countime<4;countime++){
for( ;true;)
{
//1, right
while(x<=900)
{
x++;
repaint();
if(x==900)
{
x=900;
currentAngle=90;
}
try
{
//Stop Thread
Thread.sleep(1);
}
catch(InterruptedException ex)
{
//do nothing
}
}
//2, bottom
while(y<=650)
{
y++;
repaint();
if(y==650)
{
y=700;//700
currentAngle=180;
}
try
{
//Stop Thread
Thread.sleep(1);
}
catch(InterruptedException ex)
{
//do nothing
}
}
//3 ( left)
while(x>=50)
{
x--;
if(x==50)//50
{
x=0;//0
currentAngle=270;
}
repaint();
try
{
//Stop Thread
Thread.sleep(1);
}
catch(InterruptedException ex)
{
//do nothing
}
}
//4.. top
while(y>=50)
{
x++;
repaint();
if(y==50)
{
y=0;
currentAngle=0;
}
try
{
//Stop Thread
Thread.sleep(1);
}
catch(InterruptedException ex)
{
//do nothing
}
}
}
}
while(x>=0)
{
x++;
repaint();
try
{
//Stop Thread
Thread.sleep(2);
}
catch (InterruptedException ex)
{
//do nothing
}
}
}
public void paintF(Graphics g) {
// super.paintF(g);
Dimension d = size();
Image image2=Toolkit.getDefaultToolkit().getIm?
int w= image2.getWidth(this);
int h = image2.getHeight(this);
g.drawImage(image2,0,0,900,700, this);
Graphics2D g2d = (Graphics2D) g;
AffineTransform origXform = g2d.getTransform();
AffineTransform newXform = (AffineTransform) (origXform.clone());
/*int radius = 200;
double angle = 2*Math.PI*i/(double)N;
x = (int)( radius*Math.cos(angle) );
y = (int)( radius*Math.sin(angle) );*/
//xRot = this.getWidth()/2;
//yRot = this.getHeight()/2;
newXform.rotate(Math.toRadians(currentAn? y);
g2d.setTransform(newXform);
Image image=Toolkit.getDefaultToolkit().getIma?
g2d.drawImage(image,x,y,null);
}//end of action
public void update(Graphics g){
ImageBuffer = createImage(this.getWidth(),this.getHeig?
GraImage=ImageBuffer.getGraphics();
paintF(GraImage);
GraImage.dispose();
g.drawImage(ImageBuffer,0,0,this);
}
public void paint(Graphics g){
update(g);
}
public static void main(String[] args){
JFrame f =new JFrame("Animation");
f.setDefaultCloseOperation(JFrame.EXIT_O?
JApplet ap = new Underwater();
ap.init();
ap.start();
f.setSize(900,732);
f.add("Center", ap);
f.setLocation(65,0);
f.setVisible(true);
}}
the background pic is underwater
then the thing moving is a starfish |
|
|
|
|
|
Sponsor Sponsor
|
|
|
apython1992
|
Posted: Sun Apr 24, 2011 10:08 pm Post subject: RE:Computer Science Java Help? |
|
|
Can you edit your post using syntax tags?
code: | [syntax="Java"]
All code goes here
[/syntax]
|
|
|
|
|
|
|
jMarie
|
Posted: Mon Apr 25, 2011 2:02 pm Post subject: RE:Computer Science Java Help? |
|
|
it says "Can not edit a post that has been replied to." |
|
|
|
|
|
RandomLetters
|
Posted: Mon Apr 25, 2011 3:00 pm Post subject: RE:Computer Science Java Help? |
|
|
What don't you get or what do you need help with? |
|
|
|
|
|
apython1992
|
Posted: Mon Apr 25, 2011 4:05 pm Post subject: RE:Computer Science Java Help? |
|
|
If you can't edit your original post, just make a new post with the code or syntax tags. And as RandomLetters has mentioned. we could do with a bit more problem specifics. What exactly are you stuck on? |
|
|
|
|
|
|
|