Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.Graphics2D;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
- */
- /**
- *
- * @author RUMAH
- */
- public class KOMPUTERGRAFIK_231011401267_JULIORH extends javax.swing.JFrame {
- /**
- * Creates new form KOMPUTERGRAFIK_231011401267_JULIORH
- */
- public KOMPUTERGRAFIK_231011401267_JULIORH() {
- initComponents();
- }
- private static BufferedImage scaleImage(BufferedImage originalImage, double tinggi, double lebar) {
- int newWidth = (int) (originalImage.getWidth() * lebar);
- int newHeight = (int) (originalImage.getHeight() * tinggi);
- BufferedImage scaledImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2d = scaledImage.createGraphics();
- g2d.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
- g2d.dispose();
- return scaledImage;
- }
- /**
- * 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.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- try {
- BufferedImage originalImage = ImageIO.read(new File("C:\\Users\\RUMAH\\Pictures\\Julio.png"));
- // Create four scaled images with custom ratios
- BufferedImage image1 = scaleImage(originalImage, 1, 1);
- BufferedImage image2 = scaleImage(originalImage, 0.5, 1);
- BufferedImage image3 = scaleImage(originalImage, 1,.5);
- BufferedImage image4 = scaleImage(originalImage, .5,.5);
- JFrame frame = new JFrame("KOMPUTER GRAFIK_231011401267_JULIORH");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- panel.setLayout(new FlowLayout());
- panel.add(new JLabel(new ImageIcon(image1)));
- panel.add(new JLabel(new ImageIcon(image2)));
- panel.add(new JLabel(new ImageIcon(image3)));
- panel.add(new JLabel(new ImageIcon(image4)));
- frame.getContentPane().add(panel);
- frame.pack();
- frame.setVisible(true);
- } catch (IOException e) {
- e.printStackTrace();
- };
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(KOMPUTERGRAFIK_231011401267_JULIORH.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new KOMPUTERGRAFIK_231011401267_JULIORH().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement