All pastes #38226 Raw Edit

Miscellany

public java v1 · immutable
#38226 ·published 2006-01-23 19:18 UTC
rendered paste body
import java.awt.*;import java.awt.event.*;public class FensterSchließenAdapter extends WindowAdapter {private boolean exitSystem   = true;private boolean askForDialog = true;   protected FensterSchließenAdapter(){   }      public FensterSchließenAdapter(boolean exitSystem){     this.exitSystem = exitSystem;   }   public void FensterSchließenAdapter(boolean exitSystem, boolean askForDialog){     this.exitSystem   = exitSystem;     this.askForDialog = askForDialog;   }      public void windowClosing(WindowEvent e){    Frame f = (Frame) e.getSource();        if(exitSystem&&askForDialog){          JaNeinFenster jaNein = new JaNeinFenster(f, "Wollen Sie das Programm beenden?");         jaNein.setVisible(true);      }   }         // innere Dialogklasse einfügen public class JaNeinDialog extends Dialogimplements ActionListener {   boolean resultat;   public JaNeinDialog(Frame fenster, String nachricht) {      super(fenster, "Ja/Nein auswählen", true);      setLayout(new BorderLayout());      setResizable(false);      Point parloc = fenster.getLocation();      setLocation(parloc.x + 30, parloc.y + 30);      //Nachricht ausgeben      add(new Label(nachricht), BorderLayout.CENTER);      //Buttons      Panel panel = new Panel();      panel.setLayout(new FlowLayout(FlowLayout.CENTER));      Button button = new Button("Ja");      button.addActionListener(this);      panel.add(button);      button = new Button("Nein");      button.addActionListener(this);      panel.add(button);      add(panel, BorderLayout.SOUTH);      pack();   }   public void actionPerformed(ActionEvent event) {      resultat = event.getActionCommand().equals("Ja");      if(resultat){      setVisible(false);      dispose();      System.exit(0);      }      else{      setVisible(false);      }   }   public boolean leseResultat() {      return resultat;   } }}import java.awt.*;import java.awt.event.*;public class JaNeinFenster extends Dialog implements ActionListener{ boolean resultat; public JaNeinFenster(Frame fenster){    super(fenster, "Ja oder Nein auswählen" ,true);    setLayout(new BorderLayout());        Button b1 = new Button("Ja");    b1.addActionListener(this);    add(b1);        Button b2 = new Button("Nein");    b2.addActionListener(this);    add(b2); }  public void actionPerformed(ActionEvent e){   Object obj = e.getSource();   if(obj instanceof Button){     String cmd = e.getActionCommand();          if(cmd.equals ("Ja")){     }     if(cmd.equals ("Nein")){     }   } }   public boolean leseResultat() {      return resultat;   }}