有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java ACM图形,在屏幕上移动图像

我无法编译我的代码。我正试图用定时器让图像在屏幕上移动。我能得到一些帮助吗?有一个背景gif我正在工作,一只乌龟的png应该在屏幕上移动,但我无法让它工作

这是我课程的开始(它全部编译并运行):

  class BackGroundPanel extends JFrame{
 private Image backGround, theImage;
 Dimension screenSize;
 int width;
 int height; 
 private URL myCodeBase;
 private Turtle turtle1;

 JPanel mainPanel;
 public BackGroundPanel(String bgImg, String theImage) {
      //super();
      backGround = Toolkit.getDefaultToolkit().getImage(bgImg);
      this.theImage = Toolkit.getDefaultToolkit().getImage(theImage);
      mainPanel =  new JPanel();
      screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      height = (int)screenSize.getHeight();
      width = (int)screenSize.getWidth();
      mainPanel.setLayout(null);
      setSize(width, height);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setLocationRelativeTo(null);
      setResizable(false);
      setVisible(true);
      add(mainPanel);

 }

以下是我的绘画方法:

public void paintComponent(Graphics g) {

      g.drawImage(backGround, 0, 0, width, height, this);
      int x=700;

      int y=700;


     final int num = 0;
     final JPanel pane;
     Timer timer = new Timer(10, new ActionListener()
     {
     public void actionPerformed(ActionEvent e) {
     num++;
     pane.repaint();
     }
     });

     pane = new JPanel() {
     @Override
     protected void paintComponent(Graphics g) {
     super.paintComponent(g);
     g.drawImage(theImage, x, y, this);
     }
     };
     timer.start();

 }

 public void setBackGroundImage(Image backGround) {
      this.backGround = backGround;    
 }

 private Image getBackGroundImage() {
      return backGround;    
 }

我得到了错误:

GTurtleFly_Tester.java:71: error: incompatible types: int cannot be converted to String
     Timer timer = new Timer(10, new ActionListener()
                             ^ 


GTurtleFly_Tester.java:86: error: cannot find symbol
     timer.start();
          ^

符号:方法开始()


共 (0) 个答案