用jdk1.6和eclipse都试过,好像说类名FrmAbout出错,看不懂。求解:源程序如下:import javax.swing.*;
public class FrmAbout extends JFrame {
JLabel lblText, lblLogo;
JButton btnSysinfo,btnExit;
JPanel pnlMain;
public FrmAbout() {
lblText = new JLabel("Happy 聊天室V1.1 Copyright2007-2010");
lblLogo = new JLabel(new ImageIcon("logo.gif"));
btnSysinfo = new JButton("系统信息(S)");
btnSysinfo.setMnemonic('S');
btnExit = new JButton("退出", new ImageIcon("exit.gif"));
pnlMain = new JPanel();
pnlMain.add(lblText);
pnlMain.add(lblLogo);
pnlMain.add(btnSysinfo);
pnlMain.add(btnExit);
this.setContentPane(pnlMain);
setSize(250,200);
setTitle("关于Java GUI");
setVisible(true);
setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]){
new FrmAbout();
}报错为:(jdk1.6) FrmAbout.java:28:非法字符: \1288
new FrmAbout();
public class FrmAbout extends JFrame {
JLabel lblText, lblLogo;
JButton btnSysinfo,btnExit;
JPanel pnlMain;
public FrmAbout() {
lblText = new JLabel("Happy 聊天室V1.1 Copyright2007-2010");
lblLogo = new JLabel(new ImageIcon("logo.gif"));
btnSysinfo = new JButton("系统信息(S)");
btnSysinfo.setMnemonic('S');
btnExit = new JButton("退出", new ImageIcon("exit.gif"));
pnlMain = new JPanel();
pnlMain.add(lblText);
pnlMain.add(lblLogo);
pnlMain.add(btnSysinfo);
pnlMain.add(btnExit);
this.setContentPane(pnlMain);
setSize(250,200);
setTitle("关于Java GUI");
setVisible(true);
setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]){
new FrmAbout();
}报错为:(jdk1.6) FrmAbout.java:28:非法字符: \1288
new FrmAbout();
2.构造方法里的setVisible()方法,放到方法最后一行,或者不写,在main方法中这样写
new FrmAbout().setVisible(true);//推荐这样写
3.看这代码就是手工写的,推荐netbeans,会帮助你提高开发效率和代码规范
JLabel lblText, lblLogo;
JButton btnSysinfo, btnExit;
JPanel pnlMain; public FrmAbout() {
lblText = new JLabel("Happy 聊天室V1.1 Copyright2007-2010");
lblLogo = new JLabel(new ImageIcon("logo.gif"));
btnSysinfo = new JButton("系统信息(S)");
btnSysinfo.setMnemonic('S');
btnExit = new JButton("退出", new ImageIcon("exit.gif"));
pnlMain = new JPanel();
pnlMain.add(lblText);
pnlMain.add(lblLogo);
pnlMain.add(btnSysinfo);
pnlMain.add(btnExit);
this.setContentPane(pnlMain);
setSize(250, 200);
setTitle("关于Java GUI");
setVisible(true);
setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
} public static void main(String args[]) {
new FrmAbout();
}
}
myeclipse6.5 jdk1.5 运行没错啊!
支持 2 楼的,尽量用开发工具来做GUI