You are on page 1of 3

private void setDefaultPlayer() {

String str = JOptionPane.showInputDialog(fr, "Enter le nom du programme fer


mer par dfaut", "Programme par dfaut", JOptionPane.QUESTION_MESSAGE);
if(str != "" || str != null) {
try {
BufferedWriter bfw = new BufferedWriter(new FileWriter(f));
bfw.write(str);
bfw.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public void rebours() // Methode du compte rebours
{
System.out.println(System.getProperty("os.name").toUpperCase());
if (System.getProperty("os.name").toUpperCase().equals("WINDOWS XP")) {
commande = "tskill "+prg;
commande2 = "shutdown -s -t 5";
commandedef = "tskill "+s;
}else if (System.getProperty("os.name").toUpperCase().equals("LINUX")) {
commande = "killall "+prg;
commande2 = "sudo halt";
commandedef = "killall "+s;
}else if(System.getProperty("os.name").toUpperCase().equals("WINDOWS VISTA")
|| System.getProperty("os.name").toUpperCase().equals("WINDOWS SEVEN")) {
commande = "taskkill /IM "+prg+" /T";
commande2 = "shutdown -s -t 5";
commandedef = "taskkill /IM "+s+" /T";
}
minute = i;
seconde = 0;
prg = tff.getText();
tache_timer= new ActionListener()
{
public void actionPerformed(ActionEvent e1) {
seconde--; // Pour le Timer
if(seconde==-1){
seconde=59;
minute--;
}
if(minute==-1){
timer1.stop();
if(defaultPrg.isSelected()){
try {
Runtime.getRuntime().exec(commandedef); // Commande Dos simplement fermer le
prog par dfaut
//en cours apres le timer
} catch (IOException t) { }
}else if(other.isSelected()){
try {
Runtime.getRuntime().exec(commande); // Commande Dos simplement fermer un pr
og choisi
//en cours apres le timer
} catch (IOException t) { }
}
if (close.isSelected()){
System.exit(0); // Ferme le programme
}
if(exit.isSelected()){
try {
Runtime.getRuntime().exec(commande2); // Eteind le PC commande DOS
} catch (IOException t) { }
}
}
tim.setText(""+minute+":"+seconde);
}
};
timer1= new Timer(1000,tache_timer); //Le fameux Timer(le Prccciieuuuxx...)
}
public void validerReponse() // Pour valider l'entier du timer
{
try
{
i = Integer.parseInt(tfm.getText());
}
catch (NumberFormatException f)
{
JOptionPane.showMessageDialog(null, "Veuillez entrer un entier de chiffre.",
"Erreur", JOptionPane.ERROR_MESSAGE);
timer1.stop();
}
}
public void stateChanged(ChangeEvent e) // pour les changements du processus
fermer
{
if(defaultPrg.isSelected())
{
tff.setEnabled(false);
}
else if(other.isSelected())
{
tff.setEnabled(true);
}
}
/**
* @param property
*/
public String defaultPlayer() // Pour ajouter le lecteur par dfaut dans un fic
hier
{
// n'ayant pas trouver comment rcuprer le nom de lecteur depuis le systeme
String tmp = "Erreur";
if ( f.exists() ) { // si le fichier existe
try
{
BufferedReader bfreader = new BufferedReader(new FileReader(f));
tmp = bfreader.readLine().toLowerCase(); // on le lit et on prend la seule l
igne existante, qui contient le nom
bfreader.close();
}catch (IOException e)
{
e.printStackTrace();
}
}
return tmp;
}
public void focusGained(FocusEvent e) // Pour grer les focus sur les champs de
textes, focus on, on prend tout
{ // plus facile d'diter
((JTextComponent) e.getSource()).selectAll();
}
public void focusLost(FocusEvent e) // de mme pour focus off
{
((JTextComponent) e.getSource()).setCaretPosition(0);
}
public static void main(String[]args) // Methode Main
{
String lookAndFeelName = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(lookAndFeelName);
}
catch (ClassNotFoundException e) {}
catch (InstantiationException e) {}
catch (IllegalAccessException e) {}
catch (UnsupportedLookAndFeelException e) {}
new TimerStop();
}
}

You might also like