16.11.2013 Aufrufe

Programmieren in Java - HostFiXX.de

Programmieren in Java - HostFiXX.de

Programmieren in Java - HostFiXX.de

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

<strong>Programmieren</strong> <strong>in</strong> <strong>Java</strong><br />

kann es <strong>in</strong> <strong>de</strong>r Button-Klasse durch „public void setActionCommand(Str<strong>in</strong>g<br />

kommando)“ geän<strong>de</strong>rt wer<strong>de</strong>n.<br />

Bsp.: Setzen von H<strong>in</strong>tergrundfarben nach verschie<strong>de</strong>nen Buttonklicks 271<br />

import java.awt.*;<br />

import java.awt.event.*;<br />

public class SchaltApplet extends java.applet.Applet<br />

{<br />

private Button schalt1 = new Button("Rot");<br />

private Button schalt2 = new Button("Blau");<br />

private Button schalt3 = new Button("Gruen");<br />

private Button schalt4 = new Button("Gelb");<br />

private Button schalt5 = new Button("Schwarz");<br />

public void <strong>in</strong>it()<br />

{<br />

setBackground(Color.white);<br />

schalt1.addActionListener(new ActionListener()<br />

{<br />

public void actionPerformed(ActionEvent e)<br />

{<br />

setBackground(Color.red);<br />

}<br />

});<br />

schalt2.addActionListener(new ActionListener()<br />

{<br />

public void actionPerformed(ActionEvent e)<br />

{<br />

setBackground(Color.blue);<br />

}<br />

});<br />

schalt3.addActionListener(new ActionListener()<br />

{<br />

public void actionPerformed(ActionEvent e)<br />

{<br />

setBackground(Color.green);<br />

}<br />

});<br />

schalt4.addActionListener(new ActionListener()<br />

{<br />

public void actionPerformed(ActionEvent e)<br />

{<br />

setBackground(Color.yellow);<br />

}<br />

});<br />

schalt5.addActionListener(new ActionListener()<br />

{<br />

public void actionPerformed(ActionEvent e)<br />

{<br />

setBackground(Color.black);<br />

}<br />

});<br />

this.setLayout(new Bor<strong>de</strong>rLayout(15,15));<br />

Panel p = new Panel();<br />

p.setLayout(new FlowLayout(FlowLayout.CENTER,15,15));<br />

p.add(schalt1);<br />

p.add(schalt2);<br />

p.add(schalt3);<br />

p.add(schalt4);<br />

p.add(schalt5);<br />

this.add("South",p);<br />

// this.pack();<br />

}<br />

}<br />

271 pr52105<br />

313

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!