在java.awt.Graphics中有类似“Anchors”(javax.microedition.lcdui.Graphics)的东西吗?

时间:2022-01-14 21:15:49

Need to rewrite JavaME application for JavaSE. (source code is not mine) There are "draw*" methods using anchors, but how can I implement this in awt?

需要为JavaSE重写JavaME应用程序。 (源代码不是我的)有使用锚点的“draw *”方法,但我怎样才能在awt中实现它?

1 个解决方案

#1


0  

it depends on what kind of anchors your are interested in. If your are wanna just use three lines do something like this

这取决于你感兴趣的锚点类型。如果你想用三条线做这样的事情

public void paintAnchor( Point start, Point end, Graphics g ) {
  g.drawLine( start.x, start.y, end.x, end.y);
  g.drawLine( end.x - ( end.x / 10 ), end.y - 5, end.x, end.y );
  g.drawLine( end.x - ( end.x / 10 ), end.y + 5, end.x, end.y );
}

this ist the simplest approach i can think about. And you will see it will only work good for a horizontal anchor. So what you have to do is, you have to implement it for different angles, maybe different thicknesses and for each quadrant of the coordinate system.

这是我能想到的最简单的方法。你会发现它只适用于水平锚。所以你要做的是,你必须为不同的角度,可能是不同的厚度和坐标系的每个象限实现它。

An alternative could be to select a specific font with anchors and just paint them. So it depends on what you trying to do.

另一种方法是选择具有锚点的特定字体并仅绘制它们。所以这取决于你想做什么。

sincerely

#1


0  

it depends on what kind of anchors your are interested in. If your are wanna just use three lines do something like this

这取决于你感兴趣的锚点类型。如果你想用三条线做这样的事情

public void paintAnchor( Point start, Point end, Graphics g ) {
  g.drawLine( start.x, start.y, end.x, end.y);
  g.drawLine( end.x - ( end.x / 10 ), end.y - 5, end.x, end.y );
  g.drawLine( end.x - ( end.x / 10 ), end.y + 5, end.x, end.y );
}

this ist the simplest approach i can think about. And you will see it will only work good for a horizontal anchor. So what you have to do is, you have to implement it for different angles, maybe different thicknesses and for each quadrant of the coordinate system.

这是我能想到的最简单的方法。你会发现它只适用于水平锚。所以你要做的是,你必须为不同的角度,可能是不同的厚度和坐标系的每个象限实现它。

An alternative could be to select a specific font with anchors and just paint them. So it depends on what you trying to do.

另一种方法是选择具有锚点的特定字体并仅绘制它们。所以这取决于你想做什么。

sincerely