Advertisement
shchuko

Example

Aug 26th, 2019
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package com.samurai.guicore;
  2.  
  3. import java.awt.Image;
  4. import javax.swing.JLabel;
  5. import javax.swing.JPanel;
  6. import javax.swing.ImageIcon;
  7. import java.io.File;
  8. import javax.imageio.ImageIO;
  9. import java.awt.image.BufferedImage;
  10. import java.io.IOException;
  11.  
  12.  
  13. public class StartImagePanel implements PanelFactory {
  14.     private BufferedImage imageBuf;
  15.  
  16.     public StartImagePanel(String imageFilename) throws IOException {
  17.         imageBuf = ImageIO.read(new File(imageFilename));
  18.     }
  19.  
  20.     @Override
  21.     public JPanel getPanel() {
  22.         JLabel label = new JLabel();
  23.         Image image = new ImageIcon(imageBuf).getImage();
  24.         Image scaledImage = image.getScaledInstance(452, 640,  java.awt.Image.SCALE_SMOOTH);
  25.  
  26.         label.setIcon(new ImageIcon(scaledImage));
  27.         JPanel panel = new JPanel();
  28.         panel.add(label);
  29.         return panel;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement