import java.awt.Color; import java.awt.Font; import java.awt.Graphics; 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.SwingUtilities; import javax.swing.border.LineBorder; public class AufBildZeichnenClass { String imgPath = "img/h1.jpg"; BufferedImage image; public AufBildZeichnenClass() { File file = new File(imgPath); image = loadImg(file); if (image == null) { return; } zensiere(); init(); } private void init() { JFrame frame = new JFrame("Zensiert"); ImageIcon icon = new ImageIcon(image); JLabel label = new JLabel(icon); label.setBorder(new LineBorder(Color.WHITE)); frame.add(label); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } private BufferedImage loadImg(File file) { BufferedImage image = null; try { image = ImageIO.read(file); } catch (IOException ex) { ex.printStackTrace(); } return image; } public void zensiere() { Graphics g = image.getGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 190, 450, 50); g.setFont(new Font("Sans", Font.PLAIN, 40)); g.setColor(Color.WHITE); g.drawString("zensiert", 40, 230); } public static void main(String args[]) { SwingUtilities.invokeLater(() -> new AufBildZeichnenClass()); } }