import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FramePanel {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
NotHelloWorldFrame frame = new NotHelloWorldFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
/*
* A frame that contains a message panel
*
*/
}
class NotHelloWorldFrame extends JFrame
{
public void NotHelloWorldFrame()
{
setTitle("NotHello");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
//add panel to frame
NotHelloWorldPanel panel = new NotHelloWorldPanel();
add(panel);
}
public static final int DEFAULT_WIDTH =300;
public static final int DEFAULT_HEIGHT =200 ;
}
/*
* A panel that display a message;
*
*/
class NotHelloWorldPanel extends JPanel
{
public void paintComponent(Graphics g)
{
g.drawString("Not a hello,world program", x, y);
}
public static final int x = 75;
public static final int y =100;
}
小弟新手,不懂这个程序运行出来为什么出现在屏幕左上角,然后什么都没有,没字也没size..,求帮帮忙,哪里错了
------解决思路----------------------
public void NotHelloWorldFrame()
把void去掉 要不然你就没有构造函数了,变成普通方法了