是否有任何原因使用mouselistener没有响应?

时间:2018-02-26 00:14:46

标签: java mouselistener

基本上,我想在按下鼠标时获取鼠标的坐标。我之前已经完成了,我知道它可能,但它似乎没有使用我当前的jframe / jpanel设置,我无法理解为什么。

这是我的mouselistener代码的摘要:

package com.JJEngine.input;

import java.awt.MouseInfo;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import com.JJEngine.output.Window;

public class Mouse implements MouseListener {
    public Mouse(){
    }

    public void mouseClicked(MouseEvent arg0) {
    }

    @Override
    public void mouseEntered(MouseEvent arg0) {
    }

    @Override
    public void mouseExited(MouseEvent arg0) {

    }

    @Override
    public void mousePressed(MouseEvent arg0) {
        //This is where i'd do my stuff if this actually worked
    }

    @Override
    public void mouseReleased(MouseEvent arg0) {

    }

}

这是我的jpanel / jframe     包com.JJEngine.output;

import java.awt.Container;

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

import com.JJEngine.input.Mouse;
import com.JJEngine.main.Main;

import custom.GameMain;

public class Window extends JPanel{
    public static JFrame frame = new JFrame();  
    public static JPanel gamePanel = new JPanel();
    private Container window;


    public Window() {
        frame.addMouseListener(new Mouse());

        frame.setExtendedState(JFrame.MAXIMIZED_BOTH); 
        frame.setUndecorated(!GameMain.BORDERS);
        frame.setVisible(true);
        // Custom options
        frame.setSize(Main.game.X, Main.game.Y);
        frame.setTitle(Main.game.NAME);
        frame.setResizable(Main.game.RESIZABLE);

        window = frame.getContentPane();
        frame.add(gamePanel);
        frame.add(Main.render);

           // Built options
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationRelativeTo(null);
            frame.setFocusable(true);
            frame.setAlwaysOnTop(true);
        }
    }

我的猜测是我必须重构我的整个Window类。如果是这样的话,为什么呢?提前谢谢。

0 个答案:

没有答案