Java Graphics_7

来源:互联网 发布:淘宝网女式夏装冰丝裙 编辑:程序博客网 时间:2024/06/05 01:15

package com.han;import java.awt.Canvas;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.Toolkit;import java.net.URL;import javax.swing.JFrame;@SuppressWarnings("serial")public class Graphics_7 extends JFrame {public Graphics_7() {// TODO Auto-generated constructor stubadd(new CanvasPanel());}class CanvasPanel extends Canvas {public void paint(Graphics g) {Graphics2D g2 = (Graphics2D) g;URL imgURL = this.getClass().getResource("/images/Lighthouse.jpg");Image image = Toolkit.getDefaultToolkit().getImage(imgURL);g2.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);}}/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubGraphics_7 frame = new Graphics_7();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setTitle("绘制图片");frame.setSize(440, 300);frame.setVisible(true);}}


原创粉丝点击