2014-01-13 4 views
0

죄송 합니다만,이 질문이 멍청한 질문 인 것처럼 보이지만 내 프로그램에서 "56 비트 DES 키 생성 중"부분에 JProgress 막대를 추가 할 수 있는지 말해 줄 수 있습니다 ... "그렇다면 어떻게 할 것인가?프로그램의 가로 막 대형 막대

또한 "귀하의 키가 생성되었습니다!"라는 대화 상자를 자동으로 닫을 수 있습니까?

진행률 막대의 목적은 순수한 미학을위한 것입니다.

도움 주셔서 감사합니다.

코드 :

public class myDesCbc2 { 


public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { 


     JFrame frame = null; 
     JFileChooser fChoose = new JFileChooser(System.getProperty("user.home")); 
     int returnVal = fChoose.showOpenDialog(frame); 
     File myFile = fChoose.getSelectedFile(); 

     FileInputStream fis = new FileInputStream(myFile); 
     BufferedReader stream = new BufferedReader(new InputStreamReader(fis, "ISO-8859-1")); 
     String file; 
     while ((file = stream.readLine()) != null) { 

      JOptionPane.showOptionDialog(
        null, "Generating a 56-bit DES key...", "Processing...", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null); 

     } 
     // Create an 8-byte initialization vector 
     SecureRandom sr = new SecureRandom(); 
     byte[] iv = new byte[8]; 
     sr.nextBytes(iv); 
     IvParameterSpec IV = new IvParameterSpec(iv); 

     // Create a 56-bit DES key 
     KeyGenerator kg = KeyGenerator.getInstance("DES"); 

     // Initialize with keysize 
     kg.init(56); 
     Key mykey = kg.generateKey(); 

     JOptionPane.showOptionDialog(
       null, "Your key has been generated!", "Processing...", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null); 

     // Create a cipher object and use the generated key to initialize it 
     Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); 

     cipher.init(Cipher.ENCRYPT_MODE, mykey, IV); 

     byte[] plaintext = file.getBytes("UTF8"); 

     // Encrypt the text 
     byte[] ciphertext = cipher.doFinal(plaintext); 

     JOptionPane.showMessageDialog(
       null, "Your ciphertext is" + asHex(ciphertext), "Done!", JOptionPane.PLAIN_MESSAGE); 

    } 
} 

답변

0

것은 네,하지만 당신은 완전히 코드를 재 작업해야 할 것입니다.

나는 그것이 나에게 더 제어 할 수 있습니다으로이 작업을 수행하기 위해 SwingWorker를 사용하는 것을 선호 싶지만, 핀치에 당신이 ProgressMonitor 또는

ProgressMonitorInputStream은 자세한 내용과 예제

에 대한 How to use progress bars에서 봐 사용할 수 있습니다
관련 문제