ACM Graphics,在屏幕上移动图像

时间:2017-05-12 17:51:20

标签: java graphics jframe jpanel

我无法编译代码。我试图通过使用计时器让图像在屏幕上移动。我可以得到一些帮助吗?它有一个我工作的背景gif,一个海龟应该在屏幕上移动,但我不能让它工作。

这是我课程的开始(它全部编译和工作):

  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();
          ^

symbol:方法start()

0 个答案:

没有答案