正文

Java中awt的简单使用2007-12-13 07:51:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/tld5yj/31404.html

分享到:

这是Java中简单的java.awt包的使用,并且使用了监听接口,只是作为一个程序思想的展示,没有什么高深之处。 import java.awt.*;import java.awt.event.*; class ChangeColor extends WindowAdapter implements WindowListener,ActionListener{Frame f;Button r,b,y; public static void main(String args[]) {ChangeColor c=new ChangeColor();  c.execute(); } public void execute() {f=new Frame("改变颜色");  f.setLayout(new FlowLayout());  f.addWindowListener(this);  r=new Button("红色");  b=new Button("蓝色");  y=new Button("黄色");  f.add(r);f.add(b);f.add(y);  r.addActionListener(this);  b.addActionListener(this);  y.addActionListener(this);  f.setSize(400,300);f.setVisible(true); } public void windowClosing(WindowEvent e) {System.exit(0); } public void actionPerformed(ActionEvent e) {if(e.getSource()==r)f.setBackground(Color.red);  else if(e.getSource()==b)f.setBackground(Color.blue);  else if(e.getSource()==y)f.setBackground(Color.yellow); }}

阅读(7417) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册