Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
improve string get method and filechooser
Browse files Browse the repository at this point in the history
  • Loading branch information
Waldenth committed Mar 28, 2021
1 parent b4e1d13 commit 34781c6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,26 @@ public void actionPerformed(ActionEvent e) {
//System.out.println(versionComboBox.getSelectedItem().toString());
//System.out.println(timeField.getText());
//System.out.println(stepField.getText());
String imeiCode=imeiCodeFileld.getText().replaceAll("\\s*","");
String version=versionComboBox.getSelectedItem().toString().replaceAll("\\s*","");
String time=timeField.getText().replaceAll("\\s*","");
String step=stepField.getText().replaceAll("\\s*","");
String longtitude=longitudeField.getText().replaceAll("\\s*","");
String latitude=latitudeField.getText().replaceAll("\\s*","");
int confirmed=JOptionPane.showConfirmDialog(null,"Your IMEI:"+imeiCodeFileld.getText()+"\n"
+"Your version:"+versionComboBox.getSelectedItem().toString()+"\n"+"Approximate time:"+timeField.getText()+"(s)\n"
+"Approximate steps:"+stepField.getText()+"\n"
int confirmed=JOptionPane.showConfirmDialog(null,"Your IMEI:"+imeiCode+"\n"
+"Your version:"+version+"\n"
+"Approximate time:"+time+"(s)\n"
+"Approximate steps:"+step+"\n"
+"Longtitude:"+longtitude+"\n"
+"Latitude:"+latitude,"确认",JOptionPane.YES_NO_OPTION);
//System.out.println(confirmed);
if(confirmed==0){
if(imeiCodeFileld.getText().length()!=32){
if(imeiCode.length()!=32){
JOptionPane.showMessageDialog(null, "IMEI码长度应为32", "错误",JOptionPane.ERROR_MESSAGE);
}else {
WorkingFrame workingFrame = new WorkingFrame(imeiCodeFileld.getText(), versionComboBox.getSelectedItem().toString(), timeField.getText(), stepField.getText(),longtitude,latitude);
MainFrame.this.setEnabled(false);
MainFrame thisMainFrame=MainFrame.this;
WorkingFrame workingFrame = new WorkingFrame(thisMainFrame,imeiCode, version, time, step,longtitude,latitude);
workingFrame.setVisible(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -20,14 +22,21 @@
* @author dasd
*/
public class WorkingFrame extends JFrame {
public WorkingFrame(String imeiCode,String version,String seconds,String steps,String longitude,String latitude) {
public WorkingFrame(MainFrame mainFrame,String imeiCode,String version,String seconds,String steps,String longitude,String latitude) {
this.imeiCode=imeiCode;
this.version=version;
this.seconds=Integer.parseInt(seconds);
this.steps=Integer.parseInt(steps);
this.longtitude=longitude;
this.latitude=latitude;
//this.returnFrame=mainFrame;
initComponents();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
mainFrame.setEnabled(true);
}
});
RunFucker runFucker=new RunFucker();
runFucker.execute();
}
Expand Down Expand Up @@ -131,9 +140,13 @@ public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,"还未完成,日志尚未完全生成","提示",JOptionPane.PLAIN_MESSAGE);
}else{
JFileChooser jfc=new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
jfc.showDialog(new JLabel(), "选择");
File file=jfc.getSelectedFile();
jfc.setSelectedFile(new File(jfc.getCurrentDirectory()+"/log["+formatter.format(new Date(System.currentTimeMillis())).substring(0,10)+"].txt"));
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY );
File file=null;
if(jfc.showDialog(new JLabel(), "选择")==JFileChooser.APPROVE_OPTION){
file=jfc.getSelectedFile();
}
//System.out.println(file.getAbsolutePath());
if (file != null) {
if (!file.isFile()) {
try {
Expand All @@ -145,15 +158,24 @@ public void actionPerformed(ActionEvent e) {
}
if (file.isFile()) {
String log = logText.toString();
FileOutputStream output=null;
try {
FileOutputStream output = new FileOutputStream(file);
output = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(output, "utf-8");
writer.write(log);
writer.flush();
JOptionPane.showMessageDialog(null, "导出日志成功", "提示", JOptionPane.PLAIN_MESSAGE);
} catch (IOException ioException) {
JOptionPane.showMessageDialog(null, "写入文件失败", "错误", JOptionPane.ERROR_MESSAGE);
ioException.printStackTrace();
}finally {
if(output!=null){
try {
output.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
}
}
Expand Down Expand Up @@ -190,6 +212,10 @@ public void actionPerformed(ActionEvent e) {

public static String lastErrorResponse="";

public SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");

//private MainFrame returnFrame;

private class ProgressData{
private int curSecond; // 备用
private String log;
Expand All @@ -198,8 +224,6 @@ private class ProgressData{

public class RunFucker extends SwingWorker<StringBuilder,ProgressData> {

SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");

public RunFucker(){

}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ WHU-汉姆-阳光体育代跑图形界面工具-环境打包-即开即用

### Update

#### v0.1.3

修复日志导出文件选择框逻辑,加入界面锁,过滤所有输入框空格

#### v0.1.2

修改异常处理机制,删除部分冗余
Expand Down

0 comments on commit 34781c6

Please sign in to comment.