Hirdetés

Új hozzászólás Aktív témák

  • n00n

    őstag

    Ismét kellene egy kis segítség:

    Adott kettő class közös package-ben:

    programGUI és fileMasolas

    programGUI.java ködrészlete:

    //Progress bar:
    JDialog copyModalDialog = new JDialog();
    copyModalDialog.setTitle("Mentés másolása folyamatban");

    pb = new JProgressBar(0, 100);
    pb.setValue(0);
    pb.setStringPainted(true);

    JPanel panel = new JPanel();
    panel.add(pb);

    panel.setBorder(BorderFactory.createEmptyBorder(40, 75, 40, 75));
    copyModalDialog.setContentPane(panel);
    copyModalDialog.setResizable(false);
    copyModalDialog.setModal(true);
    copyModalDialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    copyModalDialog.pack();
    copyModalDialog.setLocationRelativeTo(null);

    //fájlmásolás szál indítása:
    fileMasolas tMasolas = new fileMasolas();
    tMasolas.start();

    //progress ablak megjelenítése:
    copyModalDialog.setVisible(true);

    fileMasolas.java kód:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package proba;

    import java.io.*;

    class fileMasolas extends Thread {

    public fileMasolas() {
    }

    public void run() {
    File filein = new File("D:/adat.db");
    File fileout = new File("D:/adat_new.db");

    FileInputStream fin = null;
    FileOutputStream fout = null;
    long length = filein.length();
    long counter = 0;
    int r = 0;
    byte[] b = new byte[100];
    try {
    fin = new FileInputStream(filein);
    fout = new FileOutputStream(fileout);
    while ((r = fin.read(b)) != -1) {
    counter += r;
    int bar = (int) (100.0 * counter / length);
    MentesKeszitoGUI.pb.setValue(bar);
    fout.write(b, 0, r);
    }
    } catch (Exception e) {
    System.out.println("Hiba");
    }
    }
    }

    A kérdés, ha végzett a run() metódus, hogyan tudom ezt a szálat leállítani és visszaadni a másiknak a vezérlést. Vagyis eltüntetni a copyModalDialog-ot?

Új hozzászólás Aktív témák