a parte il FileChooser (che è un discorso a parte), ho fatto così:
ogni if richiama un metodo.codice:// EVENTI MENU itemSaveTxt.addActionListener(cal); itemSaveXls.addActionListener(cal); itemPrint.addActionListener(cal); itemAbout.addActionListener(cal); itemSavePdf.addActionListener(cal); itemAuthorsChart.addActionListener(cal); itemEditorsChart.addActionListener(cal); itemSaveXml.addActionListener(cal); itemEsc.addActionListener(cal); // EVENTI BUTTON btnConnect.addActionListener(cal); btnModify.addActionListener(cal); btnDelete.addActionListener(cal); btnAddBook.addActionListener(cal); btnAddAuthor.addActionListener(cal); btnUpAuthor.addActionListener(cal); btnDelAuthor.addActionListener(cal); btnAddEditor.addActionListener(cal); btnUpEditor.addActionListener(cal); btnDeleteEditor.addActionListener(cal); private class CustomActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent ev) { Object source = ev.getSource(); if (source == itemAbout) { formAbout(); } else if (source == itemPrint) { printTable(); } else if (source == itemSaveTxt) { fileChooser("txt"); } else if (source == itemSaveXls) { fileChooser("xls"); } else if (source == itemSavePdf) { fileChooser("pdf"); } else if (source == itemAuthorsChart) { formGraph(UrlAndPath.GRAPH_AUTHORS); } else if (source == itemEditorsChart) { formGraph(UrlAndPath.GRAPH_EDITORS); } else if (source == itemSaveXml) { fileChooser("xml"); } else if (source == itemEsc) { close(); } else if (source == btnConnect) { createConnection(); } else if (source == btnModify) { getTableData(); tableData.requestFocus(); } else if (source == btnDelete) { deleteBook(); tableData.requestFocus(); } else if (source == btnAddBook) { addBook(); } else if (source == btnAddAuthor || source == txtAddAuthor) { addAuthor(); } else if (source == btnUpAuthor || source == txtUpAuthor) { upAuthor(); } else if (source == btnDelAuthor) { deleteAuthor(); } else if (source == btnAddEditor || source == txtAddEditor) { addEditor(); } else if (source == btnUpEditor || source == txtUpEditor) { upEditor(); } else if (source == btnDeleteEditor) { deleteEditor(); } } }
dentro al metodo gestisco eventuali eccezioni (poi magari sistemerò meglio anche quelle, ma anche qui è un discorso a parte).
mi sembra funzioni tutto.

Rispondi quotando