Graphics Programming

Thread Solved

Join Date: Oct 2009
Posts: 15
Reputation: babylonlion is an unknown quantity at this point 
Solved Threads: 0
babylonlion babylonlion is offline Offline
Newbie Poster

Graphics Programming

 
0
  #1
32 Days Ago
Hi guys,
I need to display "Java Mug" (in red) inside the mug I created in the following code. I spent hours working on it but couldn't get anywhere. Can you guys help me please?
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.geom.*;
  4.  
  5. public class DrawJavaMugTest {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. EventQueue.invokeLater(new Runnable(){
  10.  
  11. public void run(){
  12. DrawFrame frame = new DrawFrame();
  13. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  14. frame.setVisible(true);
  15. }
  16. });
  17. }
  18. }
  19.  
  20. class DrawFrame extends JFrame{
  21.  
  22. public DrawFrame(){
  23. setTitle("babylonlion");
  24. setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
  25.  
  26. //DrawJavaMugPanel panel = new DrawJavaMugPanel();
  27. //add(panel);
  28.  
  29. DrawJavaMugComponent component = new DrawJavaMugComponent();
  30. add(component);
  31. }
  32. public static final int DEFAULT_WIDTH = 400;
  33. public static final int DEFAULT_HEIGHT = 400;
  34. }
  35.  
  36. class DrawJavaMugComponent extends JComponent{
  37.  
  38. public void paintComponent(Graphics g){
  39.  
  40. Graphics2D g2 = (Graphics2D) g;
  41.  
  42. g2.draw(new Line2D.Double(100, 100, 100, 300));//Vertical line 1
  43. g2.draw(new Line2D.Double(276, 100, 276, 300));//Vertical line 2
  44. g2.draw(new Line2D.Double(276, 300, 100, 300));//Horizontal line
  45.  
  46. Ellipse2D ellipse1 = new Ellipse2D.Double();//the opening of the mug
  47. ellipse1.setFrame(276, 125, 40, 150);
  48. g2.draw(ellipse1);
  49.  
  50. Ellipse2D ellipse2 = new Ellipse2D.Double();//the handle of the mug
  51. ellipse2.setFrame(99.5, 91, 177, 15);//(leftX,topY,width, height)
  52. g2.draw(ellipse2);
  53.  
  54. }
  55. }
Last edited by babylonlion; 32 Days Ago at 3:04 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
1
  #2
32 Days Ago
Just use the drawString method to draw your words. g.drawString(parameters go here) http://java.sun.com/j2se/1.4.2/docs/.../Graphics.html

You can set the Graphics contexts' font and color and stuff before you draw the string, and it will draw in that font and color. At least so says the API if you read that link.
Out.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: babylonlion is an unknown quantity at this point 
Solved Threads: 0
babylonlion babylonlion is offline Offline
Newbie Poster
 
0
  #3
32 Days Ago
Originally Posted by BestJewSinceJC View Post
Just use the drawString method to draw your words. g.drawString(parameters go here) http://java.sun.com/j2se/1.4.2/docs/.../Graphics.html

You can set the Graphics contexts' font and color and stuff before you draw the string, and it will draw in that font and color. At least so says the API if you read that link.
I'm aware of the API. And I know what tools to use, but I don't know how to use them; I was hoping that someone could help me write the code. Thank you for you time
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: babylonlion is an unknown quantity at this point 
Solved Threads: 0
babylonlion babylonlion is offline Offline
Newbie Poster
 
0
  #4
32 Days Ago
Never mind; I fixed it thank you for your time
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #5
32 Days Ago
Ok, glad you got it fixed. The reason I thought you didn't know the API was because it looked like you were trying to write words by drawing the lines individually and connecting them. But anyway, my mistake. Mark this solved if you have no more questions.
Out.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #6
22 Days Ago
.
Last edited by quuba; 22 Days Ago at 4:26 am. Reason: my error in thread #
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC