📄 mousecircle.java
字号:
///////////////////////
//在下面这个例子中,当按下鼠标时,一个圆不断地增大半径。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MouseCircle extends Applet implements MouseListener
{
TextField text;
int x;
public void init()
{
x=5;
text=new TextField(40);
add(text);
addMouseListener(this); //小程序监视小程序容器中的鼠标事件
}
public void paint(Graphics g)
{
x=x+3;
g.drawOval(10,10,x,x);
}
public void mousePressed(MouseEvent e)
{
text.setText("鼠标键按下了,位置是"+e.getX()+", "+e.getY());
repaint(); //调用这个方法时,程序将清除:paint()方法以前所
//画的内容,并再调用paint()方法。
}
public void mouseReleased(MouseEvent e)
{
text.setText("鼠标松开了,位置是"+e.getX()+","+e.getY());
}
public void mouseEntered(MouseEvent e)
{
text.setText("鼠标进来了,位置是"+e.getX()+","+e.getY());
}
public void mouseExited(MouseEvent e)
{
text.setText("鼠标走开了");
}
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount()==2)
{
text.setText("鼠标键双击。位置:"+e.getX()+","+getY());//
}
else
{}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -