JPanel没有被运行
package com.corejava.L73;/**
* 例题7-3 界面没有显示字符
*/
import java.awt.BorderLayout;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class NotHelloJava {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
NotHelloWorldFrame frame = new NotHelloWorldFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class NotHelloWorldFrame extends JFrame {
public NotHelloWorldFrame() {
setTitle("NotHelloWorld");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
NotHelloWorldPanel panel = new NotHelloWorldPanel();
add(panel);
}
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
}
class NotHelloWorldPanel extends JPanel {
public void paintComponet(Graphics g) {
super.paintComponent(g);
g.drawString("NotHelloWorldPanel", MESSAGE_X, MESSAGE_Y); // 未显示
}
public static final int MESSAGE_X = 75;
public static final int MESSAGE_Y = 100;
}
这是Java核心技术卷一第七章的例题,现在运行后没出现预期的效果(运行后在面板上会显示文字),调试发现红色代码部分未被运行,请教高手指点。