Java游戏中延迟下载资源及调用示例 - 编程入门网
8 - 2009
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [url]http://www.apache.org/licenses/LICENSE-2.0[/url]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* @project loonframework
* @author chenpeng
* @email:ceponline@yahoo.com.cn
* @version 0.1
*/
public class DownloadCanvas extends Canvas implements DownloadListen {
/**
*
*/
private static final long serialVersionUID = 1L;
private DownloadTool progress; private Graphics canvasGraphics = null; private BufferStrategy bufferStrategy; private Image backgroundImage = GraphicsUtils .loadImage("image/background.jpg"); private boolean initFlag; private Window window; final static List downloadList = new ArrayList(2); Java游戏中延迟下载资源及调用示例(7)时间:2011-01-26 cping/** * 预定下载的文件 */ static { DownloadTool download1 = new DownloadTool( "http://loon-simple.googlecode.com/files/Java25DSimple.jar"); download1.setDownloadName("下载Java2.5D八法行走示例中"); DownloadTool download2 = new DownloadTool( "http://greenvm.googlecode.com/files/LocalOS_src.rar"); download2.setDownloadName("下载Java外挂入门示例中"); downloadList.add(download1); downloadList.add(download2); } public void call() { if (downloadList.size() == 0) { window.setVisible(false); window.dispose(); JarLoaderUtils.callJarMain("Java25DSimple.jar"); } else { progress = (DownloadTool) downloadList.remove(0); progress.setRectangle(rectangle); progress.download(this); } } final Rectangle rectangle; public void createBufferGraphics() { createBufferStrategy(2); bufferStrategy = getBufferStrategy(); } public DownloadCanvas(Window window, int width, int height) { int pw = 600; int ph = 27; this.rectangle = new Rectangle(width / 2 - pw / 2, height / 2 - ph / 2, pw, ph); this.window = window; this.call(); } public synchronized void updateScreen() { canvasGraphics = bufferStrategy.getDrawGraphics(); if (!initFlag) { canvasGraphics.drawImage(backgroundImage, 0, 0, null); initFlag = true; } else { progress.draw(canvasGraphics); } bufferStrategy.show(); canvasGraphics.dispose(); Toolkit.getDefaultToolkit().sync(); Thread.yield(); } } Java游戏中延迟下载资源及调用示例(8)时间:2011-01-26 cpingMain.java(主类,用以启动此下载示例) package org.loon.game.simple.download; import java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /** * Copyright 2008 - 2009 * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |