📄 example11_1.java.bak
字号:
import java.applet.*;import java.awt.*;import java.io.*;
import java.awt.event.*;import java.net.*;
class MyWin extends Frame implements ActionListener,Runnable
{ Button button;
URL url;
TextField text;
TextArea area;
byte b[]=new byte[118];
Thread thread;
public void init()
{ text=new TextField(20);
area=new TextArea(12,12);
button=new Button("确定");
thread=new Thread(this);
Panel p=new Panel();
p.add(new Label("输入网址:"));p.add(text); p.add(button);
button.addActionListener(this);
add(area,BorderLayout.CENTER);add(p,BorderLayout.NORTH);
setBounds(60,60,360,360);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ if(!(thread.isAlive()))
thread=new Thread(this);
try{thread.start();
}
catch(Exception ee){text.setText("我正在读取"+url);}
}
public void run()
{
try{int n=-1;
area.setText(null);
url=new URL(text.getText().trim());
InputStream in=url.openStream();
while((n=in.read(b))!=-1)
{
String s=new String(b,0,n);
area.append(s);
}
}
catch(MalformedURLException el)
{
text.setText(""+el);
return;
}
catch(IOException e1)
{
text.setText(""+e1);
return;
}
}
}
public class Example11_1
{
public static void main(String args[])
{
new MyWin;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -