/* PerusKomponenttiTesti.java Tekijä: Juha Peltomäki. */ import java.awt.*; import java.awt.event.*; public class PerusKomponenttiTesti { public static void main(String[] args) { new Kehys(); } } // Luodaan Frame-olio class Kehys extends Frame { public Kehys() { setSize(300,200); setTitle("Component-testi"); add(new Paneeli()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); System.exit(0); } }); setVisible(true); // show(); } class Paneeli extends Panel { Component c1 = new Button("Button1"); Component c2 = new Label("Label2"); Component c3 = new Button("Button3"); public Paneeli() { setLayout(new GridLayout(3,0)); add(c1); add(c2); add(c3); ((Button)c1).addActionListener(new Kuuntelija()); ((Button)c3).addActionListener(new Kuuntelija()); } class Kuuntelija implements ActionListener { public void actionPerformed(ActionEvent ae) { Object lahdeOlio = ae.getSource(); String txt = ((Button)lahdeOlio).getLabel(); ((Label)c2).setText(txt); validate(); } } } }