java编写程序,使得当按下鼠标时显示鼠标的位置
展开全部
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
/**
*/
public class Sanke extends JFrame implements MouseListener {
public Sanke() {
this.setSize(500, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addMouseListener(this);
this.setVisible(true);
}
@Override
public void mouseClicked(MouseEvent e) {
Point p = e.getPoint();
this.setTitle("当前坐标:" + p.x + "," + p.y);
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
public static void main(String[] args) {
new Sanke();
}
}
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
/**
*/
public class Sanke extends JFrame implements MouseListener {
public Sanke() {
this.setSize(500, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addMouseListener(this);
this.setVisible(true);
}
@Override
public void mouseClicked(MouseEvent e) {
Point p = e.getPoint();
this.setTitle("当前坐标:" + p.x + "," + p.y);
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
public static void main(String[] args) {
new Sanke();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询