Results 1 to 6 of 6
  1. #1
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default Polygon won't show up

    I made this code on one computer, then I saved the code in a text file so I could re-copy the text and make a new java file. I did this and everything compiled good, but when I run the applet it just has my black background without my polygon. Heres my code snippet where it draws:

    Java Code:
     	public void paint (Graphics g) {
        		Graphics2D g2 = (Graphics2D) g;
        		g2.setPaint(new GradientPaint(150, 200,(new Color(255, 108, 91)), 260, 200, (new Color(200, 20, 7)), false));
    
    		int []xpoints = {180,150,160,180,220,240,250,220};
    		int []ypoints = {350,400,400,380,380,400,400,350};
    		Polygon poly = new Polygon(xpoints, ypoints, xpoints.length);
    		g.fillPolygon(poly);
     	}

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    Hard to test a method without the calling code.
    Can you provide a SMALL program that compiles and executes and demonstrates your problem?

  3. #3
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    Well this is supposed to show a polygon that should look like the bottom of a rocket, it should have a light red to dark red gradient. My code looks like this:

    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    public class ballmove extends Applet implements Runnable {
    
    	private Image dbImage;
    	private Graphics dbg;
    
    	public void init(){
    	 	setBackground (Color.black);
     	}
    
     	public void start () {
      		Thread th = new Thread (this);
     		th.start ();
     	}
    
    	public void stop() {
     	}
    
     	public void destroy(){
     	}
    
     	public void run () {
      	Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    
      	while (true) {
    
       		repaint();
    
       		try {
        			Thread.sleep (20);
       		}
       		catch (InterruptedException ex) {
       		}
    
       		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
      		}
     	}
    
    
     	public void update (Graphics g) {
      		if (dbImage == null) {
       			dbImage = createImage (this.getSize().width, this.getSize().height);
       			dbg = dbImage.getGraphics ();
      		}
    
      		dbg.setColor (getBackground ());
      		dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
    		dbg.setColor (getForeground());
      		paint (dbg);
      		g.drawImage (dbImage, 0, 0, this);
     		}
     	public void paint (Graphics g) {
        		Graphics2D g2 = (Graphics2D) g;
        		g2.setPaint(new GradientPaint(150, 200,(new Color(255, 108, 91)), 260, 200, (new Color(200, 20, 7)), false));
    
    		int []xpoints = {180,150,160,180,220,240,250,220};
    		int []ypoints = {350,400,400,380,380,400,400,350};
    		Polygon poly = new Polygon(xpoints, ypoints, xpoints.length);
    		g.fillPolygon(poly);
     	}
    }
    I took out some of my movement variables that I'll be puting lin later. Thanks for the help.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    Your posted code draws a red shaped polygon in the lower-center left part of the screen in Appletviewer: D:\Java\jdk1.6.0_02\bin\appletviewer.exe.
    The red shape looks like a foot stool.

  5. #5
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

    Default

    I know that's what it's supposed to do, but when I try to view it in internet explorer the red shape won't show up.

  6. #6
    pizzadude223 is offline Member
    Join Date
    Jul 2010
    Posts
    74
    Rep Power
    0

Similar Threads

  1. Drag polygon
    By cassysumandak in forum New To Java
    Replies: 5
    Last Post: 03-10-2011, 06:30 PM
  2. Replies: 3
    Last Post: 05-27-2010, 10:54 AM
  3. How to use Polygon class?
    By lost_soul in forum New To Java
    Replies: 8
    Last Post: 04-25-2010, 12:48 AM
  4. How to copy a polygon
    By cassysumandak in forum New To Java
    Replies: 6
    Last Post: 10-07-2009, 12:37 AM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 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
  •