Ru77y
Ensign
- Registriert
- Aug. 2007
- Beiträge
- 141
Tach,
bin quasi "Java-Newbe" => besser gesagt, ich lern es zurzeit!
wollt mal was ausprobieren:
Wo es scheitert, is wenn ich den "Press me not Button!" klicke soll eine andere Bildschirmausgabe kommen!
Danke!
bin quasi "Java-Newbe" => besser gesagt, ich lern es zurzeit!
wollt mal was ausprobieren:
Code:
import java.awt.* ;
import java.awt.event.* ;
public class Klick extends Frame
implements ActionListener, WindowListener {
private Button b1;
private Button b2;
// ... more Components ...
public Klick (String s) {
super(s);
}
public void init() {
setLayout (new FlowLayout() );
b1 = new Button("Press me! ");
b1.addActionListener (this);
add(b1);
setLayout (new FlowLayout() );
b2 = new Button("Press me not! ");
b2.addActionListener (this);
add(b2);
// ... more Components ...
addWindowListener(this);
setSize(200,80); // or: pack();
setVisible(true);
}
public static void main (String[] args) {
Klick f = new Klick("Button");
f.init();
}
public void actionPerformed (ActionEvent e)
{
System.out.println("Button was pressed.");
System.out.println("You shouldn´t press the Button.");
}
public void windowClosing (WindowEvent e)
{
dispose();
System.exit(0);
}
public void windowClosed (WindowEvent e) { }
public void windowOpened (WindowEvent e) { }
public void windowIconified (WindowEvent e) { }
public void windowDeiconified (WindowEvent e) { }
public void windowActivated (WindowEvent e) { }
public void windowDeactivated (WindowEvent e) { }
}
Wo es scheitert, is wenn ich den "Press me not Button!" klicke soll eine andere Bildschirmausgabe kommen!
Danke!
Zuletzt bearbeitet von einem Moderator: