Results 1 to 4 of 4
  1. #1
    elvis0288 is offline Member
    Join Date
    Jan 2012
    Posts
    21
    Rep Power
    0

    Default StdDraw.setXscale i have problems with this

    ok my problem is that i am trying to make a polygon at the top of the screen and i have been looking about how the xscale and yscale and the filledpolygon work but i cannot still make it work this is my code
    Java Code:
    package project1;
    
    import java.util.ArrayList;
    
    public class TargetGallery
    {
    	private double x[] = {0,50,0,50};
    	private double y[] = {0,50,0,50};
    	
    	public TargetGallery()
    	{
    		
    	}
    	private void buildWorld()
    	{
    		StdDraw.setXscale(0, 200);
            StdDraw.setYscale(0, 200);
            StdDraw.setPenColor(StdDraw.BLUE);
    		StdDraw.filledPolygon(x,  y);
    	}
    	
    	private void drawShooter()
    	{
    		
    	}
    	
    	private void createTargets()
    	{
    		
    	}
    	
    	private void simulate()
    	{
    		
    	}
    	
    	private void run()
    	{
    		TargetGallery tg = new TargetGallery();
    		tg.buildWorld();
    	}
    	
    	public static void main(String[] args)
    	{
    		TargetGallery tg = new TargetGallery();
    		tg.run();
    	}
    }
    i need to make like a sky so it woul be just at the top of it and green for grass the reamining of the screen can somebody at least explain me how the x and y arrays work and the setXscale please thank you

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: StdDraw.setXscale i have problems with this

    The first thing I see is that the code creates a new TargetGallery and then immediately creates a second TargetGallery object.
    Why does it create two objects?

    What does the StdDraw class do? You'll have to read the API doc for that class and its methods so you know how to use it.

  3. #3
    elvis0288 is offline Member
    Join Date
    Jan 2012
    Posts
    21
    Rep Power
    0

    Default Re: StdDraw.setXscale i have problems with this

    yeah i fix that i was just using that to see if it was working just to test now it is like this
    Java Code:
    package project1;
    
    import java.awt.Color;
    import java.util.*;
    import javax.swing.*;
    
    public class TargetGallery
    {
    	private ArrayList<Target> targets = new ArrayList<Target>();
    	private double x[] = {0,250,250,0};
    	private double y[] = {200,200,250,250};
    	private double x1[] = {0,250,250,0};
    	private double y1[] = {0,0,200,200};
    	private double x2[] = {125,129,129,125};
    	private double y2[] = {0,0,4,4};
    	static TargetGallery tg = new TargetGallery();
    	
    	public TargetGallery()
    	{
    		
    	}
    	private void buildWorld()
    	{
    		StdDraw.setXscale(0, 250);
            StdDraw.setYscale(0, 250);
            StdDraw.setPenColor(StdDraw.BLUE);
    		StdDraw.filledPolygon(x,  y);
    		StdDraw.setPenColor(StdDraw.GREEN);
    		StdDraw.filledPolygon(x1,y1);
    		//int x = 125;
    		//int y = 10;
    		//StdDraw.picture(75, 130, "bath.jpeg", 450, 285);
    		//StdDraw.picture(125, 80, "zombie2.png", 80, 60);
    		//StdDraw.picture(x, y, "weapon.png", 80, 45);
    	}
    	
    	private void drawShooter()
    	{
    		StdDraw.setXscale(0, 250);
            StdDraw.setYscale(0, 250);
            StdDraw.setPenColor(StdDraw.BLACK);
    		StdDraw.filledPolygon(x2, y2);
    	}
    	
    	private void createTargets()
    	{
    		double ax = 125;
    		double ay = 175;
    		double aradius = 7;
    		String input = JOptionPane.showInputDialog("Type an integer" +
    				" between 2 and 5");
    		int number = Integer.parseInt(input);
    		
    		
    		for(int i = 0; i < number; i++)
    		{
    			Target targ = new Target(ax, ay, aradius);
    			targets.add(targ);
    			Random rand = new Random();
    			ax = rand.nextInt(300) + 10;
    			targ.drawAlive();
    			
    		}
    		
    	}
    	
    	public void run()
    	{
    		tg.buildWorld();
    		tg.drawShooter();
    		tg.createTargets();
    		tg.simulate();
    		
    	}
    	
    	private void simulate()
    	{
    		
    		RifleSite rifle = new RifleSite();
    		rifle.drawRifleSite();
    		
    		
    		while(true)
    		{
    			
    			if (StdDraw.hasNextKeyTyped())
    			{
    				char ch = StdDraw.nextKeyTyped();
    				if (ch == 'f')
    				{
    					
    				}
    			}
    		}
    	}
    	
    	public static void main(String[] args)
    	{
    		tg.run();
    	}
    }
    i have problem to set x and y because if i put 0.0 and 1.0 is not going to show my circle or nothing in the screen so i have to put 0 400 and things like that

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: StdDraw.setXscale i have problems with this

    What does the StdDraw class do? You'll have to read the API doc for that class and its methods so you know how to use it.

Similar Threads

  1. need help with several problems
    By tidus1103 in forum New To Java
    Replies: 4
    Last Post: 03-11-2011, 01:10 AM
  2. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  3. RMI Problems
    By michaeln31 in forum New To Java
    Replies: 4
    Last Post: 10-23-2010, 12:52 PM
  4. Gui problems
    By bulldog in forum Advanced Java
    Replies: 1
    Last Post: 12-11-2009, 12:35 PM
  5. problems with JPA
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 05:34 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
  •