“在正常情况下,一个面板不能得到键盘输入,也就是说,它不能接受任何键盘事件。为了使其能够接受焦点,我们重载了SketchPanel类中的isFocusTraversable方法,使其返回true。” 这是Core Java关于这段代码的一段说明。可是我不明白,这个isFocusTraversable方法是什么时候调用的? import java.util.*; import java.awt.event.*; import javax.swing.*;public class Sketch { public static void main(String[] args) { SketchFrame frame = new SketchFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } }/** A frame with a panel for sketching a figure */ class SketchFrame extends JFrame { public SketchFrame() { setTitle("Sketch"); setSize(WIDTH,HEIGHT); //add panel to frame SketchPanel panel = new SketchPanel(); Container contentPane = getContentPane(); contentPane.add(panel); } public static final int WIDTH = 300; public static final int HEIGHT = 200; }
这是Core Java关于这段代码的一段说明。可是我不明白,这个isFocusTraversable方法是什么时候调用的?
import java.util.*;
import java.awt.event.*;
import javax.swing.*;public class Sketch
{
public static void main(String[] args)
{
SketchFrame frame = new SketchFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}/**
A frame with a panel for sketching a figure
*/
class SketchFrame extends JFrame
{
public SketchFrame()
{
setTitle("Sketch");
setSize(WIDTH,HEIGHT); //add panel to frame SketchPanel panel = new SketchPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
} public static final int WIDTH = 300;
public static final int HEIGHT = 200;
}
支持tab