我在调用一个类的 jmenuitem 中添加了一个 actionlistener,该类读取一个 excel 文件并在 jframe 中打开一个 jgraph。我还向不同的 jmenuitem 添加了另一个 actionlistener 来为同一个 exel 文件调用同一个类,但使用不同的 excel 表(不同的 int 参数)。但是,当我运行主框架并单击菜单项时,一次只能打开其中一个。我必须关闭一个才能打开另一个。我需要更改它,以便每当用户单击它时,每次都会出现一个新的不同框架/窗口。
public class ReadExcel {
//reads excel file sheet and saves some strings in arrays
public static ArrayList<String> RM = new ArrayList<String>() ;
...
public static void excel(String excelfile, Integer sheetno) {
...
}
}
public class graphgen extends JFrame {
//creates a graph based on ReadExcel arrays
public graphgen() {
gen();
}
public void gen(){
}
public static void main(String[] args)
{
graphgen frame = new graphgen();
p2.add(graphComponent, BorderLayout.CENTER);
frame.setLayout(new BorderLayout());
frame.add(p2, BorderLayout.CENTER);
frame.pack();
frame.setResizable(true);
frame.setSize(1600, 1200);
frame.setVisible(true);
}
}
具有菜单栏的主类:
menuItem = new JMenuItem("MenuItem1",KeyEvent.VK_B);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event2) {
new ReadExcel();
ReadExcel.excel(".xls", 0);
new graphgen();
graphgen.main(null);
}
});
subsubmenu1.add(menuItem);
menuItem = new JMenuItem("MenuItem2",KeyEvent.VK_C);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event2) {
new ReadExcel();
ReadExcel.excel(".xls", 1);
new graphgen();
graphgen.main(null);
}
});
subsubmenu1.add(menuItem);
public static void main(String[] args)
{
GUIquery frame = new GUIquery();
p.add(graphComponent, BorderLayout.CENTER);
frame.setLayout(new BorderLayout());
frame.add(p, BorderLayout.CENTER);
frame.setJMenuBar(GUIquery.createMenuBar());
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(true);
frame.setSize(1600, 1200);
frame.setVisible(true);
}
错误:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: multiple points
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at graphgen.gen(graphgen.java:645)
at graphgen.<init>(graphgen.java:62)
at GUIquery$9.actionPerformed(GUIquery.java:713)
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.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(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)