Radio
import java.awt.*;
class Radio extends Frame
{
//GUI Elemente erzeugen
Label BandLabel = new Label("Band:");
Button FM = new Button("FM");
Button MW = new Button("MW");
Button LW = new Button("LW");
Button Scan = new Button("Scan");
//Panel erzeugen
Panel buttonPanel = new Panel();
Panel mainPanel = new Panel();
Radio()
{
//Frame initialisieren
setTitle("Radio");
setSize(300,120);
setResizable(false);
//Layouts setzen
setLayout(new BorderLayout());
buttonPanel.setLayout(new GridLayout(1,3));
mainPanel.setLayout(new BorderLayout());
//GUI zusammensetzen
buttonPanel.add(FM);
buttonPanel.add(MW);
buttonPanel.add(LW);
mainPanel.add(buttonPanel, BorderLayout.CENTER);
mainPanel.add(BandLabel, BorderLayout.NORTH);
mainPanel.add(Scan, BorderLayout.SOUTH);
add(mainPanel, BorderLayout.NORTH);
//Frame sichtbar machen
setVisible(true);
}
}
SchalterGUI
import java.awt.*;
import java.awt.event.*;
class SchalterGUI extends Frame
{
Button On = new Button("On");
Button Off = new Button("Off");
Label status = new Label("Der Schalter funzt noch net.");
SchalterGUI()
{
setTitle("Schalter");
setSize(200,200);
setResizable(false);
setLayout(new BorderLayout());
add(On, BorderLayout.NORTH);
add(status, BorderLayout.CENTER);
add(Off, BorderLayout.SOUTH);
setVisible(true);
On.addActionListener(new Keylistener());
Off.addActionListener(new Keylistener());
}
class Keylistener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if ("On" == e.getActionCommand())
{
status.setText("Der Schalter ist ein.");
}
else
{
status.setText("Der Schalter ist aus.");
}
}
}
}