?? mypanel.java~4~
字號:
package texturepaint;import java.awt.*;import java.awt.geom.*;import java.awt.image.*;import java.net.*;import javax.swing.*;/** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */public class MyPanel extends JPanel { BorderLayout borderLayout1 = new BorderLayout(); public MyPanel() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { this.setLayout(borderLayout1); } public void paintComponent(Graphics g) { try{clear(g); Graphics2D g2d = (Graphics2D)g; URL imageFile1 = MyPanel.class.getResource("FACE.JPG"); URL imageFile2 = MyPanel.class.getResource("COFFEE.JPG"); Image faceImage = this.getToolkit().getImage(imageFile1); Image coffeeImage = this.getToolkit().getImage(imageFile2); BufferedImage bf1 = new BufferedImage(faceImage.getWidth(this),faceImage.getHeight(this),BufferedImage.TYPE_INT_RGB); Graphics2D g2d1 = bf1.createGraphics(); g2d1.drawImage(faceImage, 0, 0, this); Rectangle imageRect = new Rectangle(0, 0, faceImage.getWidth(this), faceImage.getHeight(this)); TexturePaint imagePaint = new TexturePaint(bf1, imageRect); g2d.setPaint(imagePaint); Rectangle fillArea = new Rectangle(0, 0, this.getWidth(), this.getHeight()); g2d.fill(fillArea); g2d.drawImage(coffeeImage, (this.getWidth()-coffeeImage.getWidth(this))/2, (this.getHeight()-coffeeImage.getHeight(this))/2, this); }catch (Exception ex){} } protected void clear(Graphics g) { super.paintComponent(g); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -