| | |
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; 32 Days Ago at 3:04 am.
•
•
Join Date: Sep 2008
Posts: 1,568
Reputation:
Solved Threads: 196
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.
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 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.
![]() |
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 |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character chat class client code compile component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaee javaprojects jni jpanel jtable julia learningresources lego linked linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number online printf problem program programming project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






thank you for your time 