Bom dia estou com um problema, pq não consigo fazer esse codigo rodar simplesmente quero que ele puxe uma imagem que está na pasta do programa para ser o fundo mas não quero que seja por Label pq vai ser responsiva conforme a tela do usuario, então iz dessa maeneira parece estar tudo certo s´não roda alguem pode encontra o erro já estou a 4 dias e não acho o problema.
codigo:
package GUI;
import java.awt.GridLayout;
import javax.swing.JFrame;
import utilitarios.FundoTela;
public class Principal extends javax.swing.JFrame {
FundoTela tela;
public Principal() {
initComponents();
setExtendedState(JFrame.MAXIMIZED_BOTH);
setLayout(new GridLayout());
tela = new FundoTela ("imagens/imagem_fundo.Jpg");
getContentPane().add(tela);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem5 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Pizzaria Jede");
jMenu1.setText("Cadastro");
jMenuItem1.setText("Clientes");
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Funcionario");
jMenu1.add(jMenuItem2);
jMenuItem3.setText("Cardapio");
jMenu1.add(jMenuItem3);
jMenuItem4.setText("Entregador");
jMenu1.add(jMenuItem4);
jMenuBar1.add(jMenu1);
jMenu2.setText("Caixa");
jMenuItem5.setText("Pedido");
jMenu2.add(jMenuItem5);
jMenuBar1.add(jMenu2);
jMenu3.setText("Relatório");
jMenuBar1.add(jMenu3);
jMenu4.setText("Sair");
jMenuBar1.add(jMenu4);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 279, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Principal().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
e esse é o codigo do utlitario que criei:
package utilitarios;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
public class FundoTela extends JDesktopPane {
private Image imagem;
public FundoTela(String image){
this.imagem = new ImageIcon(imagem).getImage();
}
@Override
public void paintComponent(Graphics g){
g.drawImage (imagem, 0, 0, getWidth(), getHeight(), this );
}
}
se puderem me ajudar eu agradeço.