Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
/**
*
* Beschreibung.
*
* @version 1.0 vom 17.09.2004
* @author
*/
public class Guard1 extends JFrame {
// Anfang Variablen
private JLabel jlbstart = new JLabel();
final static JTextField jtfstart = new JTextField();
private JButton jbustart = new JButton();
private JButton jbuziel = new JButton();
private JTextField jtfziel = new JTextField();
private JFileChooser jfco1 = new JFileChooser();
String sFileChoosed;
String str1 = ("\\");
private JFileChooser jfco2 = new JFileChooser();
final static JTextArea jtastart = new JTextArea("", 1, 1);
final static StringBuffer ret = new StringBuffer();
private JScrollPane jspstart = new JScrollPane();
// Ende Variablen
public Guard1(final String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(final WindowEvent evt) { System.exit(0); } });
setBounds(50, 80, 600, 450);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
jtfstart.setText("kein Pfad ausgewählt");
jtfstart.setBackground(Color.red);
jtfstart.setEditable(false);
jtfstart.setToolTipText("Pfad zum Quellordner");
jtfstart.setBounds(5, 45, 580, 20);
getContentPane().add(jtfstart);
jbustart.setIcon(new ImageIcon(Guard1.class.getResource("start.gif")));
jbustart.setToolTipText("Quellordner auswählen");
jbustart.setBounds(5, 10, 35, 35);
getContentPane().add(jbustart, BorderLayout.CENTER);
jbustart.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
jbustartActionPerformed(evt); } });
jbuziel.setIcon(new ImageIcon(Guard1.class.getResource("start.gif")));
jbuziel.setToolTipText("Zielordner auswählen");
jbuziel.setBounds(5, 75, 35, 35);
getContentPane().add(jbuziel, BorderLayout.CENTER);
jbuziel.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
jbuzielActionPerformed(evt); } });
jtfziel.setText("kein Pfad ausgewählt");
jtfziel.setBackground(Color.green);
jtfziel.setEditable(false);
jtfziel.setToolTipText("Pfad zum Zielordner");
jtfziel.setBounds(5, 110, 580, 20);
getContentPane().add(jtfziel, BorderLayout.CENTER);
jtastart.setBackground(Color.red);
jtastart.setEditable(false);
jtastart.setToolTipText("Inhalt Quellordner");
jtastart.setBounds(5, 140, 180, 250);
getContentPane().add(jtastart, BorderLayout.CENTER);
jspstart.setViewportView(jtastart);
jspstart.setBounds(5, 140, 180, 250);
getContentPane().add(jspstart, BorderLayout.CENTER);
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void jbustartActionPerformed(final ActionEvent evt) {
jfco1.setDialogTitle("Ordner auswählen");
jfco1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // um nur Verzeichnisse auszuwählen
if (jfco1.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
String sFileChoosed = jfco1.getSelectedFile().getName();
jtfstart.setText(jfco1.getCurrentDirectory() + str1 + sFileChoosed);
File f = new File(jtfstart.getText());
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
//if (files[i].isFile()) {
ret.append(files[i].getName() + '\n');
// }
}
jtastart.setText(ret.toString());
}
}
public void jbuzielActionPerformed(final ActionEvent evt) {
}
// Ende Ereignisprozeduren
public static void main(final String[] args) {
new Guard1("Guard1");
}
}
Hallo im obrigen Prog. kann ich Ordner auswählen, deren Inhalt dann in einem
TextArea angezeigt werden. Problem jedesmal wenn ich einen neuen Ordner auswähle
wird der Inhalt immer an den des letzten angehängt. Will ich aber nicht.
Muss ich das Array auf null setzen oder was macht man da am besten? JTextArea.setText("");
funktionierte auch nicht.
:?: