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?
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);
}
}