注册 登录
编程论坛 JAVA论坛

这个有人能直接运行吗?

ehszt 发布于 2018-02-22 21:41, 1810 次点击
类名为hello,改下就行
import java.awt.*;
import javax.swing.*;
public class hello extends JFrame{
    public void CreateJFrame(String title){
        JFrame jf=new JFrame(title);
        Container container=jf.getContentPane();
        JLabel jl=new JLabel("这是一个JFrame窗体");
        jl.setHorizontalAlignment(SwingConstants.CENTER);
        container.add(jl);                //我的显示这一行 出错,不知道问题在哪,照书上打的。
        container.setBackground(Color.white);
        jf.setVisible(true);
        jf.setSize(200,150);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        }
    public static void main(String[] args){
        new hello().CreateJFrame("创建一个JFrame窗体");
    }
}
5 回复
#2
静夜思2018-02-22 21:58
直接运行没问题啊
只有本站会员才能查看附件,请 登录

#3
林月儿2018-02-22 22:08
错误信息写的什么呀
#4
疯狂的小a2018-02-22 22:21
回复 楼主 ehszt
createFrame方法名,一般首字母小写。你看的什么书,怎么一点都不规范呀
#5
ehszt2018-02-23 09:51
回复 3楼 林月儿
这是错误信息
Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at hello.main(hello.java:15)
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录
#6
ehszt2018-02-23 10:54
可能我的eclipse有点问题,重新下载一个问题就解决了。
谢谢大家。
1