public static void addNewLineButtonButtonListener(DetailPanel detailPanel,final KDWorkButton btnAddLine,final KDWorkButton btnInsertLine,final KDWorkButton btnRemoveLine,final CoreBillEditUI editUI) throws Exception{ KDWorkButton addLine = detailPanel.getAddNewLineButton(); KDWorkButton insertLine = detailPanel.getInsertLineButton(); KDWorkButton removeLines = detailPanel.getRemoveLinesButton(); MouseListener mousadd1[] = addLine.getMouseListeners(); MouseListener mousadd2[] = insertLine.getMouseListeners(); MouseListener mousadd3[] = removeLines.getMouseListeners(); for (int i = 0; i < mousadd1.length; i++) { addLine.removeMouseListener(mousadd1[i]); } for (int i = 0; i < mousadd2.length; i++) { insertLine.removeMouseListener(mousadd2[i]); } for (int i = 0; i < mousadd3.length; i++) { removeLines.removeMouseListener(mousadd3[i]); } addLine.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseevent) { //调用editUI的新增行Action(actionAddLine) ActionEvent e = new ActionEvent(btnAddLine, 0, "Click btnAddLine"); try { editUI.actionAddLine_actionPerformed(e); } catch (Exception e1) { e1.printStackTrace(); } } }); insertLine.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseevent) { ActionEvent e = new ActionEvent(btnInsertLine, 0, "Click btnInsertLine"); try { editUI.actionInsertLine_actionPerformed(e); } catch (Exception e1) { e1.printStackTrace(); } } }); removeLines.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseevent) { ActionEvent e = new ActionEvent(btnRemoveLine, 0, "Click btnRemoveLine"); try { editUI.actionRemoveLine_actionPerformed(e); } catch (Exception e1) { e1.printStackTrace(); } } }); }
在editUI调用即可!