📄 download_html.java
字号:
import java.io.*;
import java.net.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Download_html extends Applet
{
TextField tfURL;
TextArea taContext;
Label lbMsg;
public void init()
{
setLayout(new BorderLayout());
tfURL = new TextField("http://localhost/");
Button btGet = new Button("DownLoad");
taContext = new TextArea(25,6);
lbMsg = new Label(" ");
Panel panel = new Panel();
panel.add(tfURL);
panel.add(btGet);
btGet.addActionListener(new GetButtonActionListener());
add(panel,BorderLayout.NORTH);
add(taContext,BorderLayout.CENTER);
add(lbMsg,BorderLayout.SOUTH);
}
class GetButtonActionListener implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
try
{
URL
url = new URL(tfURL.getText());
URLConnection
connection = url.openConnection();
connection.setDoOutput(true);
BufferedReader in =
new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
taContext.append(inputLine + "\n");
System.out.println(inputLine);
}
in.close();
}
catch(IOException e)
{
lbMsg.setText(e.toString());
}
}
}
public static void main(String[] args)
{
Download_html applet = new Download_html();
Frame aFrame = new Frame("DownLoadWebPage");
// 增加windows事件处理,用来推出程序
aFrame.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
aFrame.add(applet, BorderLayout.CENTER);
aFrame.setSize(500,500);
applet.init();
applet.start();
aFrame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -