为什么我无法使用我的paintComponent?

时间:2015-05-05 14:59:55

标签: java actionlistener paint keyevent actionevent

DataSet_SelectForProject

为什么我无法使用DataLogic.tADDOCList
它表示对于Object类型它是未定义的。

它还说drawImage不适用于我的图像。此外,我在package com.daveoncode.filters { /** * @author Davide Zanotti (davidezanotti@gmail.com) */ public class searchFilter extends AbstractFilterDecorator { /** * @param target IFilter <p>A reference to a wrapped IFilter object</p> * @param value Object <p>Value against which the filter is applied</p> */ public function searchFilter(target:IFilter, value:Object) { super(target, value); } /** * Implementation of IFilter interface by overriding the dummy apply() of AbstractFilterDecorator */ override public function apply(item:Object):Boolean { var f:String = "ig"; var packageSearch:RegExp = new RegExp(this._value, f); var packageMatch:Boolean = packageSearch.test(item.Package); var itemSearch:RegExp = new RegExp(this._value, f); var itemMatch:Boolean = packageSearch.test(item.ItemNum); return this._target.apply(item) && (packageMatch || itemMatch); } } }执行操作时无法public class Movement implements ActionListener { MazeModel model = new MazeModel(); public void keyPressed(KeyEvent e){ //all of the different movement keys if(e.getKeyCode() == KeyEvent.VK_W || e.getKeyCode() == KeyEvent.VK_UP){ model.moveUP(model.getUserY()); } else if(e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_LEFT){ model.moveLEFT(model.getUserX()); } else if(e.getKeyCode() == KeyEvent.VK_S || e.getKeyCode() == KeyEvent.VK_DOWN){ model.moveDOWN(model.getUserY()); } else if(e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_RIGHT){ model.moveRIGHT(model.getUserX()); } } //no need for either of these at the moment public void keyRealeased(KeyEvent e){} public void keyTyped(KeyEvent e){} //painting the image protected void paintComponent(Graphics g){ super.paintComponent(g); g.drawImage("player.png", model.getUserX(), model.getUserY(), this); } //every time a key is pressed the screen will repaint the image public void actionPerformed(ActionEvent ae){ repaint(); } }

2 个答案:

答案 0 :(得分:0)

public class Movement implements ActionListener {

您的课程不是JFrame,也不是JPanel。

答案 1 :(得分:0)

您的课程必须延长JPanel