📄 example7_32.java
字号:
import java.awt.*;import java.awt.event.*;
class MyWindow extends Frame implements FocusListener
{ Button button;TextField text;
MyWindow(String s)
{ super(s);
button=new Button("确定");
text=new TextField(10);
text.requestFocusInWindow();
setLayout(new FlowLayout());
add(button);
add(text);
text.addFocusListener(this);
button.addFocusListener(this);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
setBounds(100,100,150,150);
setVisible(true);
validate();
}
public void focusGained(FocusEvent e)
{
Component com=(Component) e.getSource();
com.setBackground(Color.blue);
if(com==text)
text.setText(null);
}
public void focusLost(FocusEvent e)
{
Component com=(Component) e.getSource();
com.setBackground(Color.red);
}
}
public class Example7_32
{ public static void main(String args[])
{ new MyWindow("窗口");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -