Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author RyanR
- */
- import java.awt.*;
- import javax.swing.*;
- import java.awt.image.*;
- public class ImgPanel extends JComponent {
- private int width, height;
- private JImg panelImg;
- public ImgPanel() {
- width = 360;
- height = 240;
- panelImg = null;
- }
- public void setImage(JImg image) {
- if (image!=null) {
- width = image.getWidth();
- height = image.getHeight();
- panelImg = image;
- repaint();
- }
- }
- public void clearImage() {
- Graphics imageGraphics = panelImg.getGraphics();
- imageGraphics.setColor(Color.LIGHT_GRAY);
- imageGraphics.fillRect(0, 0, width, height);
- repaint();
- }
- public Dimension getPreferredSize() {
- return new Dimension(width, height);
- }
- public void paintComponent(Graphics g) {
- Dimension size = getSize();
- g.clearRect(0, 0, size.width, size.height);
- if(panelImg != null) {
- g.drawImage(panelImg, 0, 0, null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement