| | |
Graphics Programming
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 15
Reputation:
Solved Threads: 0
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?
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?
Java Syntax (Toggle Plain Text)
import java.awt.*; import javax.swing.*; import java.awt.geom.*; public class DrawJavaMugTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable(){ public void run(){ DrawFrame frame = new DrawFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } } class DrawFrame extends JFrame{ public DrawFrame(){ setTitle("babylonlion"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); //DrawJavaMugPanel panel = new DrawJavaMugPanel(); //add(panel); DrawJavaMugComponent component = new DrawJavaMugComponent(); add(component); } public static final int DEFAULT_WIDTH = 400; public static final int DEFAULT_HEIGHT = 400; } class DrawJavaMugComponent extends JComponent{ public void paintComponent(Graphics g){ Graphics2D g2 = (Graphics2D) g; g2.draw(new Line2D.Double(100, 100, 100, 300));//Vertical line 1 g2.draw(new Line2D.Double(276, 100, 276, 300));//Vertical line 2 g2.draw(new Line2D.Double(276, 300, 100, 300));//Horizontal line Ellipse2D ellipse1 = new Ellipse2D.Double();//the opening of the mug ellipse1.setFrame(276, 125, 40, 150); g2.draw(ellipse1); Ellipse2D ellipse2 = new Ellipse2D.Double();//the handle of the mug ellipse2.setFrame(99.5, 91, 177, 15);//(leftX,topY,width, height) g2.draw(ellipse2); } }
Last edited by babylonlion; 30 Days Ago at 3:04 am.
•
•
Join Date: Sep 2008
Posts: 1,568
Reputation:
Solved Threads: 196
1
#2 30 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.
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.
•
•
Join Date: Oct 2009
Posts: 15
Reputation:
Solved Threads: 0
0
#3 30 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.
![]() |
Similar Threads
- I rushed graphics programming... (Java)
- The Jump from C++ Programming to Graphics? (C++)
- Which programming language or languages are best suited for graphics programming (Game Development)
- Graphics In Pixel: Part II (C++)
Other Threads in the Java Forum
- Previous Thread: Help with Code
- Next Thread: P2P File sharing Application
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui homework html ide if_statement image integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia keyword linux list macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql sqlite stop string swing threads transforms tree ui unicode validation windows






thank you for your time 