From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3612.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java new file mode 100644 index 0000000..ba756fd --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java @@ -0,0 +1,59 @@ +/* Listing3612.java */ + +import java.awt.*; +import javax.swing.*; + +public class Listing3612 +extends JFrame +{ + public Listing3612() + { + super("Transparenz"); + addWindowListener(new WindowClosingAdapter(true)); + Container cp = getContentPane(); + //SimpleGridComponent erzeugen + SimpleGridComponent grid = new SimpleGridComponent(); + grid.setLayout(new FlowLayout(FlowLayout.CENTER)); + //Transparenten Button hinzufügen + JButton button = new JButton("Transparent"); + button.setOpaque(false); + grid.add(button); + //Undurchsichtigen Button hinzufügen + button = new JButton("Opaque"); + grid.add(button); + //SimpleGridComponent hinzufügen + cp.add(grid, BorderLayout.CENTER); + } + + public static void main(String[] args) + { + try { + String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; + UIManager.setLookAndFeel(plaf); + Listing3612 frame = new Listing3612(); + frame.setLocation(100, 100); + frame.setSize(300, 100); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} + +class SimpleGridComponent +extends JComponent +{ + protected void paintComponent(Graphics g) + { + int width = getSize().width; + int height = getSize().height; + g.setColor(Color.gray); + for (int i = 0; i < width; i += 10) { + g.drawLine(i, 0, i, height); + } + for (int i = 0; i < height; i += 10) { + g.drawLine(0, i, width, i); + } + } +} \ No newline at end of file -- cgit v1.2.3