Cosa significa questa eccezione,generata da un cast??
codice:
java.lang.ClassCastException
at swingtest.MenuClass.actionPerformed(MenuClass.java:97)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
CODICE:
public class MenuClass /*extends JDesktopPane*/ implements ActionListener{
public JMenuBar barra = new JMenuBar();
private JMenu file = new JMenu("File");
private JMenu effect = new JMenu("Effect");
private JMenuItem esci = new JMenuItem("Esci");
private JMenuItem salva = new JMenuItem("Salva");
private JMenuItem salvaas = new JMenuItem("Salva con nome");
private JMenuItem apri = new JMenuItem("Apri");
private JMenuItem inverti = new JMenuItem("Inverti");
private JMenuItem luminosita = new JMenuItem("Luminosità");
private JMenuItem contrasto = new JMenuItem("Contrasto");
private JFileChooser aprifile = new JFileChooser();
public JDesktopPane desktop = new JDesktopPane();
public JFileChooser salvafile=new JFileChooser("C:\\Programmi");
public JOptionPane pannellosalva = new JOptionPane();
private JOptionPane pannello = new JOptionPane();
public ImagePanel pannelloimmagine;
public JInternalFrame finestra;
public RenderedImage immagine;
public JSlider sld;
public JScrollPane srcimgpanel;
public DisplayJAI srcimg;
public OperationClass operazioni = new OperationClass();
public MenuClass() {
barra.add(file);
barra.add(effect);
file.add(apri);
file.add(salva);
file.add(salvaas);
file.add(esci);
effect.add(inverti);
effect.add(luminosita);
effect.add(contrasto);
apri.addActionListener(this);
salvaas.addActionListener(this);
esci.addActionListener(this);
inverti.addActionListener(this);
}
private String openFile(){
aprifile.setDialogTitle("Scegli Immagine");
aprifile.showOpenDialog (pannello);
String fileName = new String(aprifile.getSelectedFile().toString());
return fileName;
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == esci){
System.exit(0);
}
if(ae.getSource() == apri){
String fileName =openFile();
pannelloimmagine = new ImagePanel();
finestra = pannelloimmagine.CreatePanel(fileName);
desktop.add(finestra);
}
if(ae.getSource() == salvaas){
try{
salvafile.setDialogTitle("Inserisci percorso");
salvafile.showSaveDialog(pannellosalva);
String filesalvato = new String(salvafile.getSelectedFile().toString());
JAI.create("filestore", immagine, filesalvato, "BMP", null);
}
catch(Exception a){
System.out.println("Operazione annullata dall'utente");
}
}
if(ae.getSource() == inverti){
immagine = ((ImagePanel)desktop.getSelectedFrame()).getOriginalImage();
if(immagine != null) {
srcimg = operazioni.Inverti(immagine);
pannelloimmagine = new ImagePanel();
finestra = pannelloimmagine.CreatePanel(srcimg);
desktop.add(finestra);
}
else{ System.out.print("errorei invert"); }
}
}
}
public class ImagePanel extends JInternalFrame
{
public JInternalFrame finestra,pan;
public JScrollPane srcimgpanel;
public DisplayJAI srcimg;
public RenderedImage imgsrc;
public ImagePanel() {
}
public JInternalFrame CreatePanel(String fileName) {
imgsrc = JAI.create("fileload", fileName);
finestra = new JInternalFrame(fileName, true, true, true, true);
finestra.setSize(640,480);
srcimgpanel = new JScrollPane();
srcimg = new DisplayJAI(imgsrc);
srcimgpanel.getViewport().add(srcimg);
setPreferredSize(new Dimension(640, 480));
finestra.getContentPane().add(srcimgpanel);
finestra.setVisible(true);
return finestra;
}
public JInternalFrame CreatePanel(DisplayJAI immagine){
finestra = new JInternalFrame("Immagine Modificata",true,true,true,true);
finestra.setSize(640,480);
srcimgpanel = new JScrollPane();
srcimgpanel.getViewport().add(immagine);
finestra.getContentPane().add(srcimgpanel);
finestra.setVisible(true);
return finestra;
}
public RenderedImage getOriginalImage() {
return imgsrc;
}
}