Question
This is one of my homework: Draw the word TWO using the Line2D.Double and Ellipse2D.Double classes in the Java library. Make a project and create
This is one of my homework:
Draw the word TWO using the Line2D.Double and Ellipse2D.Double classes in the Java library.
Make a project and create a class called TwoComponent to do the drawing. There is no starter file this time. But a TwoViewer class is provided
Your drawing should follow these specifications.
1,Each letter is 40 pixels wide and 50 pixels height
2,There is a 10 pixel gap between letters
3,The upper left hand corner of the T is at (20,50)
4.Draw the T in red
5,Draw the W in blue
6,Fill the ellipse for the O (Do not draw it). Use a custom color where red is 200, green is 255, and blue is 10.
and the TwoViewer.java is:
import javax.swing.*; public class TwoViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("TWO frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TwoComponent component = new TwoComponent(); frame.add(component); frame.setVisible(true); } }
--------------------------------------------------------------
I write my code but something is wrong.My code can output "TW" , but it's really small.there is my code
import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent;
public class TwoComponent extends JComponent { private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.RED); g2.drawString("T", 20, 100); g2.setColor(Color.BLUE); g2.drawString("W", 30, 100); }
}
The first one is what I actually output and the second one is what I should output
Image ExpectedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started