java的getshape()_JAVA(Swing)中的镜像形状

大家好,

我有一个功课,涉及在Swing GUI中绘制和操作形状.

我遇到了一个问题,当我试图镜像我的形状时,我得不到我想要的结果.

drawallnodes方法在Jpanels paintComponent中调用.

public void drawallnodes(ArrayList nodes, Graphics2D g2)

{

int arraysize = nodes.size();

ArrayList temparray;

AffineTransform at = new AffineTransform();

if (nodes.size() != 0)

{

System.out.println("nodes.size " + nodes.size());

if (currentarrayindex >= 0)

{

AffineTransform afx = new AffineTransform();// for rotate

for (int i = 0; i <= currentarrayindex; i++)

{

if (nodes.get(i).getWasAngleChanged())

{

afx.rotate(

Math.toRadians(nodes.get(i).getAngleInDegrees()),

nodes.get(i).getCenter().x,

nodes.get(i).getCenter().y);

nodes.get(i).setShape(

afx.createTransformedShape(nodes.get(i).getShape()));

nodes.get(i).setWasAngleChanged(false);

nodes.get(i).setokrajRectangle();

}

try

{

Rectangle r = nodes.get(i).getShape().getBounds();

}

catch (Exception e)

{

System.out.println(

"Exception found at getbounds, no shape with getbounds found");

}

AffineTransform saveXform = g2.getTransform();

g2.setColor(nodes.get(i).getColor());

int w = getWidth();

// it gets the JPanels width, which is set to 758px

at = AffineTransform.getTranslateInstance(w, 0);

System.out.println("*********Get width of shape: " + w);

at.scale(-1, 1); // mirror -x, y

g2.setPaint(Color.red);

g2.draw(at.createTransformedShape(nodes.get(i).getShape()));

try

{

g2.drawString(nodes.get(i).getText(),

(int) nodes.get(i).getCenter().getX(),

(int) nodes.get(i).getCenter().getY());

}

catch (Exception e)

{

System.err.println("No text found at node");

}

try

{

g2.draw((Shape) nodes.get(i).getShape());

}

catch (Exception e)

{

System.err.println("No shape found at node");

}

// g2.transform(AffineTransform.getRotateInstance(0, 1));

g2.setTransform(saveXform);

}

}

}

}

当我镜像Shape时,例如我在右侧绘制,但镜像图像出现在左侧…我想镜像形状并在同一个地方获得镜像形状而不是我的jpanel ….

谢谢您的帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值