经过 2 小时的搜索后,我真的不知道为什么我的代码不起作用,所以我想知道您是否可以提供帮助。
当我按下按钮时,我只想看到“点击”。我的班级MouseInput实现MouseListener了,在方法中mouseClicked我得到的只是system.out...("clicked");
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class App implements Runnable {
private Display display;
private BufferStrategy bs;
private Graphics g;
private int cubeSide = 150;
private String title;
private int height,width;
private boolean running = false;
private Thread thread;
private MouseInput mouseInput;
public App(String title,int width,int height){
this.height=height;
this.width=width;
this.title=title;
display = new Display(title, width, height);
}
void setBufferStrategy(){
if(display.getCanvas().getBufferStrategy()==null){
display.getCanvas().createBufferStrategy(3);
}
bs = display.getCanvas().getBufferStrategy();
}
void init(){
setBufferStrategy();
mouseInput = new MouseInput();
display.getFrame().addMouseListener(mouseInput);
}
public synchronized void start(){
if(running==true)
return;
running=true;
thread = new Thread(this);
thread.start();
}
void render(){
}
@Override
public void run() {
init();
while(running){
render();
}
}
public synchronized void stop(){
}
}
鼠标输入代码:
`import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class MouseInput implements MouseListener {
@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println("Click");
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
潇潇雨雨
萧十郎
相关分类