当前位置: 代码迷 >> Java相关 >> java窗口helloworld程序为什么窗口中未显示“hello world program"文字
  详细解决方案

java窗口helloworld程序为什么窗口中未显示“hello world program"文字

热度:10553   发布时间:2013-02-25 21:45:26.0
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);    }}
  相关解决方案