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)