标题:创造图形界面
取消只看楼主
wc524500
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2010-9-14
结帖率:66.67%
 问题点数:0 回复次数:0 
创造图形界面
package yonghujiemian;
import java.awt.*;
import javax.swing.*;
public class layoutdemo extends JFrame
{
    JPanel pNorth;
    JLabel lblDrive;
    JComboBox cboDrive;
    JLabel lblSize;
    JTextField txtSize;
    JButton btnStart;
    JButton btnQuit;
    JTextArea areaStatus;
    JProgressBar pBar;
    public layoutdemo()
    {
        super("往磁盘写随机文件(务必谨慎使用)");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pNorth=new JPanel();
        getContentPane().add("north",pNorth);
        lblDrive=new JLabel("选择路径:");
        cboDrive=new JComboBox();
        for (char ch='A';ch<='H';ch++)
            cboDrive.addItem(ch+":");
        cboDrive.setSelectedIndex(2);
        lblSize=new JLabel("输入要生成文件的大小:");
        txtSize=new JTextField("100M",6);
        txtSize.setToolTipText("最大可输入65535G!");
        btnStart=new JButton("开始写程序(W)");
        btnQuit=new JButton("退出程序(Q)");
        btnStart.setMnemonic('W');
        btnQuit.setMnemonic('Q');
        pNorth.setLayout(new FlowLayout(FlowLayout.CENTER,3,3));
        pNorth.add(lblDrive);
        pNorth.add(cboDrive);
        pNorth.add(lblSize);
        pNorth.add(txtSize);
        pNorth.add(btnStart);
        pNorth.add(btnQuit);
        areaStatus=new JTextArea("启动就绪,等待你的操作…" +
                "\n提示:输入文件大小,可以用字母M或者G结尾!",7,12);
        areaStatus.setEditable(false);
        String sOsName=System.getProperty("os.name");
        areaStatus.setToolTipText(sOsName+ " Version");
        getContentPane().add("Center",scPane);
        pBar=new JProgressBar();
        getContentPane().add("South",pBar);
        Font f =new Font(null,Font.BOLD,18);
        lblDrive.setFont(f);
        cboDrive.setFont(f);
        lblSize.setFont(f);
        txtSize.setFont(f);
        btnStart.setFont(f);
        btnQuit.setFont(f);
        areaStatus.setFont(f);
        pack();
        Dimension dScreen=Toolkit.getDefaultToolkit().getScreenSize();
        double wS=dScreen.getWidth();
        double hS=dScreen.getHeight();
        int x=(int) (wS-getWidth())/2;
        int y=(int) (hS-getHeight())/2;
        setLocation(x,y);
        setVisible(true);
    }
    public static void main(String args[])
    {
        layoutdemo objHD=new layoutdemo();
    }
}
不知道为什么总是运行不了,错误提醒是:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    scPane cannot be resolved

    at yonghujiemian.layoutdemo.<init>(layoutdemo.java:45)
    at yonghujiemian.layoutdemo.main(layoutdemo.java:67)
请大家帮帮忙,看看应该怎么改。谢了啦
搜索更多相关主题的帖子: super 
2011-03-05 01:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-333260-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.954777 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved