carookee - group communication for you
Home / JavaForum / Java allgemein
Infos   |   Features   |   Gold-Edition   |   Kundenservice   
java
  Übersicht
  Forum
Beginner
Java allgemein
JDBC
JNI
Networking
Online-Ressourcen
Swing + AWT
XML
Meckerecke
  Mitglieder
LOGIN





· Passwort vergessen
· Kostenlos anmelden
  Information
  Demo
  Features
  Im Vergleich
  Anmeldung
SUCHE
Beiträge, Foren oder Verfasser finden:
  Kundenservice
  Impressum
  Datenschutz
  AGB
Status
4.585 User online
0 User eingeloggt
 

Beiträge
   Antworten     Neuer Beitrag    

Beitrag 1520 von 2212 (69%) |<   <   >   >|

Autor Patrick Hypscher
Datum 01.11.01, 23:00
Betreff Re: Zeitgeber


mit Syntax-Highlighting:
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;

public class Shutdown extends JFrame implements ActionListener{
    JTextField field, path;
    String PATH;
    JRadioButton end, restart, user;
    
    public Shutdown() {
        setTitle("PC herunterfahren");
        setSize(200,200);
        addWindowListener( new WindowAdapter()
        { public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    } );
    setResizable(true);
    JPanel pane = new JPanel(new BorderLayout());
    JPanel panel = new JPanel(new BorderLayout());
    JPanel bottom = new JPanel(new FlowLayout());
    JPanel center = new JPanel(new BorderLayout());
    field = new JTextField("0",10);
    JButton start = new JButton("Los");
    JButton exit = new JButton("Beenden");
    JButton file = new JButton("Wählen");
    file.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            path();
        }
    });
    start.addActionListener(this);
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.exit(0);
        }
    });
    bottom.add(file);
    bottom.add(start);
    bottom.add(exit);
    
    Box box = Box.createVerticalBox();
    ButtonGroup group = new ButtonGroup();
    end = new JRadioButton(" Herunterfahren", true);
    restart = new JRadioButton(" neu Starten");
    user = new JRadioButton(" Benutzer");
    group.add(end);
    group.add(restart);
    group.add(user);
    path = new JTextField(20);
    box.add(new JLabel("Zeit in Sekunden:"));
    box.add(field);
    box.add(end);
    box.add(restart);
    box.add(user);
    box.add( new JLabel("Benutzer-Pfad:"));
    box.add(path);
    center.add(box, BorderLayout.CENTER);
    center.add(bottom, BorderLayout.SOUTH);
    //panel.setBorder(new EtchedBorder());
    panel.add(center, BorderLayout.CENTER);
    pane.add(new JLabel(" "), BorderLayout.NORTH);
    pane.add(new JLabel(" "), BorderLayout.SOUTH);
    pane.add(new JLabel(" "), BorderLayout.EAST);
    pane.add(new JLabel(" "), BorderLayout.WEST);
    pane.add(panel, BorderLayout.CENTER);
    setContentPane(pane);
    pack();
    
}
public static void main(String[] args) {
    Shutdown frame = new Shutdown();
    frame.show();
}

public void path() {
    JFileChooser filechooser = new JFileChooser();
    filechooser.setMultiSelectionEnabled(false);
    int result = filechooser.showOpenDialog(this.getParent());
    if (result==JFileChooser.APPROVE_OPTION) {
        path.setText(filechooser.getSelectedFile().getPath());
    }
}

public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if(user.isSelected()) PATH = path.getText();
    else if(restart.isSelected()) PATH = "C:/WINDOWS/RUNDLL32.EXE user,ExitWindowsExec";
    else if(end.isSelected()) PATH = "C:/WINDOWS/RUNDLL32.EXE user,exitWindows";
    else PATH = " ";
    if (source instanceof JButton) {
        javax.swing.Timer timer = new javax.swing.Timer(new Integer(field.getText()).intValue()*1000, this);
        timer.setRepeats(false);
        timer.start();
    }
    else {
        try {
            Runtime.getRuntime().exec(PATH);
        }
        catch (Exception E) {
            System.exit(0);
        }
    }
}
}



Diskussionsverlauf:
Zeitgeber
    Re: Zeitgeber

 Auf diesen Beitrag antworten
 Neuen Beitrag verfassen


|<   <   >   >|

                                                                                                                                                                                                                           

Impressum  · Datenschutz  · AGB  · Infos  · Presse
Ein modernes Forum: teamturn.com