问题:用Java制作简单的图形 [英] Question: Making simple graphics in Java

查看:72
本文介绍了问题:用Java制作简单的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于图形的两个问题:

1。我正在尝试为房子创建屋顶,需要61像素长。为了使屋顶正确居中,我需要将两个基点距离中心30.5像素。


我试图通过制作三个点,峰值,左右基点,并用线连接它来实现这一目标。


但是,代码如下:

Point2D.Float roofPointLeft = new Point2D.Float(9.5 + x,40 + y);
< br $> b $ b产生错误。


我被告知你不能有半个像素,这对我来说很有意义。但是,如果没有半个像素,我根据任务说明不能将我的屋顶居中。


洞察力,任何人?

2。我家的屋顶由三个点组成,两条线用于两侧,矩形的顶部用作房子的主体作为底座。


我怎么能填写一个封闭的区域,比如我的屋顶?


一个相关的问题,如果我安排三个形状对象(比如一个圆形,一个三角形和一个正方形),那么它之间就有一个封闭的空间他们 - 有没有办法填补这个空间?


感谢您的帮助!

解决方案


关于图形的两个问题:

1。我正在尝试为需要的房子创建屋顶长61像素。为了使屋顶正确居中,我需要将两个基点距离中心30.5像素。


我试图通过制作三个点,峰值,左右基点,并用线连接它来实现这一目标。


但是,代码如下:

Point2D.Float roofPointLeft = new Point2D.Float(9.5 + x,40 + y);
< br $> b $ b产生错误。


我被告知你不能有半个像素,这对我来说很有意义。但是,如果没有半个像素,我根据任务说明不能将我的屋顶居中。


洞察力,任何人?

2。我家的屋顶由三个点组成,两条线用于两侧,矩形的顶部用作房子的主体作为底座。


我怎么能填写一个封闭的区域,比如我的屋顶?


一个相关的问题,如果我安排三个形状对象(比如一个圆形,一个三角形和一个正方形),那么它之间就有一个封闭的空间他们 - 有没有办法填补这个空间?


感谢您的帮助!



让我们从1开始


你得到了什么错误?


< blockquote> 构造函数Point2D.Float(double,int)未定义。


即使我删除了x& y变量。如果我向第二个数字添加一个小数(通过写40.0),投诉只需切换到(双,双)。


从我的角度来看,写了Point2D.Float,我在期待(漂浮,漂浮)。


我以为在发布我的问题之前我曾尝试过这个(见下文),但我刚才再次尝试过,似乎接受了小数,如果我写:


Point2D.Double roofPointLeft = new Point2D.Double(9.5 + x,40 + y);


d' '哦!


有没有人知道为什么它接受带有.Double的小数而不是带.Float?


构造函数Point2D.Float(double,int)未定义。


即使我删除x& y变量。如果我向第二个数字添加一个小数(通过写40.0),投诉只需切换到(双,双)。


从我的角度来看,写了Point2D.Float,我在期待(漂浮,漂浮)。


我以为在
发布我的问题之前我曾尝试过这个(见下文),但我刚才再次尝试过,似乎接受了小数,如果我写:


Point2D.Double roofPointLeft = new Point2D.Double(9.5 + x,40 + y);


d' '哦!


有没有人知道为什么它接受带有.Double的小数而不是带有.Float的小数?



Point2D.Float的构造函数采用浮点数。小数默认为两倍。你可以在末尾添加一个f表示一个9.5f的浮点数,编译器会接受它。在这种情况下,我认为你最好使用Point2D.Double,因为小数是默认的两倍


Two questions on graphics:

1. I''m trying to create the rooftop for a ''house'' which needs to be 61 pixels long. In order to center the roof properly, I need to have both base points at 30.5 pixels from the center.

I am trying to accomplish this by making three points, the peak, and left and right base points, and connecting them with lines.

However, code like this:
Point2D.Float roofPointLeft = new Point2D.Float (9.5 + x, 40 + y);

produces an error.

I''ve been told you can''t have half a pixel, and this makes sense to me. However, without half a pixel I cannot center my roof according to the assignment instructions.

Insight, anyone?

2. The roof of my house consists of three points, two lines for the sides, and the top of the rectangle which serves as the main body of the house as the base.

How can I fill an enclosed area like my roof?

A related question, if I arrange three shape objects (say a circle, a triangle, and a square) so that there is an enclosed space between them -- is there a way to fill this space?

Thanks for any and all help!

解决方案

Two questions on graphics:

1. I''m trying to create the rooftop for a ''house'' which needs to be 61 pixels long. In order to center the roof properly, I need to have both base points at 30.5 pixels from the center.

I am trying to accomplish this by making three points, the peak, and left and right base points, and connecting them with lines.

However, code like this:
Point2D.Float roofPointLeft = new Point2D.Float (9.5 + x, 40 + y);

produces an error.

I''ve been told you can''t have half a pixel, and this makes sense to me. However, without half a pixel I cannot center my roof according to the assignment instructions.

Insight, anyone?

2. The roof of my house consists of three points, two lines for the sides, and the top of the rectangle which serves as the main body of the house as the base.

How can I fill an enclosed area like my roof?

A related question, if I arrange three shape objects (say a circle, a triangle, and a square) so that there is an enclosed space between them -- is there a way to fill this space?

Thanks for any and all help!

Let''s start with 1

What error did you get?


The constructor Point2D.Float(double, int) is undefined.

This complaint persists even if I remove the x & y variables. If I add a decimal to the second number (by writing 40.0) the complaint simply switches to (double, double).

From my perspective, having written Point2D.Float, I was expecting (float, float).

I thought I''d tried this (see below) before posting my question, but I tried it again just now, and does seem to accept the decimals if I write:

Point2D.Double roofPointLeft = new Point2D.Double (9.5 + x, 40 + y);

d''Oh!

Does anyone know why it accept decimals with .Double but not with .Float?


The constructor Point2D.Float(double, int) is undefined.

This complaint persists even if I remove the x & y variables. If I add a decimal to the second number (by writing 40.0) the complaint simply switches to (double, double).

From my perspective, having written Point2D.Float, I was expecting (float, float).

I thought I''d tried this (see below) before posting my question, but I tried it again just now, and does seem to accept the decimals if I write:

Point2D.Double roofPointLeft = new Point2D.Double (9.5 + x, 40 + y);

d''Oh!

Does anyone know why it accept decimals with .Double but not with .Float?

The constructor for Point2D.Float takes floats. Decimals are double by default. You could add an f at the end to indicate a float with 9.5f, the compiler would accept that. In this case I think you are better off using Point2D.Double which is accepted because decimals are double by default


这篇关于问题:用Java制作简单的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆