图形界面---显示图像
2016-03-27 13:43
211 查看
输入代码:
运行结果:
import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; public class ImageP extends JFrame { public ImageP() { add(new ImagePanel()); } public static void main(String[] args) { JFrame frame =new ImageP(); frame.setTitle("欢迎来到烟台大学!"); frame.setSize(300,300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } class ImagePanel extends JPanel { private ImageIcon imageIcon=new ImageIcon("haige2/yanda.jpg"); private Image image=imageIcon.getImage(); protected void paintComponent(Graphics g) { super.paintComponent(g); if(image!=null) { g.drawImage(image,0,0,getWidth(),getHeight(),this); } } }
运行结果:
相关文章推荐
- JAVA线程同步——消费者和生产者模式
- springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
- python操作Excel读写(使用xlrd和xlrt)
- tomcat WEB-INF中的结构
- 6.Utm示例-公共部分
- Thread详解2:停止与中断
- Listview adapter 总结
- Windows Linux 删除N天之前文件脚本
- 20135323符运锦----第五周:扒开系统调用的“三层皮”(下)
- GRUB的那些事
- 第五周实践项目2————游戏角色类(2)
- [组合数取模] 方法汇总
- 2001
- 今日BBC
- android用符号表定位问题
- BZOJ_P1492 [NOI2007]货币兑换Cash(CDQ分治+斜率优化)
- JMeter之基本概念-The Test Plan
- 快速存档表数据
- usb总线系统介绍
- 在mac上用AndroidStudio1.5 创建NDK开发环境