summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Listing3612.java59
1 files changed, 59 insertions, 0 deletions
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