【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:ko21_6.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
import java.awt.*;
import java.awt.event.*;
public class ko21_6 extends Frame
{
Button b1=new Button("︹"),
b2=new Button("厚︹"),
b3=new Button("屡︹");
TextArea ta=new TextArea(3,10);
public ko21_6()
{
super("ko21_6");
setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.fill=GridBagConstraints.BOTH;
gbc.gridx=0;
gbc.gridy=0;
gbc.gridwidth=3;
gbc.gridheight=3;
gbc.weightx=1;
gbc.weighty=1;
add(b1,gbc);
gbc.gridx=2;
gbc.gridy=0;
gbc.gridwidth=2;
gbc.gridheight=2;
gbc.weightx=1.0;
gbc.weighty=1.0;
add(ta,gbc);
gbc.gridx=4;
gbc.gridy=0;
gbc.gridwidth=1;
gbc.gridheight=1;
gbc.weightx=0.0;
gbc.weighty=0.0;
add(b2,gbc);
gbc.gridx=4;
gbc.gridy=1;
gbc.gridwidth=1;
gbc.gridheight=1;
gbc.weightx=0.0;
gbc.weighty=0.0;
add(b3,gbc);
b1.setBackground(Color.red);
b2.setBackground(Color.green);
b3.setBackground(Color.blue);
setSize(240,150);
setVisible(true);
b1.addActionListener(new koListener());
b2.addActionListener(new koListener());
b3.addActionListener(new koListener());
addWindowListener(new koWindowListener());
}
class koWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
}
class koListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Color ko=Color.red;
if (e.getSource()==b1)
ko=Color.red;
if (e.getSource()==b2)
ko=Color.green;
if (e.getSource()==b3)
ko=Color.blue;
ta.setBackground(ko);
}
}
public static void main(String args[])
{
ko21_6 ko=new ko21_6();
}
}