import java.awt.*;
import java.awt.event.*;
public class ex28
{
public static void main(String[] args)
{
FrameListener f = new FrameListener("ex28");
Button b1 = new Button("計算せよ");
f.add(b1);
b1.addActionListener(f);
f.setVisible(true);
}
}
class FrameListener extends Frame implements ActionListener
{
public FrameListener(String title)
{
setTitle(title);
setSize(500, 500);
setBackground(Color.BLUE);
setLayout(new FlowLayout());
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if (getBackground() != Color.RED)
setBackground(Color.RED);
else
setBackground(Color.BLUE);
}
}
最終更新:2010年01月04日 07:39