求助:关于图形用户界面设计
请问一下如何使用focusListener(),我知道它有两个方法,可一个组件怎样才算失去焦点,又怎样才算得到焦点呢?比如JtextArea组件,我的程序中它好象在我点击了菜单后失去了焦点,却不能再获得焦点import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class J_Frame extends JFrame
{
private JMenuBar jmb = new JMenuBar();
private JMenuItem MI[][] = {{new JMenuItem("新建"),new JMenuItem("保存"),
new JMenuItem("打开"),new JMenuItem("另存为"),
new JMenuItem("页面设置"),new JMenuItem("打印"),
new JMenuItem("退出")},{new JMenuItem("复制"),
new JMenuItem("粘贴")},{new JMenuItem("自动换行"),
new JMenuItem("字体")},{new JMenuItem("帮助主题"),
new JMenuItem("关于记事本")}};
private JMenu menu[] = {new JMenu("文件(F)"),new JMenu("编辑(E)"),
new JMenu("格式(O)"),new JMenu("帮助(H)")};
private TextArea jta = new TextArea();
private J_Action jaction = new J_Action();
public J_Frame()
{
jta.setSize(760,550);
for(int i = 0;i < 4;i++)
{
menu[i].addActionListener(jaction);
jmb.add(menu[i]);
for(int j = 0;j < MI[i].length;j++)
{
MI[i][j].addActionListener(jaction);
menu[i].add(MI[i][j]);
}
}
jta.addFocusListener(new FocusListener()//////////////////
{
public void focusLost(FocusEvent e)
{
if(jta.isVisible())
jta.setVisible(false);
}
public void focusGained(FocusEvent e)
{
if(jta.isVisible() == false)
jta.setVisible(true);
}
});
this.getContentPane().add(new JScrollPane(jta));
this.setJMenuBar(jmb);
}
}
class J_Action implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String str = e.getActionCommand();
if(str == "新建")
{
System.exit(0);
}
}
}
public class J_Txt
{
public static void main(String args[])
{
J_Frame frame = new J_Frame();
frame.setTitle("新建文本文档.txt-记事本");
frame.setSize(770,570);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}