import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class HtmlJFrame extends JFrame implements Itemlistener{
private URL url;
private JComboBox combobox_url;
private JTextArea text_content;
private JTextField text_attribute;
public HtmlJFrame(){
super("URL");
setSize(640,320);
setLocation(320,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
String urls[]={"file://localhost/c:","http://www.edu.cn"};
combobox_url=new JComboBox(urls);
combobox_url.setEditable(true);
combobox_url.addItemListener(this);
add(combobox_url,"North");
text_content=new JTextArea();
add(text_content);
text_attribute=new JTextField();
add(text_attribute,"South");
setVisible(true);try{
this.url=new URL(url[0]);
this.readFormFile();
text_attribute.setText(this.getAttribute());}
catch(MalformedURLException murle){
System.out.println(murle);
}
}
public void readFormFile(){
try{
InputStreamReader in=new InputStreamReader(this.url.openStream());
BufferedReader bin=new BufferedReader(in);
String aline="";
do{
aline=bin.readLine();
if(aline!=null)
   text_content.append(aline+"\r\n");
}while(aline!=null);
bin.close();
in.close();
}catch(IOException ioe){
System.out.print(ioe);
}}
public String getAttribute(){
String str_attr="文件:";
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm");
if(url.getProtocol().equals("file")){
File afile=new File(url.getFile());str_attr+=afile.getAbsolutePath()+"/t";
str_attr+=afile.length()+"B/t";
str_attr+=sdf.format(new Date(afile.lastModified()));
}if(url.getProtocol().equals("http")){
{
  try{
URLConnection urlconn=url.openConnection();
str_attr+=url.toString()+"\t";
str_attr+=urlconn.getContentLength()+"B\t";
str_attr+=urlconn.getContentType()+"\t";
str_attr+=sdf.format(new Date(urlconn.getLastModifield()));
}catch(IOException ioe){
System.out.print(ioe);
}
}return str_attr;
}
public void itemStateChanged(ItemEvent e)
{
String urlname=(String)combobox_url.getSelectedItem();try{
this.url=new URL(urlname);
this.readFormFile();
text_attribute.setText(this.getAttribute());
}
catch(MalformedURLException murle){System.out.println(murle);}}public static void main(String[] args)
{
new HtmlJFrame();
}
}
D:\>javac HtmlJFrame.java
HtmlJFrame.java:102: 非法的表达式开始
public void itemStateChanged(ItemEvent e)
^
HtmlJFrame.java:102: 非法的表达式开始
public void itemStateChanged(ItemEvent e)
       ^
HtmlJFrame.java:102: 需要 ';'
public void itemStateChanged(ItemEvent e)
                            ^
HtmlJFrame.java:102: 需要 ';'
public void itemStateChanged(ItemEvent e)
                                        ^
HtmlJFrame.java:121: 非法的表达式开始
public static void main(String[] args)
^
HtmlJFrame.java:121: 非法的表达式开始
public static void main(String[] args)
       ^
HtmlJFrame.java:121: 需要 ';'
public static void main(String[] args)
             ^
HtmlJFrame.java:121: 需要 ".class"
public static void main(String[] args)
                                 ^
HtmlJFrame.java:121: 需要 ';'
public static void main(String[] args)
                                     ^
HtmlJFrame.java:125: 进行语法解析时已到达文件结尾
}
 ^
10 错误

解决方案 »

  1.   

    晕死,手写的代码吗? 那么多错!import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.text.SimpleDateFormat;
    import java.util.Date;import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;public class HtmlJFrame extends JFrame implements ItemListener {
    private URL url;
    private JComboBox combobox_url;
    private JTextArea text_content;
    private JTextField text_attribute; public HtmlJFrame() {
    super("URL");
    setSize(640, 320);
    setLocation(320, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    String urls[] = { "file://localhost/c:", "file://localhost/D:" };
    combobox_url = new JComboBox(urls);
    combobox_url.setEditable(true);
    combobox_url.addItemListener(this);
    add(combobox_url, "North"); text_content = new JTextArea();
    add(text_content);
    text_attribute = new JTextField();
    add(text_attribute, "South");
    setVisible(true); try {
    this.url = new URL(urls[0]);
    this.readFormFile();
    text_attribute.setText(this.getAttribute()); } catch (MalformedURLException murle) {
    System.out.println(murle);
    } } public void readFormFile() {
    try {
    InputStreamReader in = new InputStreamReader(this.url.openStream());
    BufferedReader bin = new BufferedReader(in);
    String aline = "";
    do {
    aline = bin.readLine();
    if (aline != null)
    text_content.append(aline + "\r\n");
    } while (aline != null);
    bin.close();
    in.close();
    } catch (IOException ioe) {
    System.out.print(ioe);
    } } public String getAttribute() {
    String str_attr = "文件:";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm"); if (url.getProtocol().equals("file")) {
    File afile = new File(url.getFile()); str_attr += afile.getAbsolutePath() + "/t";
    str_attr += afile.length() + "B/t";
    str_attr += sdf.format(new Date(afile.lastModified()));
    } if (url.getProtocol().equals("http")) { try {
    URLConnection urlconn = url.openConnection();
    str_attr += url.toString() + "\t";
    str_attr += urlconn.getContentLength() + "B\t";
    str_attr += urlconn.getContentType() + "\t";
    str_attr += sdf.format(new Date(urlconn.getLastModified()));
    } catch (IOException ioe) {
    System.out.print(ioe);
    }
    }
    return str_attr;
    } public void itemStateChanged(ItemEvent e) {
    String urlname = (String) combobox_url.getSelectedItem(); try {
    this.url = new URL(urlname);
    this.readFormFile();
    text_attribute.setText(this.getAttribute());
    } catch (MalformedURLException murle) {
    System.out.println(murle);
    } } public static void main(String[] args) {
    new HtmlJFrame();
    }
    }
      

  2.   

    楼主不用编译器吗?import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.text.SimpleDateFormat;public class HtmlJFrame extends JFrame implements ItemListener {
    private URL url;
    private JComboBox combobox_url;
    private JTextArea text_content;
    private JTextField text_attribute; public HtmlJFrame() {
    super("URL");
    setSize(640, 320);
    setLocation(320, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    String urls[] = { "file://localhost/c:", "http://www.edu.cn" };
    combobox_url = new JComboBox(urls);
    combobox_url.setEditable(true);
    combobox_url.addItemListener(this);
    add(combobox_url, "North");
    text_content = new JTextArea();
    add(text_content);
    text_attribute = new JTextField();
    add(text_attribute, "South");
    setVisible(true);
    try {
    this.url = new URL(url[0]);
    this.readFormFile();
    text_attribute.setText(this.getAttribute());
    } catch (MalformedURLException murle) {
    System.out.println(murle);
    }
    } public void readFormFile() {
    try {
    InputStreamReader in = new InputStreamReader(this.url.openStream());
    BufferedReader bin = new BufferedReader(in);
    String aline = "";
    do {
    aline = bin.readLine();
    if (aline != null)
    text_content.append(aline + "\r\n");
    } while (aline != null);
    bin.close();
    in.close();
    } catch (IOException ioe) {
    System.out.print(ioe);
    }
    } public String getAttribute() {
    String str_attr = "文件:";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm"); if (url.getProtocol().equals("file")) {
    File afile = new File(url.getFile()); str_attr += afile.getAbsolutePath() + "/t";
    str_attr += afile.length() + "B/t";
    str_attr += sdf.format(new Date(afile.lastModified()));
    } if (url.getProtocol().equals("http")) {
    try {
    URLConnection urlconn = url.openConnection();
    str_attr += url.toString() + "\t";
    str_attr += urlconn.getContentLength() + "B\t";
    str_attr += urlconn.getContentType() + "\t";
    str_attr += sdf.format(new Date(urlconn.getLastModified()));
    } catch (IOException ioe) {
    System.out.print(ioe);
    }
    } return str_attr;
    } public void itemStateChanged(ItemEvent e) {
    String urlname = (String) combobox_url.getSelectedItem(); try {
    this.url = new URL(urlname);
    this.readFormFile();
    text_attribute.setText(this.getAttribute());
    } catch (MalformedURLException murle) {
    System.out.println(murle);
    } } public static void main(String[] args) {
    new HtmlJFrame();
    }
    }
      

  3.   

    直接粘贴到eclipse里面,错误直接就看出来了。
      

  4.   

    COPY到工具里边去编码。我写的代码从复制到工具里去编译就没问题。拿出来手动编译就报错。
    更可气的是写:
    public class A {}
     *
    都会给我报public 这里有错。。
      

  5.   

    我都是MyEclipse 7.0 去画
    还没有手写过!更别说不用IDE了!!
    牛人!敬佩!!!
      

  6.   

    35行url[0]这个变量不是数组
    85行这个方法没有给参数urlconn.getLastModifield()
    91行差个}号
      

  7.   

    我学JAVA30多天我都是这样做的,这还算小的了,前些日子我写了386条代码改了老长的时间
    看来我的改一下
      

  8.   

    我学JAVA30多天我都是这样做的,这还算小的了,前些日子我写了386条代码改了老长的时间
    看来我的改一下
      

  9.   

    起码也得把JDK看的差不多,再不用IDE编程
      

  10.   

    COPY到工具里边去编码。我写的代码从复制到工具里去编译就没问题。拿出来手动编译就报错。 
    更可气的是写: 
    public class A {} 

    都会给我报public 这里有错。。
      

  11.   

    我明白了,谢谢各位CSDN们的回答