输入我的2个文件(Mesh.txt, TH.TXT)
后,我的导出功能出现了很大问题。我真的试图解决这个问题,但我不是最好的java编码器,也没有多少经验。
我的错误:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 24
at eu.keksfabrik.hydrustranslator.HydrusMeshReadout.writeRes2dModFormat(HydrusMeshReadout.java:612)
at eu.keksfabrik.hydrustranslator.HydrusMeshReadout.startWriting(HydrusMeshReadout.java:406)
at eu.keksfabrik.hydrustranslator.LoadFilesGUI.actionPerformed(LoadFilesGUI.java:304)
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.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)
程序包的链接: 我的程序完整源代码:
https://www.dropbox.com/s/zttz9123acaha3x/HydrusTranslator.zip
输入文件:
https://www.dropbox.com/s/qt2rwc3jdm28vx8/Input%20Files.zip
这是我的五个文件的代码,我拉链也是因为它太多了。
主GUI:
package eu.keksfabrik.hydrustranslator;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import java.awt.Color;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
public class MainGUI extends JFrame {
private static final long serialVersionUID = 20130513;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainGUI frame = new MainGUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainGUI() {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
setDefaultLookAndFeelDecorated(true);
setTitle("HYDRUS Filetranslator \u00a92013 Jan Mahle");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 730, 700);
contentPane = new JPanel();
contentPane.setAutoscrolls(true);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new MigLayout("", "[grow][]", "[grow][grow]"));
//JScrollBar wird erzeugt
// JScrollBar vsb = new JScrollBar(JScrollBar.VERTICAL, 1,10,1,100);
//...und dem JPanel hinzugefügt
// contentPane.add("East",vsb);
LoadFilesGUI loadFilesGUI = new LoadFilesGUI(this);
loadFilesGUI.setBackground(new Color(240, 240, 240));
contentPane.add(loadFilesGUI, "cell 0 0,growy");
setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] {contentPane, loadFilesGUI}));
}
}
LoadFilesGUI.java:
package eu.keksfabrik.hydrustranslator;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JSeparator;
import javax.swing.JLabel;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.jgoodies.forms.factories.DefaultComponentFactory;
public class LoadFilesGUI extends JPanel implements ActionListener {
private static final long serialVersionUID = 20130513;
private MigLayout ml;
private JTextField txtInMESH;
private JTextField txtInTH;
private JTextField txtOut;
private JButton btnMESH;
private JButton btnTH;
private JButton btnOut;
private JButton btnAnalyze;
private JLabel lblMeshtxt;
private JLabel lblThtxt;
private JLabel lblOutput;
private JFileChooser fcMESH;
private JFileChooser fcTH;
private JFileChooser fcCheckOut;
private JFileChooser fcOut;
private File defaultDirectory = null;
private HydrusMeshReadout hmr = null;
private TableGUI tableGUI;
private LoadingDialog loadingDialog;
private JButton addElectrods;
private JTextField nrelectrods;
private JCheckBox chckbxElectrods;
private JTextField tfelecs;
// private JScrollBar scrolli;
/**
* Create the panel.
*/
public LoadFilesGUI(JFrame parent) {
ml = new MigLayout("", "[59.00,left][grow][]", "[][][][][][grow][]");
setLayout(ml);
loadingDialog = new LoadingDialog(parent);
loadingDialog.setTitle("Working...");
lblMeshtxt = DefaultComponentFactory.getInstance().createLabel(
"*_MESH.TXT");
add(lblMeshtxt, "cell 0 0,alignx center");
txtInMESH = new JTextField();
add(txtInMESH, "cell 1 0,growx");
txtInMESH.setColumns(10);
txtInMESH.setEditable(false);
btnMESH = new JButton("Browse");
add(btnMESH, "cell 2 0,grow");
btnMESH.addActionListener(this);
fcMESH = new JFileChooser();
fcMESH.setDialogType(JFileChooser.OPEN_DIALOG);
fcMESH.setDialogTitle("Open *_MESH.TXT ...");
fcMESH.setFileFilter(new FileNameExtensionFilter("ASCII Files", "TXT"));
fcMESH.setMultiSelectionEnabled(false);
fcMESH.setDragEnabled(true);
fcMESH.setFileSelectionMode(JFileChooser.FILES_ONLY);
fcMESH.addActionListener(this);
lblThtxt = DefaultComponentFactory.getInstance().createLabel("TH.TXT");
add(lblThtxt, "cell 0 1,alignx center");
txtInTH = new JTextField();
add(txtInTH, "cell 1 1,growx");
txtInTH.setColumns(10);
txtInTH.setEditable(false);
btnTH = new JButton("Browse");
add(btnTH, "cell 2 1,grow");
btnTH.addActionListener(this);
fcTH = new JFileChooser();
fcTH.setDialogType(JFileChooser.OPEN_DIALOG);
fcTH.setDialogTitle("Open TH.TXT ...");
fcTH.setFileFilter(new FileNameExtensionFilter("ASCII Files", "TXT"));
fcTH.setMultiSelectionEnabled(false);
fcTH.setDragEnabled(true);
fcTH.setFileSelectionMode(JFileChooser.FILES_ONLY);
fcTH.addActionListener(this);
fcCheckOut = new JFileChooser();
fcCheckOut.setDialogType(JFileChooser.OPEN_DIALOG);
fcCheckOut.setDialogTitle("Open Check.out ...");
fcCheckOut
.setFileFilter(new FileNameExtensionFilter("Out Files", "OUT"));
fcCheckOut.setMultiSelectionEnabled(false);
fcCheckOut.setDragEnabled(true);
fcCheckOut.setFileSelectionMode(JFileChooser.FILES_ONLY);
fcCheckOut.addActionListener(this);
JSeparator separator = new JSeparator();
add(separator, "cell 0 2 3 1,growx");
lblOutput = DefaultComponentFactory.getInstance().createLabel("Output");
add(lblOutput, "cell 0 3,alignx center");
txtOut = new JTextField();
add(txtOut, "cell 1 3,growx");
txtOut.setColumns(10);
txtOut.setEditable(false);
btnOut = new JButton("Browse");
add(btnOut, "cell 2 3,growx");
btnOut.addActionListener(this);
fcOut = new JFileChooser();
fcOut.setDialogType(JFileChooser.SAVE_DIALOG);
fcOut.setDialogTitle("Save to...");
fcOut.setFileFilter(new FileNameExtensionFilter("ASCII Files", "xyz"));
fcOut.setMultiSelectionEnabled(false);
fcOut.setDragEnabled(true);
fcOut.setFileSelectionMode(JFileChooser.FILES_ONLY);
fcOut.addActionListener(this);
chckbxElectrods = new JCheckBox("Edit Electrods ?");
chckbxElectrods.setSelected(false);
chckbxElectrods.setEnabled(true);
add(chckbxElectrods, "cell 1 4,alignx leading");
nrelectrods = new JTextField();
add(nrelectrods, "cell 1 4,growx");
nrelectrods.setColumns(1);
nrelectrods.setEditable(true);
nrelectrods.addActionListener(this);
addElectrods = new JButton("Set Electrods");
addElectrods.setEnabled(false);
add(addElectrods, "cell 1 4,right");
addElectrods.addActionListener(this);
tfelecs = new JTextField("");
tfelecs.setEnabled(false);
add(tfelecs, "cell 1 4,right");
tfelecs.addActionListener(this);
btnAnalyze = new JButton("Analyze");
btnAnalyze.setEnabled(false);
add(btnAnalyze, "cell 2 4,growx");
btnAnalyze.addActionListener(this);
tableGUI = new TableGUI(this, null);
// JScrollBar wird erzeugt
JScrollBar vsb = new JScrollBar(JScrollBar.VERTICAL, 1, 10, 1, 100);
// ...und dem JPanel hinzugefügt
tableGUI.add("East", vsb);
tableGUI.setVisible(false);
add(tableGUI, "cell 0 6 3 1,grow");
}
// public checkelectrods = chckbxElectrods.isEnabled() {
// }
public void actionPerformed(ActionEvent e) {
System.out.println(this.getClass() + "\t" + e.getActionCommand() + "\t"
+ e.getSource().getClass().toString().substring(6));
if (e.getSource().equals(btnMESH)) {
if (defaultDirectory != null)
fcMESH.setCurrentDirectory(defaultDirectory);
fcMESH.showOpenDialog(btnMESH);
} else if (e.getSource().equals(fcMESH)) {
defaultDirectory = fcMESH.getCurrentDirectory();
if (fcMESH.getSelectedFile() != null) {
txtInMESH.setText(fcMESH.getSelectedFile().toString());
if (hmr != null)
hmr = null;
} else
txtInMESH.setText("");
} else if (e.getSource().equals(btnTH)) {
if (defaultDirectory != null)
fcTH.setCurrentDirectory(defaultDirectory);
fcTH.showOpenDialog(btnTH);
} else if (e.getSource().equals(fcTH)) {
defaultDirectory = fcTH.getCurrentDirectory();
if (fcTH.getSelectedFile() != null) {
txtInTH.setText(fcTH.getSelectedFile().toString());
if (hmr != null)
hmr = null;
} else
txtInTH.setText("");
} else if (e.getSource().equals(btnOut)) {
if (defaultDirectory != null)
fcOut.setCurrentDirectory(defaultDirectory);
fcOut.showOpenDialog(btnOut);
} else if (e.getSource().equals(fcOut)) {
defaultDirectory = fcOut.getCurrentDirectory();
if (fcOut.getSelectedFile() != null) {
txtOut.setText(fcOut.getSelectedFile().toString());
if (hmr != null)
hmr = null;
} else
txtOut.setText("");
} else if (e.getSource().equals(nrelectrods)) {
chckbxElectrods.setEnabled(false);
nrelectrods.setText("75");
nrelectrods.getText();
}
else if (e.getSource().equals(btnAnalyze)) {
new Thread() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
loadingDialog.setMessage("ANALYZING");
loadingDialog.setVisible(true);
}
});
};
}.start();
hmr = new HydrusMeshReadout(fcMESH.getSelectedFile(),
fcTH.getSelectedFile(), fcCheckOut.getSelectedFile(),
fcOut.getSelectedFile());
if (tableGUI != null && this.isAncestorOf(tableGUI)) {
remove(tableGUI);
repaint();
}
tableGUI = new TableGUI(this, hmr.getMaterials());
add(tableGUI, "cell 0 7 3 1,grow");
tableGUI.setVisible(true);
revalidate();
repaint();
// System.out.println("tableGUI = new TableGUI(this, hmr.getMaterials());\t"
// + hmr.getMaterials().toString());
btnAnalyze.setEnabled(false);
new Thread() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
loadingDialog.setVisible(false);
}
});
};
}.start();
} else if (e.getActionCommand().equals("startEvaluating")) {
new Thread() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
loadingDialog.setMessage("WRITING FILES");
loadingDialog.setVisible(true);
}
});
};
}.start();
/*
* new Thread() {
*
* @Override public void run() { SwingUtilities.invokeLater(new
* Runnable() { public void run() {
*/
hmr.setModel(tableGUI.getRhoadesEquations());
boolean[] fo = tableGUI.getFileOptions();
hmr.setTime(tableGUI.getSelectedTime());
hmr.startWriting(fo[0], fo[1], fo[2], fo[3], fo[4], fo[5],
tableGUI.getFileFormat());
/*
* } }); }; }.start();
*/
new Thread() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
loadingDialog.setVisible(false);
}
});
};
}.start();
}
if (hmr == null) {
tableGUI.setVisible(false);
}
if (!txtInMESH.getText().equals("") && !txtInTH.getText().equals("")
&& !txtOut.getText().equals("") && hmr == null) {
btnAnalyze.setEnabled(true);
} else {
btnAnalyze.setEnabled(false);
}
}
public ArrayList<Double> getAverageWaterContent() {
return hmr == null ? new ArrayList<Double>() : hmr
.getAverageWaterContent();
}
public ArrayList<Double> getTimes() {
return hmr == null ? new ArrayList<Double>() : hmr.getTimes();
}
@SuppressWarnings("serial")
private static class LoadingDialog extends JDialog {
private JLabel imglabel = new JLabel();
private JLabel label = new JLabel();
private JPanel panel = new JPanel();
private BorderLayout layout = new BorderLayout();
private JFrame owner;
public LoadingDialog(JFrame owner) {
super(owner, ModalityType.APPLICATION_MODAL);
panel.setBorder(BorderFactory.createTitledBorder(""));
this.owner = owner;
setUndecorated(true);
panel.setLayout(layout);
panel.setBackground(Color.ORANGE);
imglabel.setIcon(new ImageIcon("loading.gif"));
label.setFont(new Font(label.getFont().toString(), Font.BOLD, label
.getFont().getSize() * 2));
panel.add(imglabel, BorderLayout.CENTER);
panel.add(label, BorderLayout.EAST);
add(panel);
setMessage("PROCESSING IMAGES");
}
public void setMessage(String message) {
label.setText(message);
panel.setSize(new Dimension(label.getText().length()
* label.getFont().getSize(), label.getHeight() * 2));
setLocation((int) owner.getX()
+ (owner.getWidth() - getSize().width) / 2,
(int) owner.getY() + (owner.getHeight() - getSize().height)
/ 2);
pack();
repaint();
// System.err.println(this.getSize().getWidth() + "x" +
// this.getSize().getHeight());
}
}
}
好的,我看到我不能在这里输入整个代码,也许你可以帮助我了.... 请检查我的源代码所在的zip文件。
感谢您的帮助。