G
gxhu
Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是jbuilder8.0,就两个文件,请帮忙看看。
Frame1.java原代码如下:
package URLDemo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.*;
import java.net.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
Label label1 = new Label();
TextField textField1 = new TextField();
Button button1 = new Button();
TextArea textArea1 = new TextArea();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
label1.setText("URL地址");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
button1.setLabel("读入");
button1.addActionListener(new Frame1_button1_actionAdapter(this));
textField1.setText("");
textArea1.setText("");
contentPane.add(label1, new XYConstraints(52, 34, 35, 22));
contentPane.add(textField1, new XYConstraints(95, 34, 117, 24));
contentPane.add(button1, new XYConstraints(267, 39, 53, 23));
contentPane.add(textArea1, new XYConstraints(40, 73, 308, 204));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void button1_actionPerformed(ActionEvent e) {
try {
URL url = new URL(textField1.getText());
String inputLine = "";
InputStream is = url.openStream();
InputStream bis = new BufferedInputStream(is);
InputStreamReader r = new InputStreamReader(bis);
int c;
while ( (c = r.read()) != 1) {
inputLine += (char) c;
textArea1.setText(inputLine);
bis.close();
}
catch (MalformedURLException e) {
e.parintStackTrace();
}
}
}
}
class Frame1_button1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
URLDemo.java原代码如下:
package URLDemo;
import javax.swing.UIManager;
import java.awt.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class URLDemo {
boolean packFrame = false;
//Construct the application
public URLDemo() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else
{
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height >
screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width >
screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new URLDemo();
}
}
错误如下:
"Frame1.java": Error #: 212 : 'catch' without 'try' at line 76, column 7
"Frame1.java": Error #: 209 : 'try' without 'catch' or 'finally' at line 64, column 5
"URLDemo.java": Error #: 300 : class Frame1 not found in class URLDemo.URLDemo at line 20, column 5
"URLDemo.java": Error #: 300 : class Frame1 not found in class URLDemo.URLDemo at line 20, column 24
Frame1.java原代码如下:
package URLDemo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.*;
import java.net.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
Label label1 = new Label();
TextField textField1 = new TextField();
Button button1 = new Button();
TextArea textArea1 = new TextArea();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
label1.setText("URL地址");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
button1.setLabel("读入");
button1.addActionListener(new Frame1_button1_actionAdapter(this));
textField1.setText("");
textArea1.setText("");
contentPane.add(label1, new XYConstraints(52, 34, 35, 22));
contentPane.add(textField1, new XYConstraints(95, 34, 117, 24));
contentPane.add(button1, new XYConstraints(267, 39, 53, 23));
contentPane.add(textArea1, new XYConstraints(40, 73, 308, 204));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void button1_actionPerformed(ActionEvent e) {
try {
URL url = new URL(textField1.getText());
String inputLine = "";
InputStream is = url.openStream();
InputStream bis = new BufferedInputStream(is);
InputStreamReader r = new InputStreamReader(bis);
int c;
while ( (c = r.read()) != 1) {
inputLine += (char) c;
textArea1.setText(inputLine);
bis.close();
}
catch (MalformedURLException e) {
e.parintStackTrace();
}
}
}
}
class Frame1_button1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
URLDemo.java原代码如下:
package URLDemo;
import javax.swing.UIManager;
import java.awt.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class URLDemo {
boolean packFrame = false;
//Construct the application
public URLDemo() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else
{
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height >
screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width >
screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new URLDemo();
}
}
错误如下:
"Frame1.java": Error #: 212 : 'catch' without 'try' at line 76, column 7
"Frame1.java": Error #: 209 : 'try' without 'catch' or 'finally' at line 64, column 5
"URLDemo.java": Error #: 300 : class Frame1 not found in class URLDemo.URLDemo at line 20, column 5
"URLDemo.java": Error #: 300 : class Frame1 not found in class URLDemo.URLDemo at line 20, column 24