import org.imgscalr.Scalr; import javax.imageio.ImageIO; import javax.swing.*; import javax.swing.border.Border; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.image.BufferedImage; import java.io.*; import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.ArrayList; import java.util.Scanner; import com.google.zxing.BarcodeFormat; import com.google.zxing.WriterException; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.client.j2se.MatrixToImageWriter; public class AutomationEditor extends JFrame implements ActionListener { private static final int FIRST_THRESHOLD = 27; // Karakter sayısı eşiği private static final int SECOND_THRESHOLD = 45; private static final float INITIAL_FONT_SIZE = 25f; // Başlangıç yazı boyutu private static final float FIRST_REDUCED_FONT_SIZE = INITIAL_FONT_SIZE - 0f; // Küçültülmüş yazı boyutu private static final float SECOND_REDUCED_FONT_SIZE = INITIAL_FONT_SIZE - 12f; public boolean changeAllowed = false; private Dimension getCustomDimensions() { if (frame == null){ return new Dimension(200,200); } if (changeAllowed) { return new Dimension((int) (super.getParent().getBounds().width * 0.3), frame.getBounds().height); } else { return new Dimension(200, frame.getBounds().height); } } @Override public Dimension getMaximumSize() { return getCustomDimensions(); } @Override public Dimension getMinimumSize() { return getCustomDimensions(); } @Override public Dimension getPreferredSize() { return getCustomDimensions(); } private BufferedImage transparentQRImage; private BufferedImage transparentResimImage; private final JFileChooser openFileChooser; private final JFileChooser saveFileChooser; Border blackline = BorderFactory.createLineBorder(Color.black); JMenu fileMenu; JMenuBar menuBar; JMenuItem openItem; JMenuItem saveItem; JMenuItem exitItem; JPanel panel; JFrame frame; JButton resimButton; JButton qrButton; JButton saveButton; JLabel yilkaLabel; JLabel firmaLabel; JLabel parcaLabel; JLabel sablonNoLabel; JLabel qrLabel; JLabel emptyQRLabel = new JLabel(); JLabel resimLabel; JLabel emptyResimLabel = new JLabel(); JTextArea yilkaTextArea; JTextArea firmaTextArea; JTextArea parcaTextArea; JScrollPane yilkaScrollPane; JScrollPane firmaScrollPane; JScrollPane parcaScrollPane; JTextField resimTextField; public AutomationEditor(){ openFileChooser = new JFileChooser(); openFileChooser.setCurrentDirectory(new File(".")); openFileChooser.setFileFilter(new FileNameExtensionFilter("Kaydedilen Dosyalar", "xdd")); saveFileChooser = new JFileChooser(); saveFileChooser.setCurrentDirectory(new File(".")); saveFileChooser.setFileFilter(new FileNameExtensionFilter("Kaydedilen Dosyalar", "xdd")); frame = new JFrame("YILKA DEPO OTOMASYONU"); frame.setBounds(860,570,860,570); panel = new JPanel(); panel.setLayout(new GridBagLayout()); panel.setPreferredSize(new Dimension(860,570)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); GridBagConstraints constraints1 = new GridBagConstraints(); constraints1.gridx = 1; constraints1.gridy = 1; constraints1.weightx = 2; constraints1.gridwidth = 1; constraints1.gridheight =1; constraints1.anchor = GridBagConstraints.NORTHWEST; constraints1.insets = new Insets(0, 20, 0, 0); constraints1.fill = GridBagConstraints.BOTH; GridBagConstraints constraints2 = new GridBagConstraints(); constraints2.gridx = 2; constraints2.gridy = 1; constraints2.weightx = 2; constraints2.gridwidth = 1; constraints2.gridheight =1; constraints2.anchor = GridBagConstraints.NORTHEAST; constraints2.insets = new Insets(0, 0, 0, 20); constraints2.fill = GridBagConstraints.BOTH; GridBagConstraints constraints3 = new GridBagConstraints(); constraints3.gridx = 1; constraints3.gridy = 2; constraints3.weightx = 2; constraints3.gridwidth = 1; constraints3.gridheight =1; constraints3.anchor = GridBagConstraints.WEST; constraints3.insets = new Insets(0, 20, 0, 0); constraints3.fill = GridBagConstraints.BOTH; GridBagConstraints constraints4 = new GridBagConstraints(); constraints4.gridx = 2; constraints4.gridy = 2; constraints4.weightx = 2; constraints4.gridwidth = 1; constraints4.gridheight =1; constraints4.anchor = GridBagConstraints.EAST; constraints4.insets = new Insets(0, 0, 0, 20); constraints4.fill = GridBagConstraints.BOTH; GridBagConstraints constraints5 = new GridBagConstraints(); constraints5.gridx = 1; constraints5.gridy = 3; constraints5.weightx = 2; constraints5.gridwidth = 1; constraints5.gridheight =1; constraints5.anchor = GridBagConstraints.WEST; constraints5.insets = new Insets(0, 20, 0, 0); constraints5.fill = GridBagConstraints.BOTH; GridBagConstraints constraints6 = new GridBagConstraints(); constraints6.gridx = 2; constraints6.gridy = 3; constraints6.weightx = 2; constraints6.gridwidth = 1; constraints6.gridheight =1; constraints6.anchor = GridBagConstraints.EAST; constraints6.insets = new Insets(0, 0, 0, 20); constraints6.fill = GridBagConstraints.BOTH; GridBagConstraints constraints7 = new GridBagConstraints(); constraints7.gridx = 1; constraints7.gridy = 6; constraints7.weightx = 2; constraints7.gridwidth = 1; constraints7.gridheight =1; constraints7.anchor = GridBagConstraints.EAST; constraints7.insets = new Insets(20, 20, 0, 0); constraints7.fill = GridBagConstraints.BOTH; GridBagConstraints constraints8 = new GridBagConstraints(); constraints8.gridx = 2; constraints8.gridy = 6; constraints8.weightx = 2; constraints8.gridwidth = 1; constraints8.gridheight =1; constraints8.anchor = GridBagConstraints.EAST; constraints8.insets = new Insets(20, 0, 0, 20); constraints8.fill = GridBagConstraints.BOTH; GridBagConstraints constraints9 = new GridBagConstraints(); constraints9.gridx = 1; constraints9.gridy = 5; constraints9.weightx = 2; constraints9.gridwidth = 1; constraints9.gridheight =1; constraints9.anchor = GridBagConstraints.WEST; constraints9.fill = GridBagConstraints.BOTH; constraints9.insets = new Insets(0, 20, 0, 0); GridBagConstraints constraints10 = new GridBagConstraints(); constraints10.gridx = 2; constraints10.gridy = 5; constraints10.weightx = 2; constraints10.gridwidth = 1; constraints10.gridheight =1; constraints10.anchor = GridBagConstraints.EAST; constraints10.insets = new Insets(0, 0, 0, 20); constraints10.fill = GridBagConstraints.BOTH; GridBagConstraints constraintsDown1 = new GridBagConstraints(); constraintsDown1.gridx = 1; constraintsDown1.gridy = 4; constraintsDown1.weightx = 2; constraintsDown1.gridheight = 2; constraintsDown1.gridwidth = 1; constraintsDown1.fill = GridBagConstraints.BOTH; constraintsDown1.insets = new Insets(0, 20, 20, 0); constraintsDown1.anchor = GridBagConstraints.WEST; GridBagConstraints constraintsDown2 = new GridBagConstraints(); constraintsDown2.gridx = 2; constraintsDown2.gridy = 4; constraintsDown2.weightx = 2; constraintsDown2.gridheight = 2; constraintsDown2.gridwidth = 1; constraintsDown2.anchor = GridBagConstraints.EAST; constraintsDown2.insets = new Insets(0, 0, 20, 20); constraintsDown2.fill = GridBagConstraints.BOTH; GridBagConstraints constraintsDown3 = new GridBagConstraints(); constraintsDown3.gridx = 1; constraintsDown3.gridy = 8; constraintsDown3.weightx = 2; constraintsDown3.gridheight = 1; constraintsDown3.gridwidth = 1; constraintsDown3.anchor = GridBagConstraints.SOUTHWEST; constraintsDown3.insets = new Insets(0,20,20,0); constraintsDown3.fill = GridBagConstraints.BOTH; yilkaLabel = new JLabel("YILKA KODU :"); yilkaLabel.setBorder(blackline); yilkaLabel.setFont(new Font("Arial", Font.BOLD, 20)); yilkaTextArea = new JTextArea(new LimitDocument(100)); yilkaTextArea.setWrapStyleWord(true); yilkaTextArea.setLineWrap(true); JScrollPane yilkaScrollPane = new JScrollPane(yilkaTextArea); yilkaScrollPane.setBorder(blackline); yilkaScrollPane.setViewportView(yilkaTextArea); yilkaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); yilkaTextArea.setFont(new Font("Arial",Font.PLAIN,25)); yilkaTextArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateFontSize(); } @Override public void removeUpdate(DocumentEvent e) { updateFontSize(); } @Override public void changedUpdate(DocumentEvent e) { updateFontSize(); } private void updateFontSize() { int textLength = yilkaTextArea.getText().length(); float newSize; if (textLength > SECOND_THRESHOLD) { newSize = SECOND_REDUCED_FONT_SIZE; } else if (textLength > FIRST_THRESHOLD) { newSize = FIRST_REDUCED_FONT_SIZE; } else { newSize = INITIAL_FONT_SIZE; } yilkaTextArea.setFont(yilkaTextArea.getFont().deriveFont(newSize)); } }); firmaLabel = new JLabel("FİRMA KODU :"); firmaLabel.setFont(new Font("Arial", Font.BOLD,20)); firmaLabel.setBorder(blackline); firmaTextArea = new JTextArea(new LimitDocument(100)); firmaTextArea.setLineWrap(true); firmaTextArea.setWrapStyleWord(true); JScrollPane firmaScrollPane = new JScrollPane(firmaTextArea); firmaScrollPane.setBorder(blackline); firmaScrollPane.setViewportView(firmaTextArea); firmaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); firmaTextArea.setFont(new Font("Arial",Font.PLAIN,25)); firmaTextArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateFontSize(); } @Override public void removeUpdate(DocumentEvent e) { updateFontSize(); } @Override public void changedUpdate(DocumentEvent e) { updateFontSize(); } private void updateFontSize() { int textLength = firmaTextArea.getText().length(); float newSize; if (textLength > SECOND_THRESHOLD) { newSize = SECOND_REDUCED_FONT_SIZE; } else if (textLength > FIRST_THRESHOLD) { newSize = FIRST_REDUCED_FONT_SIZE; } else { newSize = INITIAL_FONT_SIZE; } firmaTextArea.setFont(firmaTextArea.getFont().deriveFont(newSize)); } }); parcaLabel = new JLabel("PARÇA ADI :"); parcaLabel.setFont(new Font("Arial",Font.BOLD,20)); parcaLabel.setBorder(blackline); parcaLabel.setHorizontalAlignment(SwingConstants.LEFT); parcaLabel.setVerticalAlignment(SwingConstants.TOP); parcaTextArea = new JTextArea(new LimitDocument(100)); parcaTextArea.setWrapStyleWord(true); parcaTextArea.setLineWrap(true); JScrollPane parcaScrollPane = new JScrollPane(parcaTextArea); parcaScrollPane.setBorder(blackline); parcaScrollPane.setViewportView(parcaTextArea); parcaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); parcaTextArea.setFont(new Font("Arial",Font.PLAIN,20)); parcaTextArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateFontSize(); } @Override public void removeUpdate(DocumentEvent e) { updateFontSize(); } @Override public void changedUpdate(DocumentEvent e) { updateFontSize(); } private void updateFontSize() { int textLength = parcaTextArea.getText().length(); float newSize; if (textLength > FIRST_THRESHOLD) { newSize = FIRST_REDUCED_FONT_SIZE; } else { newSize = INITIAL_FONT_SIZE; } parcaTextArea.setFont(parcaTextArea.getFont().deriveFont(newSize)); } }); // TODO QR BUTONU&LABEL qrLabel = new JLabel(); qrLabel.setBorder(blackline); qrLabel.setHorizontalAlignment(SwingConstants.CENTER); qrLabel.setVerticalAlignment(SwingConstants.CENTER); qrButton = new JButton("QR oluşturmak için tıklayın."); qrButton.addActionListener(this); //TODO SON // TODO RESİM BUTONU VE LABEL resimLabel = new JLabel(); resimLabel.setBorder(blackline); resimLabel.setVerticalAlignment(SwingConstants.CENTER); resimLabel.setHorizontalAlignment(SwingConstants.CENTER); resimButton = new JButton("Resim koymak için tıklayın."); resimButton.addActionListener(this); //TODO SON //TODO SAVEBUTTON saveButton = new JButton("KAYDET"); saveButton.addActionListener(this); //TODO MENU menuBar = new JMenuBar(); fileMenu = new JMenu("File"); openItem = new JMenuItem("Open"); saveItem = new JMenuItem("Save"); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); openItem.addActionListener(this); saveItem.addActionListener(this); fileMenu.add(openItem); fileMenu.add(saveItem); fileMenu.add(exitItem); menuBar.add(fileMenu); yilkaLabel.setPreferredSize(new Dimension(200,29)); yilkaTextArea.setPreferredSize(new Dimension(400,27)); firmaLabel.setPreferredSize(new Dimension(200,29)); firmaTextArea.setPreferredSize(new Dimension(400,27)); parcaLabel.setPreferredSize(new Dimension(200,58)); parcaTextArea.setPreferredSize(new Dimension(400,56)); qrButton.setPreferredSize(new Dimension(240,20)); emptyQRLabel.setPreferredSize(new Dimension(240,20)); resimButton.setPreferredSize(new Dimension(360,20)); emptyResimLabel.setPreferredSize(new Dimension(360,20)); qrLabel.setPreferredSize(new Dimension(230,500)); resimLabel.setPreferredSize(new Dimension(400,500)); panel.add(yilkaLabel, constraints1); panel.add(yilkaScrollPane, constraints2); panel.add(firmaLabel, constraints3); panel.add(firmaScrollPane, constraints4); panel.add(parcaLabel, constraints5); panel.add(parcaScrollPane, constraints6); panel.add(qrButton, constraints7); panel.add(resimButton, constraints8); panel.add(emptyQRLabel, constraints9); panel.add(emptyResimLabel, constraints10); panel.add(qrLabel, constraintsDown1); panel.add(resimLabel, constraintsDown2); panel.add(saveButton,constraintsDown3); int fWidth = frame.getWidth(); int fHeight = frame.getHeight(); panel.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent e) { panel.setSize(frame.getWidth(),frame.getHeight()); panel.revalidate(); panel.repaint(); } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentShown(ComponentEvent e) { } @Override public void componentHidden(ComponentEvent e) { } }); frame.setJMenuBar(menuBar); frame.add(panel); frame.revalidate(); frame.pack(); frame.repaint(); frame.setLocationRelativeTo(null); frame.setVisible(true); } class LimitDocument extends PlainDocument{ private int limit; LimitDocument(int limit) { super(); this.limit = limit; } @Override public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException { if (str == null) return; // Metin alanındaki karakter sayısını kontrol ediyoruz if ((getLength() + str.length()) <= limit) { super.insertString(offset, str, attr); } } } @Override public void actionPerformed(ActionEvent e) { BufferedImage originalImage; if (e.getSource() == resimButton) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("C:/Users/Berkay Güner/Documents")); FileNameExtensionFilter filter = new FileNameExtensionFilter("Resim Dosyaları", "png", "jpg", "jpeg"); fileChooser.setFileFilter(filter); int response = fileChooser.showOpenDialog(null); if (response == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); Scanner fileIn = null; try { originalImage = ImageIO.read(file); Color backgroundColor = Color.WHITE; int targetWidth = 300; int targetHeight = 240; BufferedImage resizedImage = simpleResizeImage(originalImage, targetWidth, targetHeight ); BufferedImage transparentResimImage = removeBackground(resizedImage,backgroundColor); File outputFile = new File("resimoutput.png"); ImageIO.write(transparentResimImage, "png", outputFile); ImageIcon imageIcon = new ImageIcon(transparentResimImage); imageIcon.setDescription(outputFile.getAbsolutePath()); resimLabel.setIcon(imageIcon); resimLabel.setBounds(50, 50, targetWidth, targetHeight); panel.revalidate(); panel.repaint(); } catch (IOException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Resim Yüklenirken Bir Sorun Oluştu.", "Hata", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { throw new RuntimeException(ex); } } } if(e.getSource() == qrButton){ String input1 = yilkaTextArea.getText(); String input2 = firmaTextArea.getText(); String input3 = parcaTextArea.getText(); String combinedInput = input1 + " " + input2 + " " + input3; try{ Color backgroundColor = Color.WHITE; int targetHeight = 200; int targetWidth = 200; BufferedImage qrImage = generateQRCodeImage(combinedInput, 200,200,"QRCodeNB.png"); File outputFile1 = new File("QRCodeNB.png"); JOptionPane.showMessageDialog(frame, "QR Kod oluşturuldu: QRCodeNB.png"); BufferedImage qrResizedImage = simpleResizeImage(qrImage, targetWidth, targetHeight); BufferedImage transparentQRImage = removeBackground(qrResizedImage,backgroundColor); ImageIcon imageIcon1 = new ImageIcon(transparentQRImage); imageIcon1.setDescription(outputFile1.getAbsolutePath()); qrLabel.setIcon(imageIcon1); panel.revalidate(); panel.repaint(); } catch (WriterException | IOException ex){ ex.printStackTrace(); JOptionPane.showMessageDialog(frame, "QR kod oluşturulurken hata oluştu."); } catch (Exception ex) { throw new RuntimeException(ex); } } if (e.getSource() == openItem) { JFileChooser fileChooser = new JFileChooser(); int userSelection = fileChooser.showOpenDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToOpen = fileChooser.getSelectedFile(); String filePath = fileToOpen.getAbsolutePath(); if (filePath.endsWith(".xdd")) { try (BufferedReader reader = new BufferedReader(new FileReader(fileToOpen))) { String line; // İlk iki satırı oku ve JTextArea'lara ata yilkaTextArea.setText(reader.readLine().replace("\\n", "\n")); firmaTextArea.setText(reader.readLine().replace("\\n", "\n")); parcaTextArea.setText(reader.readLine().replace("\\n", "\n")); // Resim yollarını oku ve JLabel'lara ata String qrImagePath = reader.readLine(); if (!qrImagePath.isEmpty()) { File qrImgFile = new File(qrImagePath); if (qrImgFile.exists()) { qrLabel.setIcon(new ImageIcon(qrImagePath)); } else { qrLabel.setIcon(null); // QR resmi yoksa, ikonu temizle } } else { qrLabel.setIcon(null); // QR resmi yoksa, ikonu temizle } String resimImagePath = reader.readLine(); if (!resimImagePath.isEmpty()) { File resimImgFile = new File(resimImagePath); if (resimImgFile.exists()) { resimLabel.setIcon(new ImageIcon(resimImagePath)); } else { resimLabel.setIcon(null); // Resim yoksa, ikonu temizle } } else { resimLabel.setIcon(null); // Resim yoksa, ikonu temizle } } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Dosya okunurken bir hata oluştu: " + ex.getMessage()); } } else { JOptionPane.showMessageDialog(null, "Bu dosya uzantısı desteklenmiyor. Lütfen .xdd uzantılı bir dosya seçin."); } } } if(e.getSource() == saveItem) { JFileChooser fileChooser = new JFileChooser(); int userSelection = fileChooser.showSaveDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); String filePath = fileToSave.getAbsolutePath(); // Özel uzantıyı ekleyin if (!filePath.endsWith(".xdd")) { filePath += ".xdd"; } File finalFile = new File(filePath); try (FileWriter writer = new FileWriter(finalFile)) { // JLabel içeriğini ve resim yollarını kaydet writer.write(yilkaTextArea.getText().replace("\n" , "\\n") + "\n"); writer.write(firmaTextArea.getText().replace("\n" , "\\n") + "\n"); writer.write(parcaTextArea.getText().replace("\n" , "\\n") + "\n"); // Resim yollarını kaydet ImageIcon icon1 = (ImageIcon) qrLabel.getIcon(); writer.write((icon1 != null ? icon1.getDescription() : "") + "\n"); ImageIcon icon2 = (ImageIcon) resimLabel.getIcon(); writer.write((icon2 != null ? icon2.getDescription() : "") + "\n"); JOptionPane.showMessageDialog(null, "Dosya kaydedildi: " + finalFile.getAbsolutePath()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Dosya kaydedilirken bir hata oluştu: " + ex.getMessage()); } //EXCEPTION ÇIKARTIYOR BufferedImage panelImage = createPanelImageWithoutButtons(frame); String outputPath = fileToSave.getAbsolutePath() + ".png"; try { ImageIO.write(panelImage, "png", new File(outputPath)); openImageInNewWindow(panelImage); JOptionPane.showMessageDialog(null, "Image saved: " + outputPath); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error saving image: " + ex.getMessage()); } } } if(e.getSource() == exitItem){ System.exit(0); } if(e.getSource() == saveButton){ JFileChooser fileChooser = new JFileChooser(); int userSelection = fileChooser.showSaveDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); String filePath = fileToSave.getAbsolutePath(); // Özel uzantıyı ekleyin if (!filePath.endsWith(".xdd")) { filePath += ".xdd"; } File finalFile = new File(filePath); try (FileWriter writer = new FileWriter(finalFile)) { // JLabel içeriğini ve resim yollarını kaydet writer.write(yilkaTextArea.getText().replace("\n" , "\\n") + "\n"); writer.write(firmaTextArea.getText().replace("\n" , "\\n") + "\n"); writer.write(parcaTextArea.getText().replace("\n" , "\\n") + "\n"); // Resim yollarını kaydet ImageIcon icon1 = (ImageIcon) qrLabel.getIcon(); writer.write((icon1 != null ? icon1.getDescription() : "") + "\n"); ImageIcon icon2 = (ImageIcon) resimLabel.getIcon(); writer.write((icon2 != null ? icon2.getDescription() : "") + "\n"); JOptionPane.showMessageDialog(null, "Dosya kaydedildi: " + finalFile.getAbsolutePath()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Dosya kaydedilirken bir hata oluştu: " + ex.getMessage()); } //EXCEPTION ÇIKARTIYOR BufferedImage panelImage = createPanelImageWithoutButtons(frame); String outputPath = fileToSave.getAbsolutePath() + ".png"; try { ImageIO.write(panelImage, "png", new File(outputPath)); openImageInNewWindow(panelImage); JOptionPane.showMessageDialog(null, "Image saved: " + outputPath); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error saving image: " + ex.getMessage()); } } } } BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception { return Scalr.resize(originalImage,Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight, Scalr.OP_ANTIALIAS); } private static BufferedImage removeBackground(BufferedImage image, Color backgroundColor) { int width = image.getWidth(); int height = image.getHeight(); // Alfa kanalını destekleyen yeni bir BufferedImage oluştur BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int pixel = image.getRGB(x, y); // Renk farkını hesapla Color color = new Color(pixel, true); if (isColorSimilar(color, backgroundColor)) { // Benzerse şeffaf yap newImage.setRGB(x, y, 0x00FFFFFF); // Tamamen şeffaf piksel } else { // Aksi halde pikseli kopyala ve alfa kanalını koru newImage.setRGB(x, y, pixel); } } } return newImage; } private static boolean isColorSimilar(Color color1, Color color2) { int tolerance = 30; // Renk farkı toleransı int diff = Math.abs(color1.getRed() - color2.getRed()) + Math.abs(color1.getGreen() - color2.getGreen()) + Math.abs(color1.getBlue() - color2.getBlue()); return diff < tolerance; } private static BufferedImage generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException, IOException { QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); Path path = FileSystems.getDefault().getPath(filePath); MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path); return MatrixToImageWriter.toBufferedImage(bitMatrix); } // FONKSİYON EXCEPTION ÇIKARTIYOR private BufferedImage createPanelImageWithoutButtons(JFrame frame) { // Create a new JPanel to hold the elements without buttons JPanel panelWithoutButtons = new JPanel(); panelWithoutButtons.setLayout(new GridBagLayout()); panelWithoutButtons.setPreferredSize(new Dimension(860,570)); GridBagConstraints constraints1 = new GridBagConstraints(); constraints1.gridx = 1; constraints1.gridy = 1; constraints1.weightx = 2; constraints1.gridwidth = 1; constraints1.gridheight =1; constraints1.anchor = GridBagConstraints.NORTHWEST; constraints1.insets = new Insets(0, 20, 0, 0); constraints1.fill = GridBagConstraints.BOTH; GridBagConstraints constraints2 = new GridBagConstraints(); constraints2.gridx = 2; constraints2.gridy = 1; constraints2.weightx = 2; constraints2.gridwidth = 1; constraints2.gridheight =1; constraints2.anchor = GridBagConstraints.NORTHEAST; constraints2.insets = new Insets(0, 0, 0, 20); constraints2.fill = GridBagConstraints.BOTH; GridBagConstraints constraints3 = new GridBagConstraints(); constraints3.gridx = 1; constraints3.gridy = 2; constraints3.weightx = 2; constraints3.gridwidth = 1; constraints3.gridheight =1; constraints3.anchor = GridBagConstraints.WEST; constraints3.insets = new Insets(0, 20, 0, 0); constraints3.fill = GridBagConstraints.BOTH; GridBagConstraints constraints4 = new GridBagConstraints(); constraints4.gridx = 2; constraints4.gridy = 2; constraints4.weightx = 2; constraints4.gridwidth = 1; constraints4.gridheight =1; constraints4.anchor = GridBagConstraints.EAST; constraints4.insets = new Insets(0, 0, 0, 20); constraints4.fill = GridBagConstraints.BOTH; GridBagConstraints constraints5 = new GridBagConstraints(); constraints5.gridx = 1; constraints5.gridy = 3; constraints5.weightx = 2; constraints5.gridwidth = 1; constraints5.gridheight =1; constraints5.anchor = GridBagConstraints.WEST; constraints5.insets = new Insets(0, 20, 0, 0); constraints5.fill = GridBagConstraints.BOTH; GridBagConstraints constraints6 = new GridBagConstraints(); constraints6.gridx = 2; constraints6.gridy = 3; constraints6.weightx = 2; constraints6.gridwidth = 1; constraints6.gridheight =1; constraints6.anchor = GridBagConstraints.EAST; constraints6.insets = new Insets(0, 0, 0, 20); constraints6.fill = GridBagConstraints.BOTH; GridBagConstraints constraintsDown1 = new GridBagConstraints(); constraintsDown1.gridx = 1; constraintsDown1.gridy = 4; constraintsDown1.weightx = 2; constraintsDown1.gridheight = 2; constraintsDown1.gridwidth = 1; constraintsDown1.fill = GridBagConstraints.BOTH; constraintsDown1.insets = new Insets(0, 20, 20, 0); constraintsDown1.anchor = GridBagConstraints.WEST; GridBagConstraints constraintsDown2 = new GridBagConstraints(); constraintsDown2.gridx = 2; constraintsDown2.gridy = 4; constraintsDown2.weightx = 2; constraintsDown2.gridheight = 2; constraintsDown2.gridwidth = 1; constraintsDown2.anchor = GridBagConstraints.EAST; constraintsDown2.insets = new Insets(0, 0, 20, 20); constraintsDown2.fill = GridBagConstraints.BOTH; ArrayList constraintsList= new ArrayList<>(); constraintsList.add(constraints1); constraintsList.add(constraints2); constraintsList.add(constraints3); constraintsList.add(constraints4); constraintsList.add(constraints5); constraintsList.add(constraints6); constraintsList.add(constraintsDown1); constraintsList.add(constraintsDown2); // Iterate over the components in the original panel for (Component component : frame.getContentPane().getComponents()) { // If the component is not a button, add it to the new panel for (GridBagConstraints gridBagConstraints : constraintsList){ if (!(component instanceof JButton)) { panelWithoutButtons.add(component, gridBagConstraints); } } } // Ensure the panel's layout is updated panelWithoutButtons.revalidate(); panelWithoutButtons.repaint(); // Introduce a slight delay for layout updates to propagate try { Thread.sleep(100); // Adjust the delay as needed } catch (InterruptedException e) { e.printStackTrace(); } // Create a BufferedImage of the new panel without buttons BufferedImage image = new BufferedImage(panelWithoutButtons.getWidth(), panelWithoutButtons.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2d = image.createGraphics(); panelWithoutButtons.paint(g2d); g2d.dispose(); return image; } private void openImageInNewWindow(BufferedImage image) { JFrame imageFrame = new JFrame("Image Viewer"); imageFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JLabel imageLabel = new JLabel(new ImageIcon(image)); imageFrame.getContentPane().add(imageLabel); imageFrame.pack(); imageFrame.setLocationRelativeTo(null); imageFrame.setVisible(true); } }