下面的程序可以下载多个网页文件(download方法已写好),请将它改成多线程进行下载(评分占7分),如果可能, 显示计算全部下载完成程序所用的时间(提示:new Date().getTime()可以得到当前时间的毫秒数,评分占3分)。 import java.net.URL; import java.io.*; class Downloader { public static void main(String[] args) throws Exception { final URL[] urls = { new URL("http://www.pku.edu.cn"), new URL("http://www.baidu.com"), new URL("http://www.sina.com.cn"), new URL("http://www.dstang.com") }; final String[] files = { "pku.htm", "baidu.htm", "sina.htm", "study.htm", }; for(int idx=0; idx<urls.length; idx++){ try{ system.out.println(urls[idx] ); download(urls[idx], files[idx]); }catch(exception ex){ ex.printstacktrace(); } static void url url, string file) throws ioexception { try(inputstream input="url.openStream();" outputstream output="new" fileoutputstream(file)) byte[] data="new" byte[1024]; int length; while((length="input.read(data))!=-1){" output.write(data,0,length);>
第1题
下面的程序可以下载多个网页文件(download方法已写好),请将它改成多线程进行下载,如果可能, 显示计算全部下载完成程序所用的时间(提示:new Date().getTime()可以得到当前时间的毫秒数)。 import java.net.URL; import java.io.*; class Downloader { public static void main(String[] args) throws Exception { final URL[] urls = { new URL("http://www.pku.edu.cn"), new URL("http://www.baidu.com"), new URL("http://www.sina.com.cn"), new URL("http://www.dstang.com") }; final String[] files = { "pku.htm", "baidu.htm", "sina.htm", "study.htm", }; for(int idx=0; idx<urls.length; idx++){ try{ system.out.println( urls[idx] ); download( urls[idx], files[idx]); }catch(exception ex){ ex.printstacktrace(); } static void url url, string file) throws ioexception { try(inputstream input="url.openStream();" outputstream output="new" fileoutputstream(file)) byte[] data="new" byte[1024]; int length; while((length="input.read(data))!=-1){" output.write(data,0,length);>
第2题
第3题
小A是大四的学生,还有半年就要毕业了,就要跟她暗恋了三年的女神分开了。马上就是女神的生日,他想送给女神一个礼物,能让女神开心并记住他的特别礼物。他想到了电子相册,一个漂亮的网页版电子相册,因为他可以从班级网上找到女神的靓照。
第二次制作的网页女神收到礼物后跟小A说很开心,小A也非常高兴,觉得还应该在网页上增加一些小细节,来让女神感受到自己的心意。
这一次,小A想要经常更新女神的图片,但每次更新都要修改html什么的太麻烦且不方便,小A想到了新的解决方法,并顺便给每张图片配上一段说明文字:
1.写一个配置文件,以后更新女神照片和照片的说明就只需要更新这个配置文件就可以了,会比直接改动页面要方便管理。
2.把配置文件放到服务器上,在相册文件里通过接口接收配置信息并渲染到页面上,这样每次更新的时候就不需要都发给女神新的文件了,总要接收文件女神一定会很烦的吧。我们只要发给女神一次文件,以后更新图片的时候都直接在服务器上修改配置文件就可以了。
第4题
【说明】
下面的Java程序演示了如何使用Applet在网页上显示图形用户界面CUI(graphical user interface),该实例显示一个时钟。每当浏览器显现Applet的内容时都调用start()函数,让applet得以开始工作(尤其时那些被stop()函数所关闭的工作)。每当浏览器不再显现Applet的内容时都调用stop()函数,让applet得以关闭某些甚耗资源的工作调用destroy()函数之后也会调用此函数。每当浏览器将Applet从网页移除时都调用destroy()函数,已执行"applet不再被使用时"应该做的最后释放资源等动作。每当调用repaint()函数时,或网页窗口须重新刷新时调用paint()函数。
【Java程序】
import java.applet.*;
import java.awt.*;
public class ClockApplet extends (1) implements Runnable
{ //运行函数,每隔一秒刷新一次时间
public void run(){
while (true){
try{
Thread.sleep(1000);
}
catch (InterruptedException e){}
(2); //刷新当前时间
}
}
public void start(){ //调用此函数,并根据条件启动时钟线程或重起线程
if( clockThread= =null){
clockThread = new Thread(this);
clockThread. start();//启动新创建的线程
}
else
clockThread.(3);//恢复挂起的线程
}
public void stop(){ //挂起时钟线程
if (clockThread ! = null)
clockThread. (4);
}
public void destroy(){//停止时钟线程
if (5) {
clockThread.stop();
clockThread = null;
}
}
public void paint(Graphics g){//在网页上重新显示时间
g. drawString( new java.util. Date().toString(), 10,30);
}
private Thread clockThread;
}
第5题
第8题
小A是大四的学生,还有半年就要毕业了,就要跟她暗恋了三年的女神分开了。马上就是女神的生日,他想送给女神一个礼物,能让女神开心并记住他的特别礼物。他想到了电子相册,一个漂亮的网页版电子相册,因为他可以从班级网上找到女神的靓照。
1.需要可以循环播放,这样可以多放一些女神的照片。
2.循环播放时要有淡入淡出的效果,衬托出女神仙子般的气质。
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!