-
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:
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);
}
-
Hard to test a method without the calling code.
Can you provide a SMALL program that compiles and executes and demonstrates your problem?
-
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:
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.
-
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.
-
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.
-
I got it. My applet size wasn't big enough. Thanks