相关疑难解决方法(0)

JLabel图像阵列

我试图将相同的jlabel存储图像两次加载到gridlayout面板中,但是不是创建图像的两个实例,而是仅显示一次然后移动图像.

如何将件数组中的相同JLabel位置存储到boardLabels数组中的多个JLabel中.

谢谢 :)

public static JPanel boardPanel = new JPanel(new GridLayout(4, 0));
public static JLabel pieces[] = new JLabel[2];
private static JLabel[] boardLabels = new JLabel[4];

public MainFrame() {
    pieces[0] = new JLabel(new ImageIcon(System.getProperty("user.dir") + "/images/piece1.png"));
    pieces[1] = new JLabel(new ImageIcon(System.getProperty("user.dir") + "/images/piece2.png"));

    this.add(boardPanel);
    displayGUIboard();
}


public static void displayGUIboard() {

    //ERROR - the label in pieces[0] is not copied into both boardLabels [0] and [1]
    boardLabels[0] = pieces[0];
    boardLabels[1] = pieces[0];

    boardPanel.add(boardLabels[0]);
    boardPanel.add(boardLabels[1]);
}

public static void main(String[] …
Run Code Online (Sandbox Code Playgroud)

java swing jlabel imageicon

6
推荐指数
2
解决办法
4938
查看次数

Swing Worker:函数get()

我的问题是我不明白它是如何swingworker工作的,因为我想要做的是fa=worker.get()因为我有一个很长的方法来计算在后台运行的很多点因为我不想冻结我的界面而且我想要得到她的结果来绘制组件图像.但是当我这样做时,我不明白它的位置,fa=worker.get()因为我的控制台打印"titi"并且我进行了大量其他打印以查看到达的程序的下一部分,但没有人打印.请帮助我知道编译在get()执行它之后的位置,以及如果你知道如何实现我需要的每个代码块都是受欢迎的.

public void paintComponent(final Graphics g1){
            // TODO Auto-generated method stub
            final int width=getWidth();
            final int height=getHeight();
            image= new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            //On transforme le rectangle de base en un rectangle qui a le meme ratio que le cadre contenant l'ancien
            //(Il yaura dessus la meme fractale mais avec plus de fond noir) afin que l'on puisse zoomer sans deformer la fractale
            frame = frame.expandToAspectRatio((double)getWidth()/getHeight());
            FlameAccumulator fa=null;
            worker= new SwingWorker<FlameAccumulator,FlameAccumulator>(){

                @Override
                protected …
Run Code Online (Sandbox Code Playgroud)

java swing repaint swingworker paintcomponent

2
推荐指数
1
解决办法
1748
查看次数

标签 统计

java ×2

swing ×2

imageicon ×1

jlabel ×1

paintcomponent ×1

repaint ×1

swingworker ×1