Results 1 to 6 of 6
Thread: Polygon won't show up
- 08-09-2010, 02:42 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
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); }
- 08-09-2010, 02:53 AM #2
Hard to test a method without the calling code.
Can you provide a SMALL program that compiles and executes and demonstrates your problem?
- 08-09-2010, 03:02 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
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:
I took out some of my movement variables that I'll be puting lin later. Thanks for the help.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); } }
- 08-09-2010, 03:10 AM #4
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.
- 08-09-2010, 03:24 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
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.
- 08-09-2010, 03:51 AM #6
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
Similar Threads
-
Drag polygon
By cassysumandak in forum New To JavaReplies: 5Last Post: 03-10-2011, 06:30 PM -
how to show web browser in mobile app or is it possible to show it in textArea
By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 10:54 AM -
How to use Polygon class?
By lost_soul in forum New To JavaReplies: 8Last Post: 04-25-2010, 12:48 AM -
How to copy a polygon
By cassysumandak in forum New To JavaReplies: 6Last Post: 10-07-2009, 12:37 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks