📄 operationframe.java
字号:
private void seeJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seeJButtonActionPerformed // TODO add your handling code here: oneJTextArea.setText(""); if(numberJRadioButton.isSelected()){ boolean checkPoint1=checkContents(0,number1JTextField); if(checkPoint1==true&&!number1JTextField.getText().equals("")){ seekPhoto(0,number1JTextField); name1JTextField.setText(""); date1JTextField.setText(""); place1JTextField.setText(""); } else if(!number1JTextField.getText().equals("")){ JOptionPane.showMessageDialog(null,"该照片不存在!","Wrong PhotoID",JOptionPane.WARNING_MESSAGE); number1JTextField.setText(""); } else JOptionPane.showMessageDialog(null,"请输入照片ID!","Missing information",JOptionPane.WARNING_MESSAGE); } else if(nameJRadioButton.isSelected()){ boolean checkPoint2=checkContents(1,name1JTextField); if(checkPoint2==true&&!name1JTextField.getText().equals("")){ seekPhoto(1,name1JTextField); number1JTextField.setText(""); date1JTextField.setText(""); place1JTextField.setText(""); } else if(!name1JTextField.getText().equals("")){ JOptionPane.showMessageDialog(null,"该照片不存在!","Wrong Name",JOptionPane.WARNING_MESSAGE); name1JTextField.setText(""); } else JOptionPane.showMessageDialog(null,"请输入照片名称!","Missing information",JOptionPane.WARNING_MESSAGE); } else if(dateJRadioButton.isSelected()){ boolean checkPoint3=checkContents(2,date1JTextField); if(checkPoint3==true&&!date1JTextField.getText().equals("")){ seekPhoto(2,date1JTextField); number1JTextField.setText(""); name1JTextField.setText(""); place1JTextField.setText(""); } else if(!date1JTextField.getText().equals("")){ JOptionPane.showMessageDialog(null,"该照片不存在!","Wrong Date",JOptionPane.WARNING_MESSAGE); date1JTextField.setText(""); } else JOptionPane.showMessageDialog(null,"请输入照片拍摄时间!","Missing information",JOptionPane.WARNING_MESSAGE); } else if(placeJRadioButton.isSelected()){ boolean checkPoint4=checkContents(3,place1JTextField); if(checkPoint4==true&&!place1JTextField.getText().equals("")){ seekPhoto(3,place1JTextField); number1JTextField.setText(""); name1JTextField.setText(""); date1JTextField.setText(""); } else if(!place1JTextField.getText().equals("")){ JOptionPane.showMessageDialog(null,"该照片不存在!","Wrong Place",JOptionPane.WARNING_MESSAGE); place1JTextField.setText(""); } else JOptionPane.showMessageDialog(null,"请输入照片地点!","Missing information",JOptionPane.WARNING_MESSAGE); } else if(allJRadioButton.isSelected()){ try { FileReader outputFile = new FileReader(selectedFile); output=new BufferedReader(outputFile); String contents=output.readLine(); oneJTextArea.append("photoID"+"\t"+"Name"+"\t"+"Date"+"\t"+"Place"+"\t"+"Description"+"\n"); while(contents!=null) { oneJTextArea.append(contents+"\t"+output.readLine()+"\t"+output.readLine()+"\t"+output.readLine()+"\t"+output.readLine()+"\n"); contents=output.readLine(); } } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Please make sure the file exists and is of the " + "right format.", "I/O Error", JOptionPane.ERROR_MESSAGE ); } finally { try { output.close(); } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Please make sure the file exists and is of the " + "right format.", "I/O Error", JOptionPane.ERROR_MESSAGE ); } } } else JOptionPane.showMessageDialog(null,"请至少选种一项!","Missing choose",JOptionPane.ERROR_MESSAGE); }//GEN-LAST:event_seeJButtonActionPerformed private void placeJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_placeJRadioButtonActionPerformed // TODO add your handling code here: if(placeJRadioButton.isSelected()){ place1JTextField.setEditable(true); } if(!placeJRadioButton.isSelected()){ place1JTextField.setText(""); place1JTextField.setEditable(false); } }//GEN-LAST:event_placeJRadioButtonActionPerformed private void showJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showJButtonActionPerformed // TODO add your handling code here: boolean checkPoint=checkContents(0,number3JTextField); if(checkPoint==true){ if(!number3JTextField.getText().equals("")) { name3JTextField.setEditable(true); date3JTextField.setEditable(true); place3JTextField.setEditable(true); threeJTextArea.setEditable(true); ok3JButton.setEnabled(true); ok4JButton.setEnabled(true); try { FileReader outputFile = new FileReader(selectedFile); output=new BufferedReader(outputFile); String contents=output.readLine(); while(contents!=null) { if(contents.equals(number3JTextField.getText())) { name3JTextField.setText(output.readLine()); date3JTextField.setText(output.readLine()); place3JTextField.setText(output.readLine()); threeJTextArea.setText(output.readLine()); } else{ for(int i=0;i<4;i++){ output.readLine(); } } contents=output.readLine(); } } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Please make sure the file exists and is of the " + "right format.", "I/O Error", JOptionPane.ERROR_MESSAGE ); } finally { try { output.close(); } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Please make sure the file exists and is of the " + "right format.", "I/O Error", JOptionPane.ERROR_MESSAGE ); } } } else JOptionPane.showMessageDialog(null,"Please input the photoID!","Missing informaiton", JOptionPane.WARNING_MESSAGE); } else{ JOptionPane.showMessageDialog(null,"该照片不存在!","Wrong PhotoID",JOptionPane.ERROR_MESSAGE); number3JTextField.setText(""); } }//GEN-LAST:event_showJButtonActionPerformed private void ok3JButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ok3JButtonActionPerformed // TODO add your handling code here: photoArrayList.clear(); storePhotoObject(); int number=photoArrayList.size(); for(int i=0;i<number;i++){ if(number3JTextField.getText().equals(((Photo)photoArrayList.get(i)).getPhotoID())) { ((Photo)photoArrayList.get(i)).setPhotoID(number3JTextField.getText()); ((Photo)photoArrayList.get(i)).setName(name3JTextField.getText()); ((Photo)photoArrayList.get(i)).setDate(date3JTextField.getText()); ((Photo)photoArrayList.get(i)).setPlace(place3JTextField.getText()); ((Photo)photoArrayList.get(i)).setDescription(threeJTextArea.getText()); } } if(number3JTextField.getText().equals("")|| name3JTextField.getText().equals("")|| date3JTextField.getText().equals("")|| place3JTextField.getText().equals("")|| threeJTextArea.getText().equals("")){ JOptionPane.showMessageDialog(null,"请在每个选项内填入内容!","Miss Imformation",JOptionPane.ERROR_MESSAGE); } else if(!number3JTextField.getText().equals("")&& !name3JTextField.getText().equals("")&& !date3JTextField.getText().equals("")&& !place3JTextField.getText().equals("")&& !threeJTextArea.getText().equals("")) { clearPhotoFile(); for(int i=0;i<number;i++){ FileWriter inputFile=null; try { inputFile = new FileWriter(selectedFile, true); input=new PrintWriter(inputFile); } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Cannot open the file " + selectedFile.getName() + ".", "Error", JOptionPane.ERROR_MESSAGE ); } input.println((((Photo)photoArrayList.get(i)).getPhotoID())); input.println((((Photo)photoArrayList.get(i)).getName())); input.println((((Photo)photoArrayList.get(i)).getDate())); input.println((((Photo)photoArrayList.get(i)).getPlace())); input.println((((Photo)photoArrayList.get(i)).getDescription())); input.close(); } JOptionPane.showMessageDialog(null,"操作成功!"); name3JTextField.setText(""); date3JTextField.setText(""); place3JTextField.setText(""); threeJTextArea.setText(""); } }//GEN-LAST:event_ok3JButtonActionPerformed private void ok4JButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ok4JButtonActionPerformed // TODO add your handling code here: photoArrayList.clear(); storePhotoObject(); int number=photoArrayList.size(); if(!number3JTextField.getText().equals("")) { for(int i=0;i<number;i++){ if(number3JTextField.getText().equals(((Photo)photoArrayList.get(i)).getPhotoID())) { position=i; break; } } photoArrayList.remove(position); number3JTextField.setText(""); name3JTextField.setText(""); date3JTextField.setText(""); place3JTextField.setText(""); threeJTextArea.setText(""); clearPhotoFile(); for(int i=0;i<number-1;i++){ FileWriter inputFile=null; try { inputFile = new FileWriter(selectedFile, true); input=new PrintWriter(inputFile); } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Cannot open the file " + selectedFile.getName() + ".", "Error", JOptionPane.ERROR_MESSAGE ); } input.println((((Photo)photoArrayList.get(i)).getPhotoID())); input.println((((Photo)photoArrayList.get(i)).getName())); input.println((((Photo)photoArrayList.get(i)).getDate())); input.println((((Photo)photoArrayList.get(i)).getPlace())); input.println((((Photo)photoArrayList.get(i)).getDescription())); input.close(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -