我的鼠标听众仍然无法工作?

时间:2016-05-14 03:39:26

标签: java jframe mouselistener

我之前创建了一个线程,解决了为什么这不起作用的一个问题 但为什么我的鼠标听众现在不工作?我尝试实现/扩展鼠标监听器,并添加和删除@Override到方法,看看是否有效,它没有..我有2个类,我尝试使用一个,但都没有。

有什么想法吗? 我需要做一些我没看到的其他事情吗?

由于

第1课:

package Sound;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

public class JSound extends JFrame {

//IDK what its for but its important for jframe
private static final long serialVersionUID = 3314065768834871224L;

//Gets General volume
public static double volume = Audio.getMasterOutputVolume()*3*100;

//Universal variables are static, and i usually put them here
public static boolean running = true;
public static String title = "Advanced Java Sound";
public static int width = 410;
public static int height = 600;

public static int ticks = 1;

public static int[] background;

public MouseInput mouseinput;

public JSound() {
    //initialises mouse input
    //setTitle("Simple Frame");
    System.out.println("Initialising Mouse Listener");
    Display.frame.addMouseListener(mouseinput);
}

public static void main(String args[]) {
    //Creates the display basicly just the empty window you will see all the stuff drawn to
    Display.Window();
    //Calls the main loop method
    //SoundLoad();
    //addMouseListener(sound);
    new JSound();

    mainloop();
}

public static void mainloop() {
    render.quickrender();

    try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); }

    while(running) {
        long lastTime = System.nanoTime();
        double amountOfTicks = 60.0;
        double ns = 1000000000 / amountOfTicks;
        double delta = 0;
        long timer = System.currentTimeMillis();
        int frames = 0;
        while (running) {
            long now = System.nanoTime();
            delta += (now - lastTime) / ns;
            lastTime = now;
            while (delta >= 1) {
                ticks++;
                delta--;
            }
            if (running) 
                tick();
                render.renderer();
            frames++;

            if(System.currentTimeMillis() - timer > 1000) {
                timer += 1000;
                if (ticks <= 10000) {
                    System.out.println("FPS: " + frames + " Ticks: " + ticks);
                } else {
                    System.out.println("FPS: " + frames);
                }
                frames = 0;
            }
        }
    }
}

public static void tick() {
    //Put any tick method stuff here, it will be executed in priority to render, and will occur more then 60 times per second

    //Audio.setMasterOutputVolume(0.5f);
    volume = Audio.getMasterOutputVolume()*4.8*100;
    //System.out.println(Audio.getMasterOutputVolume());
    //System.out.println((int)volume);
}

}

Class 2:
package Sound;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MouseInput extends MouseAdapter implements MouseListener {

public void mouseClicked(MouseEvent e) {
    System.out.println(e.getX());
    System.out.println(e.getY());
}

public void mouseEntered(MouseEvent e) {
    System.out.println(e.getX());
    System.out.println(e.getY());
}

public void mouseExited(MouseEvent e) {
    System.out.println(e.getX());
    System.out.println(e.getY());
}

public void mousePressed(MouseEvent e) {
    int mx = e.getX();
    int my = e.getY();
    System.out.println(e.getX());
    System.out.println(e.getY());
}

public void mouseReleased(MouseEvent e) {
    System.out.println(e.getX());
    System.out.println(e.getY());
}

}

0 个答案:

没有答案