java target

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

java target

Post by shiznatix »

hey! does anyone here know how to draw a target (the kind you would shoot at) in java? any help would be great (fast help would be best) :lol:

what i have now:

Code: Select all

import java.awt.*;
import java.applet.*;

public class final_class extends Applet
{
	public void paint(Graphics g)
	{
		int dim = 0;
		int x = 0;
		int y = 0;
		for (int i = 10; i > 0; i--)
		{
			dim = i * 10;
			x   = dim / 2;
			y   = dim * 2;
			if ( i % 2 == 0)
				g.setColor (Color.red);
			else
				g.setColor (Color.blue);
			
			g.fillOval (x,y,dim,dim);//(y-axis, x-axis, height, width)
		}
		/*
		int dim = 0;
		
		for (int i = 0; i < 10; i++)
		{
			dim = i * 10;
				
			g2d.drawRoundRect(dim, dim, 50, 50, dim, dim);
		}
		*/
    }

}
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

this is what i came up with but its not near perfect. where did i go wrong_

Code: Select all

import java.awt.*;
import java.applet.*;

public class final_class extends Applet
{
	public void paint(Graphics g)
	{
		Dimension d = size();
		
		int dimw = 0;
		int dimh = 0;
		int x = 0;
		int y = 0;
		
		for (int i = 10; i < 18; i++)
		{
			dimh = i * d.height / 20;
			dimw = i * d.width / 20;
			
			x = (700 / i);
			
			g.drawOval (x,x,dimh,dimw);
		}
    }

}
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

miscellaneous? :P

awt was never my strongpoint in Java, so I can't help I am afraid :P
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I simply used gif images in one of my first shooter games ;)

http://timvw.madoka.be/programming/java/JSpace.zip
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ya sorry if i posted this in the wrong forum, i was not thinking. I turned in my last code there for my final but I believe that my teacher will be ok with it. stupid x - y axis crap, who needs it!?
Post Reply