Results 1 to 3 of 3
  1. #1
    IAM
    IAM is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Making my yellow stars bigger

    How can i make my yellow star bigger?
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    
    public class Sterrenhemel extends JPanel implements MouseWheelListener
    {
      private Ster yellowStar;
      private RodeSter redStar;
      private int bigger;
      Ster[] sterren = new Ster[100];
      private int red = 200;
      int xPositie[] = {0 + bigger,3 + bigger,12 + bigger,5 + bigger,8 + bigger,0 + bigger,-8 + bigger,-5 + bigger,-12 + bigger,-3 + bigger};
      int yPositie[] = {-13+ bigger,-4 + bigger,-4 + bigger,2 + bigger,11 + bigger,5 + bigger,11 + bigger,2 + bigger,-4 + bigger,-4 + bigger};
      
      
      public Sterrenhemel()
      {
    	  yellowStar = new Ster( xPositie , yPositie, 10, Color.yellow );
    	  redStar = new RodeSter( xPositie, yPositie, 10, new Color(red,0,0) );
    	  addMouseWheelListener(this);
    	  setFocusable(true);
    	  requestFocus();
      }
      
      public void paintComponent( Graphics g )
      {
        super.paintComponent( g );
        setBackground(Color.blue);
        for(int i = 0; i < sterren.length; i++)
        {
        	if(i < 50)
        	{
        		yellowStar.teken( g );
        	}
        	else
        	{
        		redStar.teken( g );
        	}
        }
      }
      
      public void mouseWheelMoved( MouseWheelEvent e )
    	{
    	  	yellowStar.evolueer();
    	  	redStar.evolueer();
    	  	repaint();
    	  	System.out.println(bigger);
    	}
    }
    Java Code:
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Polygon;
    import java.util.Random;
    
    public class Ster
    {
    	private int[]x = new int[10];
    	private int[]y = new int[10];
    	private int grootte;
    	private int bigger;
    	protected Color kleur; 
    	
      
      public Ster( int[]x, int[]y, int grootte, Color kleur )
      {
        this.x = x;
        this.y = y;
        this.grootte = grootte;
        this.kleur = kleur;
      }
    
      public void teken( Graphics g ) 
      {
    	Random generator = new Random();
    	int Width = generator.nextInt(900);
    	int Height = generator.nextInt(500);
    	Polygon mytri = new Polygon(x,y,grootte);
    	g.setColor( kleur );
        mytri.translate(Width, Height);
    	g.fillPolygon(mytri);
        mytri.translate(-Width, -Height);
      }
      
      public void evolueer()
    	{
    		if( bigger < 100 )
    		{
    			bigger = 2;
    		}
    		else
    		{
    		}
    		
    	}
    	
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    you could use the AffineTransform class! (Transforming Shapes, Text, and Images (The Java™ Tutorials > 2D Graphics > Advanced Topics in Java2D))

    somehting like:
    Java Code:
    	public void teken(Graphics g) {
    		Random generator = new Random();
    		int Width = generator.nextInt(900);
    		int Height = generator.nextInt(500);
    		Polygon mytri = new Polygon(x, y, grootte);
    		Graphics2D g2 = (Graphics2D) g;
    		AffineTransform saveOrig = g2.getTransform();
    		AffineTransform scale = new AffineTransform();
    		scale.scale(1.5, 1.5);
    		g2.transform(scale);
    		g.setColor(kleur);
    		mytri.translate(Width, Height);
    		g.fillPolygon(mytri);
    		mytri.translate(-Width, -Height);
    		g2.setTransform(saveOrig);
    	}
    or you have to use other coordinates!

  3. #3
    IAM
    IAM is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. project bigger then me
    By mac in forum New To Java
    Replies: 2
    Last Post: 02-19-2010, 03:14 PM
  2. bigger than long
    By scorp200 in forum New To Java
    Replies: 3
    Last Post: 12-06-2009, 08:17 AM
  3. stars
    By nalinda in forum New To Java
    Replies: 3
    Last Post: 08-25-2009, 12:48 PM
  4. Blinking stars
    By jholtt23 in forum New To Java
    Replies: 0
    Last Post: 02-19-2009, 06:38 AM
  5. Need help coding a rhombus in stars
    By LinxuS in forum New To Java
    Replies: 5
    Last Post: 10-18-2008, 01:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •