如何在GUI中以相反的方向打印JLabel卡?

时间:2016-04-17 04:30:24

标签: java swing awt jlabel

我的GUI输出是图1.我想以相反的方向打印卡,如图2所示。我使用JLabel存储每张卡,如我的代码所示。任何.swing或.awt方法都可以帮我做到这一点?

CardLabel = LabelCard(cardsInHand);
int xcoordinate = 100;
for ( JLabel Label : CardLabel){
    this.add(Label);
    Label.setBounds(i += 20 , (int) (frame.getHeight()/5.8 * game.getCurrentIdx()  +20  ) , Label.getIcon().getIconWidth(), Label.getIcon().getIconHeight() );  
}

图1:

图2:

1 个答案:

答案 0 :(得分:0)

SELECT * FROM
      (SELECT * FROM `tablename` ORDER BY columnname DESC LIMIT 3)
ORDER BY columnname ASC;

在此示例中,我使用AffineTransform翻转图像,您可以看到详细信息以获取更多详细信息https://docs.oracle.com/javase/tutorial/2d/advanced/transforming.html

您可以通过此方法将jlabel中的图标转换为缓存图像

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
-----------------------------------------------------------------------------

public static BufferedImage FlippTheImage(BufferedImage bi) {
        BufferedImage flipped = new BufferedImage(bi.getWidth(), bi.getHeight(),
        bi.getType());
        AffineTransform tran = AffineTransform.getTranslateInstance(0,
        bi.getHeight());
    AffineTransform flip = AffineTransform.getScaleInstance(1d, -1d);
    tran.concatenate(flip);

    Graphics2D g = flipped.createGraphics();
    g.setTransform(tran);
    g.drawImage(bi, 0, 0, null);
    g.dispose();

    return flipped;
  }