Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
compile errors
Lisa Smith
Ranch Hand
Posts: 57
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
could use help debugging this program
import java.awt.geom.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; class PaintGradient01{ publicstaticvoid main(String[] args){ GUI guiObj = new GUI(); }//end main }//end controlling class PaintGradient01 class GUI extends Frame{ int res;//store screen resolution here staticfinalint ds = 72;//default scale, 72 units/inch staticfinalint hSize = 4;//horizonal size = 4 inches staticfinalint vSize = 4;//vertical size = 4 inches GUI(){//constructor //Get screen resolution res = Toolkit.getDefaultToolkit(). getScreenResolution(); //Set Frame size this.setSize(hSize*res,vSize*res); this.setVisible(true); this.setTitle("Copyright 1999, R.G.Baldwin"); //Window listener to terminate program. this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0);}}); }//end constructor //-----------------------------------------------------// //Override the paint() method public void paint(Graphics g){ //Downcast the Graphics object to //a Graphics2D object Graphics2D g2 = (Graphics2D)g; //Scale device space to produce inches //on the screen // based on actual screen resolution. g2.scale((double)res/72,(double)res/72); //Translate origin to center of Frame g2.translate((hSize/2)*ds,(vSize/2)*ds); //Draw x-axis g2.draw(new Line2D.Double( -1.5*ds,0.0,1.5*ds,0.0)); //Draw y-axis g2.draw(new Line2D.Double( 0.0,-1.5*ds,0.0,1.5*ds)); //Upper left quadrant, Solid red fill Ellipse2D.Double circle1 = new Ellipse2D.Double( -2.0*ds,-2.0*ds,2.0*ds,2.0*ds); g2.setPaint(new Color(255,0,0));//red g2.fill(circle1); g2.draw(circle1); //Upper right quadrant //Gradient red to orange, acyclic Ellipse2D.Double circle2 = new Ellipse2D.Double( 0.0*ds,-2.0*ds,2.0*ds,2.0*ds); g2.setPaint( new GradientPaint( 0.5f*ds,-1.0f*ds,Color.red, 1.5f*ds,-1.0f*ds,Color.orange,false)); g2.fill(circle2); g2.draw(circle2); //Lower left quadrant //Gradient red to orange, cyclic along //horizontal axis Ellipse2D.Double circle3 = new Ellipse2D.Double( -2.0*ds,0.0*ds,2.0*ds,2.0*ds); g2.setPaint( new GradientPaint( -1.15f*ds,1.0f*ds,Color.red, -0.85f*ds,1.0f*ds,Color.orange,true)); g2.fill(circle3); g2.draw(circle3); //Lower right quadrant //Gradient red to orange, cyclic along // 45 degree angle Ellipse2D.Double circle4 = new Ellipse2D.Double( 0.0*ds,0.0*ds,2.0*ds,2.0*ds); g2.setPaint( new GradientPaint( 0.0f*ds,0.0f*ds,Color.red, 0.25f*ds,0.25f*ds,Color.orange,true)); g2.fill(circle4); g2.draw(circle4); }//end overridden paint() }//end class GUI //==============================//
(Lisa - this is getting boring. Please surround your code with [ code][ /code] tags without the spaces of course)
[ September 25, 2002: Message edited by: Cindy Glass ]
Ron Newman
Ranch Hand
Posts: 1056
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please use the UBB code tags to keep the code properly formatted. Also, what is your question about this code?
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Maybe he went home and went to bed. And took this tiny ad with him:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Graphics Graphics Graphics - Where are my circles?
Frame
Debugging
Help with Java2D gradient bug. I have to finish this before I can collect my paycheck
Graphics Graphics Graphics - Where are my circles?
More...