JPanel加载图像的过程

news/2024/7/11 0:40:21 标签: .net, Blog, HTML
<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/46860.html" frameborder="0" width="468" scrolling="no" height="60"></iframe>
要在JPanel上显示图像,调用了哪几个关键的类方法? 经过Debug,总结如下:

无论选择按钮或菜单来触发事件,打开图像文件

分别调用的方法依次是

按钮或菜单的事件处理方法(ButtonOpen_mouseClicked())->
自定义的加载方法(loadMyImage()) ->
Graphics对象的drawImage()->
JPanel的imageUpdate() ->
JPanel的repaint()

以下代码仅是示例,不完全

void ButtonOpen_mouseClicked(MouseEvent e) {
panel.loadChemImg(imageFile.getAbsolutePath());
}

public void loadMyImage(String s) {
originalImage = Toolkit.getDefaultToolkit().getImage(s);

if (ibuff == null) {
init_buff();
}
buffgra. drawImage(originalImage, 0, 0, this);
//这里会调用imageUpdate()
}

public boolean imageUpdate(Image originalImage, int flags, int x, int y, int w, int h) {
Color col;

if (flags == ImageObserver.ALLBITS) {
col = buffgra.getColor();
buffgra.setColor(Color.white);
buffgra.fillRect(0, 0, getWidth(), getHeight());
buffgra.drawImage(originalImage, 0, 0, this);
buffgra.setColor(col);

repaint();
//完全加载后返回false,防止再次调用
return false;
}
return true;
}

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=630329



http://www.niftyadmin.cn/n/599451.html

相关文章

VS2012远程调试(winform+web 远程调试)

VS2012远程调试 一、调试WinFrom 程序 安装rtools_setup_x64 下载 配置Remote启动Remote debugger 默认端口4016&#xff0c;选择工具-〉选项&#xff0c;选择 无身份验证并选中允许任何用户进行调试 如果选择Windows身份验证需要设置用户权限&#xff0c;点击权限 为…

山东大学软件学院WEB开发公共环境项目综述

WEB开发公共环境 目标 给WEB开发做Docker镜像&#xff0c;用K8s搭建和管理集群&#xff0c;公用的Web和DB服务&#xff0c;能够分配系统和DB帐号&#xff0c;在统一的环境里面开发 技术要点 Docker、Kubernetes、Go、Java、Python、JavaScript 团队名 政哥哥的小码农 团…

Zend Framework 手册中文版 最近更新:2006-3-17

<iframe align"top" marginwidth"0" marginheight"0" src"http://www.zealware.com/46860.html" frameborder"0" width"468" scrolling"no" height"60"></iframe>内容过多&#…

[原] 论从数据探索到数据产品的最快路径

概述 加快推动从数据探索到数据产品的过程是一件很有意义的事情&#xff0c;数据分析要如何做到尽量和数据分析的流程紧密结合&#xff0c;又要方便工程化落地一直困扰着许多数据分析师和Web工程师。数据分析师不想深究太多前端JS实现&#xff0c;Web工程师也不想插手复杂的业务…

使用代码打包一个maven项目

平常开发使用maven工具将一个maven项目打包成war包或者jar包部署&#xff0c;做项目为了实现代码的自动化部署&#xff0c;需要用代码自动完成这些操作。 下面记录代码实现过程 引入maven打包工具依赖 <!-- maven调用打包工具--><dependency><groupId&g…

Scala用特征来实现混入(mix-in)式的多重继承

2019独角兽企业重金招聘Python工程师标准>>> Scala里相当于Java接口的是特征(Trait)。Trait的英文意思是特质和性状&#xff08;本文称其为特征&#xff09;&#xff0c;实际上他比接口还功能强大。与接口不同的是&#xff0c;它还可以定义属性和方法的实现。Scala中…

spring 配置文件 数据库引入

一.mysql数据库引入 <bean id"dataSource" class"com.mchange.v2.c3p0.ComboPooledDataSource"> <property name"driverClass" value"com.mysql.jdbc.Driver" /> <property name"jdbcUrl" value"jdbc:m…

PHP IDE,Visual Studio还是Eclipse?

<iframe align"top" marginwidth"0" marginheight"0" src"http://www.zealware.com/46860.html" frameborder"0" width"468" scrolling"no" height"60"></iframe>每个程序员都有…