anonnymouz 11 de jul. de 2012
Bom pessoal, achei uma solução! Pode não ser a melhor, mas já é algo.
Segue meu código:
import java.awt.Color ;
import java.awt.Dimension ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.awt.GridBagLayout ;
import java.awt.Toolkit ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import javax.swing.ImageIcon ;
import javax.swing.JButton ;
import javax.swing.JFrame ;
import javax.swing.JOptionPane ;
/**
* @author Anonnymouz
*/
public class Translucent extends JFrame {
private ImageIcon background ;
private ImageIcon ok ;
private ImageIcon close ;
private JButton okButton ;
private JButton closeButton ;
private final Color transparent = new Color ( 0f , 0f , 0f , 0f );
private final Dimension screenSize = Toolkit . getDefaultToolkit (). getScreenSize ();
public static void main ( String [] args ) {
new Translucent (). setVisible ( true );
}
private Translucent () {
setDefaultCloseOperation ( EXIT_ON_CLOSE );
setUndecorated ( true );
setLayout ( new GridBagLayout ());
initComponents ();
}
private void initComponents () {
setBackground ( transparent );
background = new ImageIcon ( getClass (). getResource ( "/resources/derby.png" ));
ok = new ImageIcon ( getClass (). getResource ( "/resources/ok.png" ));
close = new ImageIcon ( getClass (). getResource ( "/resources/close.png" ));
okButton = new JButton () {
@Override
public void paint ( Graphics g ) {
okButton . setBorderPainted ( false );
(( Graphics2D ) g ). drawImage ( ok . getImage (), null , null );
super . paint ( g );
}
};
okButton . addActionListener ( new ActionListener () {
@Override
public void actionPerformed ( ActionEvent e ) {
JOptionPane . showMessageDialog ( null , "Funfa!!!" );
}
});
add ( okButton );
closeButton = new JButton () {
@Override
public void paint ( Graphics g ) {
closeButton . setBorderPainted ( false );
(( Graphics2D ) g ). drawImage ( close . getImage (), null , null );
super . paint ( g );
}
};
closeButton . addActionListener ( new ActionListener () {
@Override
public void actionPerformed ( ActionEvent e ) {
dispose ();
}
});
closeButton . setToolTipText ( "Sair" );
add ( closeButton );
setBounds (( screenSize . width - background . getIconWidth ()) / 2 , ( screenSize . height - background . getIconHeight ()) / 2 , background . getIconWidth (), background . getIconHeight ());
}
@Override
public void paint ( Graphics g ) {
(( Graphics2D ) g ). drawImage ( background . getImage (), null , null );
super . paint ( g );
}
}
Qualquer dica de melhoria é bem vinda!!!
Seguem em anexo a classe Java e as imagens…