Estou criando uma interface para um sistema e gostaria que, quando o usuário clicasse em um JPanel
, abrisse outra janela. O programa é compilado normalmente, mas, no momento em que clico no JPanel
, não abre a janela desejada e são lançadas exceções:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:217) at telas.Venda.initComponents(Venda.java:66) at telas.Venda.<init>(Venda.java:22) at telas.TelaProprietario.vendaMouseClicked(TelaProprietario.java:935) at telas.TelaProprietario.access$2400(TelaProprietario.java:15) at telas.TelaProprietario$13.mouseClicked(TelaProprietario.java:616) at java.awt.Component.processMouseEvent(Component.java:6536) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6298) at java.awt.Container.processEvent(Container.java:2236) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2294) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) at java.awt.Container.dispatchEventImpl(Container.java:2280) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Criei a interface através do NetBeans. Abaixo está parte do código:
package telas;
import java.awt.*;
import javax.swing.*;
public class TelaProprietario extends javax.swing.JFrame
{
public TelaProprietario()
{
initComponents();
}
private void initComponents()
{
tela=new javax.swing.JPanel();
venda=new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setMinimumSize(new java.awt.Dimension(1024,768));
tela.setBackground(new java.awt.Color(204,204,255));
tela.setMinimumSize(new java.awt.Dimension(1024,768));
tela.setPreferredSize(new java.awt.Dimension(1024,768));
venda.setBackground(new java.awt.Color(204,204,255));
venda.setPreferredSize(new java.awt.Dimension(150,150));
venda.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent evt)
{
vendaMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt)
{
vendaMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt)
{
vendaMouseExited(evt);
}
});
// código de layout
}
private void vendaMouseEntered(java.awt.event.MouseEvent evt)
{
venda.setBackground(new Color(255, 255, 255));
}
private void vendaMouseExited(java.awt.event.MouseEvent evt)
{
venda.setBackground(new Color(204, 204, 255));
}
private void vendaMouseClicked(java.awt.event.MouseEvent evt)
{
new Venda().setVisible(true); // outra tela
setVisible(false);
}
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new TelaProprietario().setVisible(true);
}
});
}
private javax.swing.JPanel tela;
private javax.swing.JPanel venda;
}
Gostaria de saber o que está causando esse problema e como resolvê-lo.