Java – use drawLine to extend the graphics class (double, double, double, double)

Question: / / where the story begins

You can see it's terrible

Actual prototype: public abstract void drawLine (int x1, int Y1, int X2, int Y2) draws a line between points (x1, Y1) and (X2, Y2) in the coordinate system of this drawing context using the current color

What do I want to do:

or

Turn me in the right direction and kick my ass

Solution

You don't need to "extend" graphics. If you do, it won't be very useful because the swing graphics engine can't generate objects of a specific class So this raises the question - where do you get a specific mygraphics object?

Instead, I'll use a shape object, such as line2d, and use its line2d The double subtype builds it and then draws it using a graphics2d object You can get a graphics2d object by converting a graphics object to this object Most graphics objects allow this, including objects used to draw images in jcomponents and bufferedimages There are a few places that may not be allowed, but I haven't come across this yet

Edit, I want to know that your problem comes from mixed views and models The best solution to your problem may be to have your model use double precision, while the view uses integers to display the data owned by the model Of course, you need to round off when converting data from a model to a view

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>