⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 抽奖系统。营销活动现场
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  void menuExport_actionPerformed(ActionEvent e) {    if (exportData()){      JOptionPane.showMessageDialog(this,"Data exported OK!");    };  }  /**   * 显示抽奖窗口   */  void  drawLots(){    if  (AppState.luckyUserList.size()>0){      int result = JOptionPane.showConfirmDialog(                    this,                    "Are you clear all lucky user information?",                    "Waring",                    JOptionPane.OK_CANCEL_OPTION                    );      if (result != JOptionPane.OK_OPTION) return;      AppState.luckyUserList.removeAllElements();      this.resetLuckyUserTable();    }    DrawLots lots = new DrawLots(AppState.userList.size(),AppState.roundCount);    if (lots.isUserNumberEnough() == false) {      JOptionPane.showMessageDialog(this,"lottery number is larger than user number");      return;    }    LotteryWindow win = new LotteryWindow(lots);    win.show();    //?? how blocking here,waiting the window return result ?  }  /**   * 用后台数据刷新表格   */  void resetUserTable(){    userTableModel=new UserTableModel();    userTableModel.setModelData(AppState.userList,UserInfo.getUserTableHeadArray());    userTable.setModel(userTableModel);  }  /**   * 用后台数据刷新表格   */  void resetLuckyUserTable(){    luckyUserTableModel=new UserTableModel();    luckyUserTableModel.setModelData(AppState.luckyUserList,LuckyUserInfo.luckyUserTableHeadArray);    luckyUserTable.setModel(luckyUserTableModel);  }  /**   * 退出的确认对话框   */  void doExiting() throws Exception{    int result = JOptionPane.showConfirmDialog(this,        "Are you want to save data ?",        "Warning",JOptionPane.YES_NO_CANCEL_OPTION);    if (result == JOptionPane.CANCEL_OPTION){      return;    }    if (result==JOptionPane.YES_OPTION){      if (saveFile()==false) {        return;      }    }    AppState.saveConfig();    System.exit(0);  }  /**   * 显示添加/编辑记录   */  public void showUserDlg(Frame frame,String title,boolean modal,UserInfo info, boolean isNew, int recordIndex){    UserDialog dlg;    if (isNew==true){      dlg = new UserDialog(frame,title,modal,info,isNew);    }else{      dlg= new UserDialog(frame, title,modal,info,recordIndex);    }    Dimension dlgSize = dlg.getPreferredSize();    Dimension frmSize = getSize();    Point loc = getLocation();    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);    dlg.setModal(true);    dlg.show();  }  /**   * 打开数据文件   */  void openFile(){    // show the filechooser    int result = fc.showOpenDialog(this);    if(result != JFileChooser.APPROVE_OPTION) {      return;    }    String fileName = fc.getSelectedFile().getPath();    if (FileUtility.exist(fileName)==false){      JOptionPane.showMessageDialog(this,"File is not exsit !");      return;    }    if (FileUtility.isFileValid(fileName)==false){      JOptionPane.showMessageDialog(this,"Selected file is not a valid file!");      return;    }    // here use the new    try {      AppState.loadData(fileName);      resetUserTable();      resetLuckyUserTable();      AppState.dataFileName= fileName;      userTable.invalidate();      userTable.repaint();    }    catch (Exception ex) {      ex.printStackTrace();    }  }  /**   * 编辑当前记录   */  public void editCurrentRecord(){    if (tabbedPane.getSelectedIndex()!=0) return;    if (userTable.getRowCount()==0) return;    int selectedRow=userTable.getSelectedRow();    userTable.clearSelection() ;    //user must select one row to edit    if (selectedRow < 0 ) {      JOptionPane.showMessageDialog(this,"No record selected");      return;    }    UserInfo info = (UserInfo)AppState.userList.elementAt(selectedRow);    showUserDlg(this,"Edit a User",true,info,false,selectedRow);  }  /**   * 删除当前记录   */  void deleteCurrentRecord(){    if (tabbedPane.getSelectedIndex()!=0) return;    if (userTable.getRowCount()==0) return;    int selectedRow=userTable.getSelectedRow();    userTable.clearSelection() ;    //user must select one row to edit    if (selectedRow < 0 ) {      JOptionPane.showMessageDialog(this,"No record selected");      return;    }    int result = JOptionPane.showConfirmDialog(this,        "Are you sure to erase current record ?",        "Warning",JOptionPane.OK_CANCEL_OPTION);    if (result==JOptionPane.OK_OPTION){      AppState.removeUser(selectedRow);      userTable.invalidate();      userTable.repaint();    }  }  /**   * 显示"关于"对话框   */  void showAboutDialog(){    MainFrame_AboutBox dlg = new MainFrame_AboutBox(this);    Dimension dlgSize = dlg.getPreferredSize();    Dimension frmSize = getSize();    Point loc = getLocation();    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);    dlg.setModal(true);    dlg.show();  }  /**   * 清空当前的数据状态   */  void newFile(){    if (AppState.userList.size()!=0){      int result = JOptionPane.showConfirmDialog(this,          "Are you sure clear all data ?",          "Warning",JOptionPane.OK_CANCEL_OPTION);      if (result==JOptionPane.OK_OPTION){        AppState.resetAllState();        resetUserTable();        resetLuckyUserTable();      }    }  }  /**   * 保存文件   */  public boolean saveFile(){    return saveFile(false);  }  /**   * 保存文件   */  public boolean saveFile(boolean isSaveAs){    String fileName;    if (AppState.dataFileName==null        ||AppState.dataFileName.equals("")        ||isSaveAs){      JFileChooser fc = new JFileChooser();      // show the filechooser      int result = fc.showOpenDialog(this);      if(result != JFileChooser.APPROVE_OPTION) {        return false;      }      fileName = fc.getSelectedFile().getPath();      if (FileUtility.exist(fileName)==true){        int r = JOptionPane.showConfirmDialog(                  this,                  "File already exsited, overwrite it ?",                  "Warning",                  JOptionPane.OK_CANCEL_OPTION                  );        if (r != JOptionPane.OK_OPTION){          return false;        }      }    }else{      fileName = AppState.dataFileName;    }    try {      FileUtility.saveData(fileName,AppState.userList,AppState.luckyUserList);      AppState.dataFileName = fileName;      return true;    }    catch (Exception ex) {      ex.printStackTrace();      return false;    }  }  /**   * 导出幸运用户数据为csv文件   */  boolean exportData(){    if (AppState.luckyUserList==null){      return false;    }    JFileChooser fc = new JFileChooser();    fc.setFileFilter(new CYFileFilter());    // show the filechooser    int result = fc.showOpenDialog(this);    if(result != JFileChooser.APPROVE_OPTION) {      return false;    }    //judge whether file have the ".csv" suffix    String fileName = fc.getSelectedFile().getPath();    String suffix = FileUtility.getSuffix(fileName);    if (suffix==null||!suffix.equalsIgnoreCase("csv")){      fileName = fileName+".csv";    }    if (FileUtility.exist(fileName)==true){      int r = JOptionPane.showConfirmDialog(                this,                "File already exsited, overwrite it ?",                "Warning",                JOptionPane.OK_CANCEL_OPTION                );      if (r != JOptionPane.OK_OPTION){        return false;      }    }    //export lucky user info into a csv file.    try {      FileUtility.outputCSVFile(        fileName,        LuckyUserInfo.luckyUserTableHeadArray,        AppState.luckyUserList);      return true;    }    catch (Exception ex) {      System.out.println("Export file filed");      return false;    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -