📄 picturepanel.java
字号:
/*
* PicturePanel.java
*
* Created on 2007年5月7日, 上午10:49
*/
package been;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.net.URL;
/**
*
* @author 下雪天
*/
public class PicturePanel extends javax.swing.JPanel {
/** Creates new form PicturePanel */
private Image image;
public PicturePanel() {
initComponents();
}
public void setImage(URL imagePath){
image=Toolkit.getDefaultToolkit().getImage(imagePath);
MediaTracker tracker=new MediaTracker(this);
tracker.addImage(image,0);
try{
tracker.waitForID(0);
}catch(InterruptedException exception){
exception.printStackTrace();
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if(image == null) return;
//int imageWidth = image.getWidth(this);
//int imageHeight = image.getHeight(this);
g.drawImage(image,0,0,null);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
}
// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -