Question
I don't have a problem doing #1, but I am having trouble actually coding these classes in Java so it can be converted to svg.
I don't have a problem doing #1, but I am having trouble actually coding these classes in Java so it can be converted to svg.
For the SvgMaker class this is what I have so far. I don't know if it's correct.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class SvgMaker
{
public int imWidth;
public int imHeight;
public String fileName;
private PrintWriter fp;
public void setFp(PrintWriter fp_in)
{
fp = fp_in;
}
public PrintWriter getFp()
{
return fp;
}
public SvgMaker(int imWidth_in, int imHeight_in, String fileName_in)
{
// Capture incoming member variables
imWidth = imWidth_in;
imHeight = imHeight_in;
fileName = fileName_in;
// Open File
fileName = "C:/Users/mvanc/OneDrive/Documents/svg.txt";
PrintWriter outFile = null;
// Write opening svg tag to the file
try
{
outFile = new PrintWriter(new File(fileName));
outFile.print("
outFile.print(" xmlns = 'http://www.w3.org/2000/svg' ");
outFile.print(" xmlns:xlink = 'http://www.w3.org/1999/xlink' ");
outFile.print(" version = '1.1' ");
outFile.print(" width = " + "'" + imWidth + "'" + "height = " + "'" + imHeight + "'> ");
}
catch(FileNotFoundException ex)
{
System.out.print(" Error opening file: " + fileName);
}
}
public void drawCircle(Circle c, Fill fc, Stroke sc)
{
}
public void drawRectangle(Rectangle r, Fill fr, Stroke sr)
{
}
public void drawRoundedRectangle(RoundedRectangle rr, Fill frr, Stroke srr)
{
}
public void drawLine(Line l, Stroke sl)
{
}
public void drawPath(Path p, Fill fp, Stroke sp)
{
}
public void close()
{
// Write closing svg tag to file
fileName = "C:/Users/mvanc/OneDrive/Documents/svg.txt";
PrintWriter outFile = null;
try
{
outFile = new PrintWriter(new File(fileName));
outFile.print(" />");
outFile.print("");
}
catch(FileNotFoundException ex)
{
System.out.print(" Error opening file: " + fileName);
}
// Close file
outFile.flush();
outFile.close();
}
}
Circle class:
import java.io.File;
import java.io.PrintWriter;
public class Circle
{
int cx;
int cy;
int r;
public Circle(int cx_in, int cy_in, int r_in)
{
cx = cx_in;
cy = cy_in;
r = r_in;
PrintWriter outFile = null;
outFile.print("
outFile.print(" r = " + "'" + r + "' ");
}
}
Dashed Stroke Class:
import java.io.PrintWriter;
public class DashedStroke extends Stroke // Child class of Stroke
{
int d1; // First dash
int d2; // Second dash
public DashedStroke(String s_in, int sw_in, int d1, int d2)
{
// Call parent constructor
super (s_in, sw_in);
this.d1 = d1;
this.d2 = d2;
PrintWriter outFile = null;
outFile.print(" stroke = '" + s + "' stroke-width = '" + sw + "' ");
outFile.print(" stroke-dasharray = '" + d1 + "," + d2 + "' ");
}
}
Fill Class:
import java.io.PrintWriter;
public class Fill // rgb function
{
int r; // Red
int g; // Green
int b; // Blue
public Fill(int r_in, int g_in, int b_in)
{
r = r_in;
g = g_in;
b = b_in;
PrintWriter outFile = null;
outFile.print(" fill = 'rgb(" + r + "," + g + "," + b + ")' ");
}
}
Line Class:
import java.io.PrintWriter;
public class Line
{
int x1;
int y1;
int x2;
int y2;
public Line(int x1_in, int y1_in, int x2_in, int y2_in)
{
x1 = x1_in;
y1 = y1_in;
x2 = x2_in;
y2 = y2_in;
PrintWriter outFile = null;
outFile.print(" outFile.print(" x2 = '" + x2 + "' y2 = '" + y2 + "' "); } } Path Class: import java.io.PrintWriter; public class Path { int x1; int y1; int x2; int y2; int x3; int y3; public Path(int x1_in, int y1_in, int x2_in, int y2_in, int x3_in, int y3_in) { x1 = x1_in; y1 = y1_in; x2 = x2_in; y2 = y2_in; x3 = x3_in; y3 = y3_in; PrintWriter outFile = null; outFile.print(" } Rectangle Class: import java.io.PrintWriter; public class Rectangle // Parent Class to RoundedRectangle { int x; int y; int width; int height; public Rectangle(int x_in, int y_in, int width_in, int height_in) { x = x_in; y = y_in; width = width_in; height = height_in; PrintWriter outFile = null; outFile.print(" outFile.print(" width = '" + width + "' height = '"+ height + "' "); } } RoundedRectangle Class: import java.io.PrintWriter; public class RoundedRectangle extends Rectangle // Child Class of Rectangle { int r; public RoundedRectangle(int x_in, int y_in, int width_in, int height_in, int r) { // Call parent constructor super (x_in, y_in, width_in, height_in); this.r = r; PrintWriter outFile = null; outFile.print(" outFile.print(" width = '" + width + "' height = '"+ height + "' "); outFile.print(" r = '" + r + "' "); } } Stroke Class: import java.io.PrintWriter; public class Stroke // Parent Class to DashedStroke { String s; // Stroke int sw; // Stroke-width public Stroke(String s_in, int sw_in) { s = s_in; sw = sw_in; PrintWriter outFile = null; outFile.print(" stroke = '" + s + "' stroke-width = '" + sw + "' "); } } Test Class: public class TestClass { public static void main(String[] args) { SvgMaker svg = new SvgMaker(300, 300, "C:/Users/mvanc/OneDrive/Documents/svg.txt"); Circle c = new Circle(2, 1, 6); Fill fc = new Fill(0,0, 255); Stroke sc = new Stroke("black", 3); Rectangle r = new Rectangle(10, 20, 5, 5); Fill fr = new Fill(255, 0, 0); Stroke sr = new Stroke("blue", 2); RoundedRectangle rr = new RoundedRectangle(10, 20, 5, 5, 2); Fill frr = new Fill(255, 0, 255); Stroke srr = new Stroke("red", 7); Line l = new Line(3, 6, 5, 10); Stroke sl = new Stroke("blue", 2); Path p = new Path(50, 50, 250, 50, 100, 200); Fill fp = new Fill(255, 255, 255); Stroke sp = new Stroke("black", 1); } }
Step 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