Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is one of my homework: Draw the word TWO using the Line2D.Double and Ellips

ID: 3788499 • Letter: T

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 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:

--------------------------------------------------------------

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 Expected:

Explanation / Answer

import java.awt.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import javax.swing.*;

class pr1 extends JPanel
{
private static final long serialVersionUID = 1L;

public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Font f1=new Font("Serif", Font.PLAIN, 48);;
g2.setFont(f1);
g2.setColor(Color.RED);
g2.drawString("T", 20, 100);
g2.setColor(Color.BLUE);
g2.drawString("W", 40, 100);
g2.setColor(Color.green);
//g2.drawOval(45,70,50, 50);
g2.fillOval(85,65,43, 43);
}

}
public class GRP
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      frame.setSize(300, 400);
      frame.setTitle("TWO frame");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      pr1 component = new pr1 ();
      frame.add(component);

      frame.setVisible(true);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote