『经典电子书下载』Java 2 图形设计卷Ⅰ:AWT Ⅱ:SWING 本帖最后由 chenweionline 于 2008-02-29 13:31:47 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 书是好书只可惜放的电子书只不过是china-pub各章阅览+光盘的源代码而已 呵呵,我觉得这套书比其他讲GUI的书籍有价值的地方在于卷ⅠAWT的前7章,毕竟讲具体组件的书籍或文章比比皆是,但是能够系统介绍AWT/Swing里绘制、图像处理方式的就不多了。 下载了,好是好东西。但是我遇到一个问题:在21,22章里复制过来的好几个代码都有这个问题。比如下面这段public class HTMLListenerTest extends JFrame {private JEditorPane editorPane = new JEditorPane();public HTMLListenerTest() {Container contentPane = getContentPane();String url = "file:" + System.getProperty("user.dir") +System.getProperty("file.separator") +"java.util.Hashtable.html";try { editorPane.setPage(url);}catch(IOException ex) { ex.printStackTrace(); }contentPane.add(new JScrollPane(editorPane), BorderLayout.CENTER);editorPane.setEditable(false);editorPane.addHyperlinkListener(new HyperlinkListener() {public void hyperlinkUpdate(HyperlinkEvent e) {try { editorPane.setPage(e.getURL());}catch(IOException ex) { ex.printStackTrace(); }}});}public static void main(String args[]) { GJApp.launch(new HTMLListenerTest(), "JEditorPane",300,300,450,300);}}class GJApp extends WindowAdapter {static private JPanel statusArea = new JPanel();static private JLabel status = new JLabel(" ");static private ResourceBundle resources;public static void launch(final JFrame f, String title,final int x, final int y, final int w, int h) {launch(f,title,x,y,w,h,null); }public static void launch(final JFrame f, String title,final int x, final int y, final int w, int h,String propertiesFilename) {f.setTitle(title);f.setBounds(x,y,w,h);f.setVisible(true);statusArea.setBorder(BorderFactory.createEtchedBorder());statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));statusArea.add(status);status.setHorizontalAlignment(JLabel.LEFT);f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);if(propertiesFilename != null) {resources = ResourceBundle.getBundle(propertiesFilename, Locale.getDefault());}f.addWindowListener(new WindowAdapter() {public void windowClosed(WindowEvent e) {System.exit(0);}});}static public JPanel getStatusArea() {return statusArea;}static public void showStatus(String s) {status.setText(s);}static Object getResource(String key) {if(resources != null) {return resources.getString(key);}return null;} }在Eclipse3.2里编译的时候就会报错:已定义类型GJApp。不知为什么?我看来看去觉得没错啊,但就是报错。LZ你能不能帮忙看看呢? 已经不用SWING了,SWT的功能强大很多,而且使用方便 现在缺的是SWT方面的书,不过还是帮楼主顶一下 书是好书 只可惜放的电子书只不过是china-pub各章阅览+光盘的源代码而已 文本编辑器中undo,redo如何使用 一个Java程序中的继承和动态绑定问题? java引用数组二分法排序问题 各位高手帮我看看这个连接数据库的错误: 计算String中subString的数量(线程) JAVA程序封装问题---急用加高分(200分) 反射问题 有没有时间/日期控件 JAVA是一个.java文件中只能有一个类吗? 有关ACCP和系统分析员 [散分]分享老轮子 邮件附件发生器(自动分卷压缩) 如何使ant可以在某个任务失败的情况下继续执行其他任务
只可惜放的电子书只不过是china-pub各章阅览+光盘的源代码而已
public class HTMLListenerTest extends JFrame {
private JEditorPane editorPane = new JEditorPane();public HTMLListenerTest() {
Container contentPane = getContentPane();
String url = "file:" + System.getProperty("user.dir") +
System.getProperty("file.separator") +
"java.util.Hashtable.html";try {
editorPane.setPage(url);
}
catch(IOException ex) { ex.printStackTrace(); }contentPane.add(new JScrollPane(editorPane),
BorderLayout.CENTER);editorPane.setEditable(false);editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
try {
editorPane.setPage(e.getURL());
}
catch(IOException ex) { ex.printStackTrace(); }
}
});
}
public static void main(String args[]) {
GJApp.launch(new HTMLListenerTest(),
"JEditorPane",300,300,450,300);
}
}
class GJApp extends WindowAdapter {
static private JPanel statusArea = new JPanel();
static private JLabel status = new JLabel(" ");
static private ResourceBundle resources;public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h) {
launch(f,title,x,y,w,h,null);
}
public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h,
String propertiesFilename) {
f.setTitle(title);
f.setBounds(x,y,w,h);
f.setVisible(true);statusArea.setBorder(BorderFactory.createEtchedBorder());
statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
statusArea.add(status);
status.setHorizontalAlignment(JLabel.LEFT);f.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);if(propertiesFilename != null) {
resources = ResourceBundle.getBundle(
propertiesFilename, Locale.getDefault());
}f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
static public JPanel getStatusArea() {
return statusArea;
}
static public void showStatus(String s) {
status.setText(s);
}
static Object getResource(String key) {
if(resources != null) {
return resources.getString(key);
}
return null;
}
}
在Eclipse3.2里编译的时候就会报错:已定义类型GJApp。
不知为什么?我看来看去觉得没错啊,但就是报错。LZ你能不能帮忙看看呢?
只可惜放的电子书只不过是china-pub各章阅览+光盘的源代码而已