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
| JButton exit = new JButton("EXIT");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
if (AWTUtilities.isTranslucencyCapable(frame.getGraphicsConfiguration())
&& AWTUtilities.isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT) ) {
AWTUtilities.setWindowOpaque(frame, false);
}
JPanel contentPane = new JPanel() {
private Color startColor = new Color(0,0,0,80);
private Color endColor = new Color(0,0,0,220);
@Override
protected void paintComponent(Graphics g) {
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(new GradientPaint(
0, 0, startColor,
getWidth(), getHeight(), endColor));
g.fillRect(0, 0, getWidth(), getHeight());
} else {
super.paintComponent(g);
}
}
};
frame.setContentPane(contentPane);
frame.getContentPane().add(exit, BorderLayout.SOUTH);
frame.setVisible(true); |
Partager