Pessoal boa tarde, estou com um probleminha, estou querendo colocar uma imagem de fundo em um frame de login. Estou conseguindo colocar a imagem, porem ela apaga os demais itens que estão na minha tela, somente quando eu passo o mouse sobre que eles que alguns deste aparecem.
Este é meu código:
[code]public class Tela_Login extends javax.swing.JFrame{
/** Creates new form Tela_Login */
LookAndFeel visual = new LookAndFeel();
Image img;
public Tela_Login() {
initComponents();
visual.lookandfel(this);
img= (new ImageIcon("C:/Botões a serem utilizados/solucao2.jpg")).getImage();
//this.setPreferredSize( new Dimension(img.getWidth(null), img.getHeight(null)) );
//this.setSize( this.getPreferredSize() );
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//pack();
}
public void paint(Graphics g)
{
super.paint(g);
int x = ( img.getWidth ( null ) );
int y = ( img.getHeight ( null ) );
Dimension d = getSize();
g.drawImage(img, 0, 0, d.width, d.height, null);
}[/code]
[code]public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Tela_Login().setVisible(true);
}
});
}[/code]
Gostaria que vcs me ajudassem com este código. nota: utilizo a ide netbeans 5.5
public class PainelImageFundo extends JPanel {
private Image fundo;
public PainelImageFundo(String imagem) {
URL res = getClass().getResource(imagem);
if (res == null) {
throw new IllegalArgumentException("resource not found: " + imagem);
}
fundo = Toolkit.getDefaultToolkit().createImage(res);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (fundo != null) {
int w = fundo.getWidth(this);
int h = fundo.getHeight(this);
if (w > 0 && h > 0) {
for (int y = 0; y < getHeight(); y += h) {
for (int x = 0; x < getWidth(); x += w) {
g.drawImage(fundo, x, y, this);
}
}
}
}
}
}
public class TesteImage extends JFrame{
private static final long serialVersionUID = -4760333677624707409L;
private PainelImageFundo painel;
public TesteImage(){
this.setContentPane(getPainel());
}
private PainelImageFundo getPainel(){
painel = new PainelImageFundo("imagemFundo");
return painel;
}
}
Tinha encontrado um exemplo aqui mesmo no forum, mas não tenho o link pra você. Vê se te ajuda.
Cara tá um pouco confuso este seu código pra mim, coloquei ele na minha aplicação ele tah me retornando erro no metodo paintcomponent, onde ele parece que não consegue encontrar a classe ou a interface a ser preenchida.
Criei as classes que vc me mandou e na hora de compilar deu o seguinte erro:
java.lang.NoClassDefFoundError: fundoimagem/TesteImage
Exception in thread "main"
Java Result: 1