所以我一直在构建一个搜索excel文件的程序。所以我创建了两个类,一个叫做GUI,一个叫ExcelReader
。当我尝试在GUI类中创建ExcelReader
的对象时,GUI程序崩溃了。以下是我的GUI代码:
public class GUI {
private JFrame frmExcelReader;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
private static ExcelReader excelreader;
private JTextField textField_6;
private JTextField textField_7;
private JTextField textField_8;
private JTextField textField_9;
private JTextField textField_10;
private JTextField textField_11;
private JTextField textField_12;
private JTextField textField_13;
private JTextField textField_14;
private JTextField textField_15;
private JTextField textField_16;
private JTextField textField_17;
private JTextField textField_18;
private JTextField textField_19;
private JLabel lblLocation;
/**
* Launch the application.
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI window = new GUI();
window.frmExcelReader.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*
* @throws IOException
*/
public GUI() throws IOException {
initialize();
}
/**
* Initialize the contents of the frame.
*
* @throws IOException
*/
private void initialize() throws IOException {
frmExcelReader = new JFrame();
excelreader = new ExcelReader();
frmExcelReader.setFont(new Font("Dialog", Font.BOLD, 26));
frmExcelReader.setAutoRequestFocus(false);
frmExcelReader.setTitle("Excel Reader\n");
frmExcelReader.getContentPane().setBackground(Color.ORANGE);
frmExcelReader.setBounds(100, 100, 674, 432);
frmExcelReader.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmExcelReader.getContentPane().setLayout(null);
textField = new JTextField();
textField.setBounds(131, 45, 367, 32);
frmExcelReader.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(131, 95, 367, 32);
frmExcelReader.getContentPane().add(textField_1);
JButton btnNewButton = new JButton("Search");
btnNewButton.setBounds(495, 48, 117, 29);
frmExcelReader.getContentPane().add(btnNewButton);
JButton button = new JButton("Search");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button.setBounds(495, 98, 117, 29);
frmExcelReader.getContentPane().add(button);
textField_2 = new JTextField();
textField_2.setBounds(66, 189, 251, 26);
frmExcelReader.getContentPane().add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setBounds(66, 251, 251, 26);
frmExcelReader.getContentPane().add(textField_3);
textField_3.setColumns(10);
textField_4 = new JTextField();
textField_4.setBounds(66, 220, 251, 26);
frmExcelReader.getContentPane().add(textField_4);
textField_4.setColumns(10);
textField_5 = new JTextField();
textField_5.setBounds(66, 282, 251, 26);
frmExcelReader.getContentPane().add(textField_5);
textField_5.setColumns(10);
JLabel lblProductName = new JLabel("Product Name");
lblProductName.setBounds(31, 53, 98, 16);
frmExcelReader.getContentPane().add(lblProductName);
JLabel lblModelName = new JLabel("Model Number");
lblModelName.setBounds(21, 103, 98, 16);
frmExcelReader.getContentPane().add(lblModelName);
JLabel lblProductName_1 = new JLabel("Product Name");
lblProductName_1.setBounds(98, 161, 109, 16);
frmExcelReader.getContentPane().add(lblProductName_1);
textField_6 = new JTextField();
textField_6.setBounds(66, 313, 251, 26);
frmExcelReader.getContentPane().add(textField_6);
textField_6.setColumns(10);
textField_7 = new JTextField();
textField_7.setBounds(66, 344, 251, 26);
frmExcelReader.getContentPane().add(textField_7);
textField_7.setColumns(10);
textField_8 = new JTextField();
textField_8.setBounds(329, 189, 66, 26);
frmExcelReader.getContentPane().add(textField_8);
textField_8.setColumns(10);
textField_9 = new JTextField();
textField_9.setColumns(10);
textField_9.setBounds(405, 189, 130, 26);
frmExcelReader.getContentPane().add(textField_9);
textField_10 = new JTextField();
textField_10.setColumns(10);
textField_10.setBounds(329, 220, 66, 26);
frmExcelReader.getContentPane().add(textField_10);
textField_11 = new JTextField();
textField_11.setColumns(10);
textField_11.setBounds(329, 251, 66, 26);
frmExcelReader.getContentPane().add(textField_11);
textField_12 = new JTextField();
textField_12.setColumns(10);
textField_12.setBounds(329, 282, 66, 26);
frmExcelReader.getContentPane().add(textField_12);
textField_13 = new JTextField();
textField_13.setColumns(10);
textField_13.setBounds(329, 313, 66, 26);
frmExcelReader.getContentPane().add(textField_13);
textField_14 = new JTextField();
textField_14.setColumns(10);
textField_14.setBounds(329, 344, 66, 26);
frmExcelReader.getContentPane().add(textField_14);
textField_15 = new JTextField();
textField_15.setColumns(10);
textField_15.setBounds(405, 220, 130, 26);
frmExcelReader.getContentPane().add(textField_15);
textField_16 = new JTextField();
textField_16.setColumns(10);
textField_16.setBounds(405, 251, 130, 26);
frmExcelReader.getContentPane().add(textField_16);
textField_17 = new JTextField();
textField_17.setColumns(10);
textField_17.setBounds(405, 282, 130, 26);
frmExcelReader.getContentPane().add(textField_17);
textField_18 = new JTextField();
textField_18.setColumns(10);
textField_18.setBounds(405, 313, 130, 26);
frmExcelReader.getContentPane().add(textField_18);
textField_19 = new JTextField();
textField_19.setColumns(10);
textField_19.setBounds(405, 344, 130, 26);
frmExcelReader.getContentPane().add(textField_19);
JLabel lblQty = new JLabel("QTY");
lblQty.setBounds(351, 161, 61, 16);
frmExcelReader.getContentPane().add(lblQty);
lblLocation = new JLabel("Location");
lblLocation.setBounds(434, 161, 61, 16);
frmExcelReader.getContentPane().add(lblLocation);
}
}