duminică, 2 septembrie 2012

monitorizare director cu swing.c


package pack;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

import javax.swing.*;

public class Director extends Thread implements ActionListener {
private JFrame frame;
private JTextField text;
private String[] sir;
private String[] update;
private JPanel top;
private JPanel panel;
private JPanel up;
private long time=3000;
private Button but;
private int dim=0;
Director(){
frame=new JFrame("Director");
frame.setVisible(true);
frame.setSize(200,400);
//frame.setDefaultCloseOperation(frame.getDefaultCloseOperation());
top=new JPanel();
but=new Button("Timp");
top.add(but);
but.addActionListener(this);
text=new JTextField(5);
top.add(text);
top.setLayout(new FlowLayout(FlowLayout.LEFT,1,1));

frame.add(top,BorderLayout.NORTH);

panel=new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
frame.add(panel,BorderLayout.CENTER);
up=new JPanel();
up.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
frame.add(up,BorderLayout.SOUTH);

sir=new String[10];
update=new String[10];

}
public void run(){
String d="director";
File dir=new File(d);
if(dir.isDirectory() && dir.canRead()){

while(true){
sir=dir.list();
int i;
panel.add(new Label("Componentele sunt:" ));
for(i=0;i<sir.length;i++){
panel.add(new Label(sir[i]));
}
if(dim<sir.length){
up.add(new Label("S-au adaugat urmatoare fisiere: "));
for(i=0;i<sir.length;i++){
up.add(new Label(sir[i]));
}
dim=sir.length;
update=dir.list();

}
else{
if(dim>sir.length){
up.add(new Label("S-au sters urmatoare fisiere: "));
for(i=0;i<dim;i++){
if(!update[i].equals(sir[i]))
up.add(new Label(update[i]));
}
dim=sir.length;
update=dir.list();
}
}

try{
sleep(time);
}catch(InterruptedException e){
System.out.println("Thread Intrerupt");
}
panel.removeAll();
up.removeAll();
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==but){
time= Long.parseLong(text.getText());
time=time*1000;
}

}
}
package pack;

public class Test {

/**
* @param args
*/
public static void main(String[] args) {
Director fis=new Director();
fis.start();
}

}

Niciun comentariu:

Trimiteți un comentariu