當前位置:編程學習大全網 - 網站源碼 - 寫壹個Java程序 要求通過在鼠標點擊的位置顯示壹個綠色方塊來響應鼠標點擊

寫壹個Java程序 要求通過在鼠標點擊的位置顯示壹個綠色方塊來響應鼠標點擊

public class ClickTest extends JFrame implements MouseListener {

private int x=0;

private int y=0;

public ClickTest(){

setBounds(300,300,300,300);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

addMouseListener(this);

}

public void mouseClicked(MouseEvent e) {

x = e.getX()-3;

y = e.getY()-3;

repaint();

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void paint(Graphics g){

super.paint(g);

g.setColor(Color.GREEN);

g.fillRect(x, y, 6, 6);

}

public static void main(String[] args) {

new ClickTest();

}

}

  • 上一篇:codewarrior可以編譯匯編源代碼嗎?
  • 下一篇:Jflash合並十六進制文件變大還是變小?
  • copyright 2024編程學習大全網