blob: ba756fd62bfcb066429dc98631de062d0697f4d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
}
}
}
|