Bom dia,
é a primeira vez que posto aqui e gostaria de saber se tem como vocês me ajudarem a resolver um pequeno problema com a execução da minha aplicação.
Tenho um JFrame Form(Final.java) e um metodo que executa a limpeza de uns arquivos de log’s. Pois, esses logs geralmente são grandes e demoram para serem limpos e analisados, sendo assim o usuario pode pensr que o programa travou. então pensei em colocar um Frame “LOADING” enquanto o processo é executado.
mas ai que ta: o frame fica transparente e só aparece depois que o processo terminou.
usando Thread sei que resolve isso, mas nao estou conseguindo.
segue codigo:
Thread do Frame “LOADING”
Thread t = new Thread() {
public void run() {
Loading janela = new Loading();
janela.setVisible(true);
try {
sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(Final.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
Codigo que executa a limpeza:
private void editaArquivo(String nomeArquivo) {
setCursor(Cursor.WAIT_CURSOR);
remove = jTextFieldRemove.getText().split(" ");
String del[] = {"t3165799@ossneocs1>", "#", "HELP", "BASIC", "OTHER", "PM COMMANDS", "QUIT", "Stopfile=/", "> lt all", "Checking", "Parsing", "Using", "Fetching", "Connecting", "**", "Trying", "$mobrowser_pid =", "Connected", "Bye... ", "Last MO", "> q!!", "Unable", "> s+",
"Output has been logged to file ", "Bye...", "Logging to file", "Sorting of MO list"};
boolean verify = false;
//begin: opened file and delete the commands and header
try {
BigFile file = new BigFile(nomeArquivo);
for (String line : file) {
if (!verify) {
for (String delete : del) {
if (line.contains(delete)) {
line = line.replace(line, "");
}
if (line.equals(del[del.length - 1])) {
verify = true;
}
if (line.contains("9.0c") && !line.contains("XXXXXXXX")) {
line = line.replace(line, "");
}
}
}
//Remove the commands entered by user
for (int i = 0; i < remove.length; i++) {
if (line.contains("> ") && line.contains(remove[i])) {
line = line.replace(remove[i], "");
}
}
if (line == null) {
line += "fim";
}
attach += line + "\n";
}
file.Close();
setCursor(Cursor.DEFAULT_CURSOR);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "ERROR OPENING THE FILE " + ex.toString(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
//begin: save the file
try {
FileWriter save = new FileWriter(nomeArquivo);
BufferedWriter bw = new BufferedWriter(save);
bw.write(attach);
bw.flush();
bw.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "ERROR SAVING THE FILE", "ERROR" + e.toString(), JOptionPane.ERROR_MESSAGE);
}
// show when the process finish
setCursor(Cursor.DEFAULT_CURSOR);
}
Action que executa o metodo acima:
t.start();
for (File arquivoTemp : file) {
editaArquivo(arquivoTemp.getAbsolutePath());
JOptionPane.showMessageDialog(null, "File Edited");
}
Detalhe: coloquei a Thread para iniciar nesse action acima.
…
Preciso de ajuda quanto a isso.
Obg 