Advertisement
AzerothGT

Untitled

May 14th, 2024
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.46 KB | None | 0 0
  1.  
  2. import java.awt.FlowLayout;
  3. import java.awt.Graphics2D;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import javax.imageio.ImageIO;
  8. import javax.swing.ImageIcon;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12.  
  13. /*
  14.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  15.  * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
  16.  */
  17.  
  18. /**
  19.  *
  20.  * @author RUMAH
  21.  */
  22. public class KOMPUTERGRAFIK_231011401267_JULIORH extends javax.swing.JFrame {
  23.  
  24.     /**
  25.      * Creates new form KOMPUTERGRAFIK_231011401267_JULIORH
  26.      */
  27.     public KOMPUTERGRAFIK_231011401267_JULIORH() {
  28.         initComponents();
  29.     }
  30. private static BufferedImage scaleImage(BufferedImage originalImage, double tinggi, double lebar) {
  31.         int newWidth = (int) (originalImage.getWidth() * lebar);
  32.         int newHeight = (int) (originalImage.getHeight() * tinggi);
  33.         BufferedImage scaledImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
  34.         Graphics2D g2d = scaledImage.createGraphics();
  35.         g2d.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
  36.         g2d.dispose();
  37.         return scaledImage;
  38.     }
  39.  
  40.     /**
  41.      * This method is called from within the constructor to initialize the form.
  42.      * WARNING: Do NOT modify this code. The content of this method is always
  43.      * regenerated by the Form Editor.
  44.      */
  45.     @SuppressWarnings("unchecked")
  46.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  47.     private void initComponents() {
  48.  
  49.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  50.  
  51.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  52.         getContentPane().setLayout(layout);
  53.         layout.setHorizontalGroup(
  54.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  55.             .addGap(0, 400, Short.MAX_VALUE)
  56.         );
  57.         layout.setVerticalGroup(
  58.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  59.             .addGap(0, 300, Short.MAX_VALUE)
  60.         );
  61.  
  62.         pack();
  63.     }// </editor-fold>                        
  64.  
  65.     /**
  66.      * @param args the command line arguments
  67.      */
  68.     public static void main(String args[]) {
  69.        
  70.             try {
  71.                 BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\RUMAH\\Pictures\\Julio.png"));
  72.  
  73.                 // Create four scaled images with custom ratios
  74.                 BufferedImage image1 = scaleImage(originalImage, 1, 1);
  75.                 BufferedImage image2 = scaleImage(originalImage, 0.5, 1);
  76.                 BufferedImage image3 = scaleImage(originalImage, 1,.5);
  77.                 BufferedImage image4 = scaleImage(originalImage, .5,.5);
  78.  
  79.                 JFrame frame = new JFrame("KOMPUTER GRAFIK_231011401267_JULIORH");
  80.                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  81.  
  82.                 JPanel panel = new JPanel();
  83.                 panel.setLayout(new FlowLayout());
  84.                 panel.add(new JLabel(new ImageIcon(image1)));
  85.                 panel.add(new JLabel(new ImageIcon(image2)));
  86.                 panel.add(new JLabel(new ImageIcon(image3)));
  87.                 panel.add(new JLabel(new ImageIcon(image4)));
  88.  
  89.                 frame.getContentPane().add(panel);
  90.                 frame.pack();
  91.                 frame.setVisible(true);
  92.             } catch (IOException e) {
  93.                 e.printStackTrace();
  94.             };
  95.        
  96.         /* Set the Nimbus look and feel */
  97.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  98.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  99.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  100.          */
  101.         try {
  102.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  103.                 if ("Nimbus".equals(info.getName())) {
  104.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  105.                     break;
  106.                 }
  107.             }
  108.         } catch (ClassNotFoundException ex) {
  109.             java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  110.         } catch (InstantiationException ex) {
  111.             java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  112.         } catch (IllegalAccessException ex) {
  113.             java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  114.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  115.             java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  116.         }
  117.         //</editor-fold>
  118.  
  119.         /* Create and display the form */
  120.         java.awt.EventQueue.invokeLater(new Runnable() {
  121.             public void run() {
  122.                 new KOMPUTERGRAFIK_231011401267_JULIORH().setVisible(true);
  123.             }
  124.         });
  125.     }
  126.  
  127.     // Variables declaration - do not modify                    
  128.     // End of variables declaration                  
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement