Estou com um problema para criar uma caixa de diálogo…
O problema está na hora que especifico o tipo de mensagem (WARNING_MESSAGE e INFORMATION_MESSAGE), mas por que acontece isso? Não é uma variável estática.
Os erros encontram-se nas linhas 22 e 61…
Se puder ajudar ficarei grato…
import java.io.*;
import javax.swing.*;
public class QuebraArquivo {
public static String formata(int x) {
String base = "teste_parte_";
String ext = ".part";
if(x < 10) return base + "00" + x + ext;
else if(x < 100) return base + "0" + x + ext;
return base + x + ext;
}
public static void main(String[] args){
FileInputStream in = null;
boolean existeArquivo = true;
try {
in = new FileInputStream("teste.exe");
}
catch(FileNotFoundException e) {
existeArquivo = false;
JOptionPane.showMessageDialog(null, "Arquivo não encontrado.", "Erro", WARNING_MESSAGE);
}
try {
if(existeArquivo) {
FileOutputStream out = null;
int c = 0;
int contArq = 1;
int contBytes = 0;
String input = JOptionPane.showInputDialog(
"Tamanho limite dos arquivos particionados (em kb)");
int limite = Integer.parseInt(input) * 1024;
while(c != -1) {
if(contBytes == 0) out = new FileOutputStream(formata(contArq));
c = in.read();
if(c != -1) {
out.write(c);
contBytes++;
}
if(contBytes == limite) {
contBytes = 0;
contArq++;
out.close();
}
}
if(contBytes != 0) {
out.close();
}
in.close();
}
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Arquivo particionado.", "Concluído", INFORMATION_MESSAGE);
}
}
dae kra, como vc mesmo disse é uma variável estática e como tal pra termos acesso à ela devemos informar primeiro o nome da classe…como JOptionPane.WARNING_MESSAGE, não somente o nome da variável como está no teu código, blz!!!
Valeu galera. Pablo sua dica foi muito util. Tem que fazer como o método showMessageDialog, por o JOptionPAne antes. Grato a todos, problema resolvido.
Está aqui o código pronto…
import java.io.*;
import javax.swing.*;
public class QuebraArquivo {
public static String formata(int x) {
String base = "teste_parte_";
String ext = ".part";
if(x < 10) return base + "00" + x + ext;
else if(x < 100) return base + "0" + x + ext;
return base + x + ext;
}
public static void main(String[] args){
FileInputStream in = null;
boolean continua = true;
try {
in = new FileInputStream("teste.exe");
}
catch(FileNotFoundException e) {
continua = false;
JOptionPane.showMessageDialog(null, "Arquivo não encontrado.", "Erro", JOptionPane.WARNING_MESSAGE);
}
try {
int limite = 0;
String input = JOptionPane.showInputDialog(
"Tamanho limite dos arquivos particionados (em kb)");
if(input == null) {
JOptionPane.showMessageDialog(null, "Operação cancelada.", "Mensagem", JOptionPane.INFORMATION_MESSAGE);
continua = false;
}
else if(Integer.parseInt(input) < 1) {
JOptionPane.showMessageDialog(null, "Número Inválido.", "Erro", JOptionPane.WARNING_MESSAGE);
continua = false;
}
else limite = Integer.parseInt(input) * 1024;
if(continua) {
FileOutputStream out = null;
int c = 0;
int contArq = 1;
int contBytes = 0;
while(c != -1) {
if(contBytes == 0) out = new FileOutputStream(formata(contArq));
c = in.read();
if(c != -1) {
out.write(c);
contBytes++;
}
if(contBytes == limite) {
contBytes = 0;
contArq++;
out.close();
}
}
if(contBytes != 0) {
out.close();
}
in.close();
JOptionPane.showMessageDialog(null, "Arquivo particionado.", "Concluído", JOptionPane.INFORMATION_MESSAGE);
}
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Número Inválido.", "Erro", JOptionPane.WARNING_MESSAGE);
}
}