📄 operationframe.java
字号:
JOptionPane.showMessageDialog(null,"操作成功!"); } else JOptionPane.showMessageDialog(null,"Please input the photoID!","Missing informaiton", JOptionPane.WARNING_MESSAGE); }//GEN-LAST:event_ok4JButtonActionPerformed private void orderJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderJButtonActionPerformed // TODO add your handling code here: if(upJRadioButton.isSelected()||downJRadioButton.isSelected()){ photoArrayList.clear(); storePhotoObject(); int number=photoArrayList.size(); int arrayNumber1[]=new int[number]; int arrayNumber2[]=new int[number]; for(int i=0;i<number;i++){ arrayNumber1[i]=Integer.parseInt(((Photo)photoArrayList.get(i)).getPhotoID()); } Arrays.sort(arrayNumber1); for(int i=0;i<number;i++){ arrayNumber2[number-i-1]=arrayNumber1[i]; } if(upJRadioButton.isSelected()){ setOrder(arrayNumber1,number); } else{ setOrder(arrayNumber2,number); } } else JOptionPane.showMessageDialog(null,"Please select one JRadionButton!","Missing Selected",JOptionPane.ERROR_MESSAGE); }//GEN-LAST:event_orderJButtonActionPerformed private void setOrderJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setOrderJMenuItemActionPerformed // TODO add your handling code here: if(okNumber==1){ upJRadioButton.setEnabled(true); downJRadioButton.setEnabled(true); orderJButton.setEnabled(true); }}//GEN-LAST:event_setOrderJMenuItemActionPerformed private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed // TODO add your handling code here: DescriptionJFrame description=new DescriptionJFrame(); description.setVisible(true); description.setLocationRelativeTo(null); }//GEN-LAST:event_jMenuItem1ActionPerformed private void seekPhoto(int number,JTextField textField){ try { String array[]=new String[5]; 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) { array[0]=contents; for(int i=1;i<5;i++){ array[i]=output.readLine(); } if(array[number].equals(textField.getText())) { oneJTextArea.append(array[0]+"\t"+array[1]+"\t"+array[2]+"\t"+array[3]+"\t"+array[4]+"\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 ); } } } private void storePhotoObject(){ try { FileReader outputFile = new FileReader(selectedFile); output=new BufferedReader(outputFile); String contents=output.readLine(); while(contents!=null) { newPhoto=new Photo(); photoArrayList.add(newPhoto); newPhoto.setPhotoID(contents); newPhoto.setName(output.readLine()); newPhoto.setDate(output.readLine()); newPhoto.setPlace(output.readLine()); newPhoto.setDescription(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 ); } } } private void clearPhotoFile(){ try { FileOutputStream inputFile4=new FileOutputStream(selectedFile); inputFile4.close(); } catch (IOException ex) { JOptionPane.showMessageDialog( this, "Cannot open the file " + selectedFile.getName() + ".", "Error", JOptionPane.ERROR_MESSAGE ); } } private boolean checkContents(int number,JTextField textField){ boolean check=false; try { String array[]=new String[5]; FileReader outputFile = new FileReader(selectedFile); output=new BufferedReader(outputFile); String contents=output.readLine(); while(contents!=null) { array[0]=contents; for(int i=1;i<5;i++){ array[i]=output.readLine(); } if(array[number].equals(textField.getText())) { check=true; } 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 ); } } return check; } private void setOrder(int array[],int number){ oneJTextArea.setText(""); oneJTextArea.append("PhotoID"+"\t"+"Name"+"\t"+"Date"+"\t"+"Place"+"\t"+"Dsecription"+"\n"); for(int i=0;i<number;i++){ for(int j=0;j<number;j++){ if(array[i]==Integer.parseInt(((Photo)photoArrayList.get(j)).getPhotoID())){ oneJTextArea.append(((Photo)photoArrayList.get(j)).getPhotoID()+"\t"+ ((Photo)photoArrayList.get(j)).getName()+"\t"+ ((Photo)photoArrayList.get(j)).getDate()+"\t"+ ((Photo)photoArrayList.get(j)).getPlace()+"\t"+ ((Photo)photoArrayList.get(j)).getDescription()+"\n"); } } } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new OperationFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton allJRadioButton; private javax.swing.JMenuItem authorJMenuItem; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; private javax.swing.JMenuItem changPasswordJMenuItem; private javax.swing.JMenuItem changeJMenuItem; private javax.swing.JPanel changeJPanel; private javax.swing.JTextField date1JTextField; private javax.swing.JTextField date2JTextField; private javax.swing.JTextField date3JTextField; private javax.swing.JLabel dateJLabel; private javax.swing.JRadioButton dateJRadioButton; private javax.swing.JLabel descriptionJLabel; private javax.swing.JRadioButton downJRadioButton; private javax.swing.JMenu editorJMenu; private javax.swing.JPanel examinationJPanel; private javax.swing.JMenu fileJMenu; private javax.swing.JMenu helpJMenu; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JMenuItem lookJMenuItem; private javax.swing.JMenuBar mainJMenuBar; private javax.swing.JTextField name1JTextField; private javax.swing.JTextField name2JTextField; private javax.swing.JTextField name3JTextField; private javax.swing.JLabel nameJLabel; private javax.swing.JRadioButton nameJRadioButton; private javax.swing.JMenuItem newJMenuItem; private javax.swing.JPanel newJPanel; private javax.swing.JTextField number1JTextField; private javax.swing.JTextField number2JTextField; private javax.swing.JTextField number3JTextField; private javax.swing.JLabel numberJLabel; private javax.swing.JRadioButton numberJRadioButton; private javax.swing.JButton ok2JButton; private javax.swing.JButton ok3JButton; private javax.swing.JButton ok4JButton; private javax.swing.JTextArea oneJTextArea; private javax.swing.JMenuItem openFileJMenuItem; private javax.swing.JButton orderJButton; private javax.swing.JTextField place1JTextField; private javax.swing.JTextField place2JTextField; private javax.swing.JTextField place3JTextField; private javax.swing.JLabel placeJLabel; private javax.swing.JRadioButton placeJRadioButton; private javax.swing.JButton seeJButton; private javax.swing.JMenuItem setOrderJMenuItem; private javax.swing.JButton showJButton; private javax.swing.JTextArea threeJTextArea; private javax.swing.JTextArea twoJTextArea; private javax.swing.JRadioButton upJRadioButton; private javax.swing.JMenuItem versionJMenuItem; // End of variables declaration//GEN-END:variables }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -