10+
来自「本压缩文档为《Java大学实用教程》(7-121-00959-5 电子工业出版社」· 代码 · 共 42 行
TXT
42 行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyWindow extends JFrame implements FocusListener
{
JTextField text;
JButton button;
MyWindow(String s)
{
super(s);
text=new JTextField(10);
button=new JButton("按钮");
text.requestFocusInWindow();
Container con=getContentPane();
con.setLayout(new FlowLayout());
con.add(text);
con.add(button);
text.addFocusListener(this);
button.addFocusListener(this);
setBounds(100,100,150,150);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void focusGained(FocusEvent e)
{
JComponent com=(JComponent)e.getSource();
com.setBackground(Color.blue);
}
public void focusLost(FocusEvent e)
{
JComponent com=(JComponent)e.getSource();
com.setBackground(Color.red);
}
}
class Example
{
public static void main(String args[])
{
MyWindow win=new MyWindow("窗口");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?