💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ package draw.a6; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test extends JFrame { Wdmb5 mb=null; public static void main(String[] args) { Test lx=new Test(); } Test() { mb=new Wdmb5(); this.add(mb); //this.addMouseListener(mb);//鼠标 //this.addKeyListener(mb);//键盘 this.addMouseMotionListener(mb);//移动和拖拽 this.setSize(400,300); this.setLocation(300,280); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } } class Wdmb5 extends JPanel implements MouseListener,KeyListener,MouseMotionListener { public void paint(Graphics g) { super.paint(g); } @Override public void mouseClicked(MouseEvent e) { System.out.println("鼠标点击的位置是:"); System.out.println("横坐标:"+e.getX()); System.out.println("纵坐标:"+e.getY()); } public void mousePressed(MouseEvent e) { //System.out.println("鼠标被按下"); } public void mouseReleased(MouseEvent e) { //System.out.println("鼠标被松开"); } public void mouseEntered(MouseEvent e) { //System.out.println("鼠标移动到界面中"); } public void mouseExited(MouseEvent e) { //System.out.println("鼠标离开界面"); } @Override public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { System.out.println(e.getKeyChar()+"被按下"); } public void keyReleased(KeyEvent e) { } @Override public void mouseDragged(MouseEvent e)//拖拽 { System.out.println("鼠标当前位置是:"); System.out.println("横坐标:"+e.getX()); System.out.println("纵坐标:"+e.getY()); } public void mouseMoved(MouseEvent e) //移动 { /*System.out.println("鼠标当前位置是:"); System.out.println("横坐标:"+e.getX()); System.out.println("纵坐标:"+e.getY());*/ } } ~~~