急!!!!!!!编写一个java程序,在程序中建立一个窗口,操作窗口"失去焦点"与"得到焦点"的事 5
急!!!!!!!编写一个java程序,在程序中建立一个窗口,操作窗口"失去焦点"与"得到焦点"的事件...
急!!!!!!!编写一个java程序,在程序中建立一个窗口,操作窗口"失去焦点"与"得到焦点"的事件
展开
展开全部
用WindowFocusListener可以实现:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame
{
public static void main(String[] args)
{
new Test().setVisible(true);
}
public Test()
{
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addWindowFocusListener(new WindowFocusListener()
{
public void windowGainedFocus(WindowEvent e)
{
setTitle("窗体获得焦点");
}
public void windowLostFocus(WindowEvent e)
{
setTitle("窗体失去焦点");
}
});
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame
{
public static void main(String[] args)
{
new Test().setVisible(true);
}
public Test()
{
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addWindowFocusListener(new WindowFocusListener()
{
public void windowGainedFocus(WindowEvent e)
{
setTitle("窗体获得焦点");
}
public void windowLostFocus(WindowEvent e)
{
setTitle("窗体失去焦点");
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询