创造图形界面
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)
请大家帮帮忙,看看应该怎么改。谢了啦