📄 ex.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Ex
{
Frame f;
Button[] b;
Panel p;
TextField t;
int i=0;
int j=0;
public Ex()
{
f = new Frame("鬼子进村");
String[] s={"小张","小王","小刘","小李","小白","小黄"};
b = new Button[s.length];
p=new Panel();
p.setBackground(Color.orange);
t = new TextField(10);
for (int i = 0; i<s.length; i++)
{
b[i]= new Button(s[i]);
b[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
t.setText("鬼子进"+s+"家了");
}
});
p.add(b[i]);
}
p.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e)
{
i=j;
t.setText("鬼子跑了");
}
});
f.add(p,BorderLayout.NORTH);
f.add(t,BorderLayout.SOUTH);
f.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e)
{
i++;
t.setText("鬼子第"+i+"次进村");
}
public void mouseExited(MouseEvent e)
{
j=i;
i=0;
t.setText("鬼子跑了");
}
});
f.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
t.setText("鬼子的位置X:"+x+"Y:"+y);
}
});
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String[] args)
{
new Ex();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -