Allora il mio problema è questo :
ho un'interfaccia di questo tipo :
Io voglio che quando vado a cliccare su Reperibilità (mattina o notte), deve colorarmi il background del tasto nel modo corrispondente..in particolare se sul tasto c'è già un'icona di questi quattro tipi:
ferie
esonerato
congedo straordinario
malattia
deve cancellare l'icona...e settare solo il background del colore corrispondente...
bene...questa cosa la riesco a fare su tutti i tasti del calendario, però quando clicco su un tasto ke nn ha nessuna icona (come le domeniche ke vedi nel mio calendario ora)..bè a quel punto il programma mi da un'eccezzione di questo tipo :
codice:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at interfacciaInsMod.Cella$1.actionPerformed(Cella.java:229)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
l'errore mi viene segnalato in questa porzione di codice:
codice:
if (Pannello_inserimento_modifica.tastoPremutoReperibilita.toString()== "Giorno"){
//jButton1.setIcon(new ImageIcon(getClass().getResource("/RM.jpg")));
if (buttonicon.getImage()==ferie.getImage()||buttonicon.getImage()==esonerato.getImage()||buttonicon.getImage()==congedo.getImage()||buttonicon.getImage()==malattia.getImage()||jButton1.getIcon()==null){
jButton1.setIcon(null);}
jButton1.setBackground(Color.cyan);}
else{
//jButton1.setIcon(new ImageIcon(getClass().getResource("/RN.jpg")));
if (buttonicon.getImage()==ferie.getImage()||buttonicon.getImage()==esonerato.getImage()||buttonicon.getImage()==congedo.getImage()||buttonicon.getImage()==malattia.getImage()){
jButton1.setIcon(null);}
jButton1.setBackground(new Color(0,128,128));}
la riga 229 dell'eccezzione è questa qui :
codice:
if (buttonicon.getImage()==ferie.getImage()||buttonicon.getImage()==esonerato.getImage()||buttonicon.getImage()==congedo.getImage()||buttonicon.getImage()==malattia.getImage()||jButton1.getIcon()==null)
nn riesco a capire dove sta il problema..
se ti possono servire queste sn le dichiarazioni ke stanno prima del blocco if che ti ho postato:
codice:
ImageIcon buttonicon = (ImageIcon) jButton1.getIcon();
ImageIcon ferie = new ImageIcon(getClass().getResource("/travel1.jpg"));
ImageIcon esonerato = new ImageIcon(getClass().getResource("/stop1.jpg"));
ImageIcon congedo = new ImageIcon(getClass().getResource("/earth1.jpg"));
ImageIcon malattia = new ImageIcon(getClass().getResource("/soccorso1.jpg"));