小编McD*_*iel的帖子

在另一个类中调用Repaint()方法

repaint()我的Java代码中的方法有问题.我想在另一个中调用它,class但我不能,有些东西根本不起作用.我在论坛上搜索过,但没有任何东西可以帮助我.

我的主要 class:

public class Main {

public static Main main;
public static JFrame f;
public Main(){

}

public static void main(String[] args) {
    main = new Main();

    f = new JFrame();
    Ball b = new Ball();

    f.getContentPane().setBackground(Color.GRAY);

    f.add(b);
    f.setSize(500, 500);
    f.setLocationRelativeTo(null);
    f.setTitle("Test");
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.addMouseMotionListener(b);
    f.addKeyListener(new Key());


}
}
Run Code Online (Sandbox Code Playgroud)

class在我创建用于移动形状的2DGraphics的:

public class Ball extends JLabel implements MouseMotionListener{

public Ball(){

}

public static double x = 10;
public static double …
Run Code Online (Sandbox Code Playgroud)

java swing repaint paintcomponent

6
推荐指数
1
解决办法
565
查看次数

标签 统计

java ×1

paintcomponent ×1

repaint ×1

swing ×1