小编Jos*_*osh的帖子

不知道为什么我不能得到addMouseListener(this()),addMouseMotionListener(this())工作

所以这是我的RocketShip的面板,我想将MouseListener和我的MouseMotionListener添加到它,但它告诉我"这个"是一个无效的名称.我的教科书有时使用这个,教授也建议我们在这个例子中使用"this",这样我就会遇到问题所在.我的代码如下.感谢您提供的任何建议.

    import java.applet.*;
import java.awt.*;           
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JPanel;

//I cannot understand how to draw my new rocketship or how to update the coordinates for mouse moved, mouse dragged, mouse pressed or mouse released
//also not sure how to work with setShooting
public class RocketShipPanel extends JPanel implements MouseListener,MouseMotionListener
{
    private final int WIDTH = 300, HEIGHT = 300;
    RocketShip ship = new RocketShip();

    public RocketShipPanel(){ //constructor
        addMouseListener (this());
        addMouseMotionListener (this());

        setBackground …
Run Code Online (Sandbox Code Playgroud)

java this jpanel

0
推荐指数
1
解决办法
2466
查看次数

标签 统计

java ×1

jpanel ×1

this ×1