Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit f1dbe11

Browse files
committed
fix a bug: when res is null, it will create a Object[0][6] and give to data
1 parent bcb4e94 commit f1dbe11

File tree

1 file changed

+32
-10
lines changed
  • src/main/java/top/mryan2005/managesysteminjava

1 file changed

+32
-10
lines changed

src/main/java/top/mryan2005/managesysteminjava/Core.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public void actionPerformed(ActionEvent e) {
543543
}
544544

545545
public void createViewWindow() {
546-
final String[] types = {""};
546+
final String[] types = {"", ""};
547547
Object[][] data;
548548
JDialog jDialogGetWhich = new JDialog(this, "select", true);
549549
jDialogGetWhich.setBounds(0, 0, 300, 500);
@@ -553,6 +553,19 @@ public void createViewWindow() {
553553
Insets insets = new Insets(10, 10, 10, 10);
554554
gbc.fill = GridBagConstraints.BOTH;
555555
gbc.insets = insets;
556+
JComboBox comboBoxPlace = new JComboBox();
557+
String[] selections1 = {"梧州", "苍梧石桥", "蒙山"};
558+
for(String item: selections1) {
559+
comboBoxPlace.addItem(item);
560+
}
561+
comboBoxPlace.setSize(100, 50);
562+
gbc.gridx = 0;
563+
gbc.gridy = 0;
564+
gbc.gridwidth = 1; // 横占一个单元格
565+
gbc.gridheight = 1; // 列占一个单元格
566+
gbc.weightx = 0.0; // 当窗口放大时,长度不变
567+
gbc.weighty = 0.0; // 当窗口放大时,高度不变
568+
jDialogGetWhich.add(comboBoxPlace, gbc);
556569
JComboBox comboBox = new JComboBox();
557570
String[] selections = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "All"};
558571
for(String item: selections) {
@@ -561,15 +574,15 @@ public void createViewWindow() {
561574
comboBox.setSelectedItem("All");
562575
comboBox.setSize(100, 50);
563576
gbc.gridx = 0;
564-
gbc.gridy = 0;
577+
gbc.gridy = 1;
565578
gbc.gridwidth = 1; // 横占一个单元格
566579
gbc.gridheight = 1; // 列占一个单元格
567580
gbc.weightx = 0.0; // 当窗口放大时,长度不变
568581
gbc.weighty = 0.0; // 当窗口放大时,高度不变
569582
jDialogGetWhich.add(comboBox, gbc);
570583
JButton jButtonSubmit = new JButton("Submit");
571584
gbc.gridx = 0;
572-
gbc.gridy = 1;
585+
gbc.gridy = 2;
573586
gbc.gridwidth = 1; // 横占一个单元格
574587
gbc.gridheight = 1; // 列占一个单元格
575588
gbc.weightx = 0.0; // 当窗口放大时,长度不变
@@ -578,6 +591,7 @@ public void createViewWindow() {
578591
@Override
579592
public void actionPerformed(ActionEvent e) {
580593
types[0] = comboBox.getSelectedItem().toString();
594+
types[1] = comboBoxPlace.getSelectedItem().toString();
581595
jDialogGetWhich.dispose();
582596
}
583597
});
@@ -590,8 +604,12 @@ public void actionPerformed(ActionEvent e) {
590604
String[] columnNames = {"id", "简体字", "繁体字", "梧州读音", "苍梧石桥读音", "蒙山读音"};
591605
List<Object[]> l = new ArrayList<>();
592606
ResultSet res;
607+
String place = null;
608+
if(types[1].matches("梧州")) {
609+
place = "Wuzhou";
610+
}
593611
if(types[0].matches("A"))
594-
res = sql.runSQL("SELECT * FROM entry.aPart ORDER BY id");
612+
res = sql.runSQL("SELECT * FROM entry.main WHERE Pronunciation_of_"+place+" LIKE 'a%' ORDER BY id");
595613
else if(types[0].matches("B"))
596614
res = sql.runSQL("SELECT * FROM entry.bPart ORDER BY id");
597615
else if(types[0].matches("C"))
@@ -647,12 +665,16 @@ else if(types[0].matches("All"))
647665
else
648666
res = sql.runSQL("SELECT * FROM entry.viewAll ORDER BY id");
649667
try {
650-
while (res.next()) {
651-
l.add(new Object[]{res.getString("id"), res.getString("simplified_Chinese_character"), res.getString("traditional_Chinese_character"), res.getString("Pronunciation_of_Wuzhou"), res.getString("Pronunciation_of_Cangwu_Shiqiao"), res.getString("Pronunciation_of_Mengshan")});
652-
}
653-
data = new Object[l.size()][6];
654-
for (int i = 0; i < l.size(); i++) {
655-
data[i] = l.get(i);
668+
if(res != null) {
669+
while (res.next()) {
670+
l.add(new Object[]{res.getString("id"), res.getString("simplified_Chinese_character"), res.getString("traditional_Chinese_character"), res.getString("Pronunciation_of_Wuzhou"), res.getString("Pronunciation_of_Cangwu_Shiqiao"), res.getString("Pronunciation_of_Mengshan")});
671+
}
672+
data = new Object[l.size()][6];
673+
for (int i = 0; i < l.size(); i++) {
674+
data[i] = l.get(i);
675+
}
676+
} else {
677+
data = new Object[0][6];
656678
}
657679
} catch (SQLException e) {
658680
data = new Object[0][6];

0 commit comments

Comments
 (0)