请问Java swing编程如何让左键点击绘制图形?
代码:publicclassMyActionListener{publicvoidadd(){Creater.Jframe.addMouseListener(newMou...
代码:
public class MyActionListener {
public void add() {
Creater.Jframe.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent ME) {
int x = ME.getX();
int y = ME.getY();
if(ME.getButton() == MouseEvent.BUTTON1){
G.drawImage(ImageIO.read(new FileInputStream("这里是路径")), x, y, null);
}
}
public void mouseEntered(MouseEvent ME) {
}
public void mouseExited(MouseEvent ME) {
}
public void mousePressed(MouseEvent ME) {
}
public void mouseReleased(MouseEvent ME) {
}
});
}
} 展开
public class MyActionListener {
public void add() {
Creater.Jframe.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent ME) {
int x = ME.getX();
int y = ME.getY();
if(ME.getButton() == MouseEvent.BUTTON1){
G.drawImage(ImageIO.read(new FileInputStream("这里是路径")), x, y, null);
}
}
public void mouseEntered(MouseEvent ME) {
}
public void mouseExited(MouseEvent ME) {
}
public void mousePressed(MouseEvent ME) {
}
public void mouseReleased(MouseEvent ME) {
}
});
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询