java窗口helloworld程序为何窗口中未显示“hello world program"文字
求大虾解答,我是照java2核心技术书上程序写的,为何窗口未显示文字
以下是程序:
import javax.swing.*;
import java.awt.*;
public class Frame1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleFrame frame=new SimpleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class SimpleFrame extends JFrame{
public SimpleFrame(){
setSize(600,600);
setTitle("hello");
Simplepanel ss=new Simplepanel();
add(ss);
}
}
class Simplepanel extends JPanel{
public static int message_x=75;
public static int message_y=100;
public void paintConponent(Graphics g){
super.paintComponent(g);
g.drawString("not a hello,world program", message_x, message_y);
}
}
------解决方案--------------------
paintConponent -> paintComponent
Java code
class Simplepanel extends JPanel {
public static int message_x = 75;
public static int message_y = 100;
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.drawString("not a hello,world program", message_x, message_y);
}
}