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 错误
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 错误
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();
}
}
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();
}
}
更可气的是写:
public class A {}
*
都会给我报public 这里有错。。
还没有手写过!更别说不用IDE了!!
牛人!敬佩!!!
85行这个方法没有给参数urlconn.getLastModifield()
91行差个}号
看来我的改一下
看来我的改一下
更可气的是写:
public class A {}
*
都会给我报public 这里有错。。