正文

布局和事件2007-12-22 21:16:00

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

分享到:

一个简单的布局和时间的组合程序,没什么可借鉴的的地方,只是作为曾经做过的一个标志。 import java.awt.*;import java.awt.event.*;import javax.swing.*; public class Copy extends JFrame implements ActionListener{JPanel p1,p2;TextField t1,t2;Label l1,l2;JButton b1,b2; public static void main(String args[]) {new Copy(); } Copy() {addWindowListener(new WindowAdapter()  {public void windowClosing(WindowEvent e)   {System.exit(0);   }  });  setLayout(new GridLayout(2,1));  p1=new JPanel();p2=new JPanel();t1=new TextField();t2=new TextField();  l1=new Label();l2=new Label();b1=new JButton("复制");b2=new JButton("复制");  p1.setLayout(new BorderLayout());  p2.setLayout(new GridLayout(3,1));  p1.add("North",t1);p1.add("East",b1);p1.add("Center",l1);  p2.add(t2);p2.add(l2);p2.add(b2);  b1.addActionListener(this);b2.addActionListener(this);  add(p1);add(p2);setVisible(true);setSize(500,400); } public void actionPerformed(ActionEvent e) {if(e.getSource()==b1)l1.setText(t1.getText());  else if(e.getSource()==b2)l2.setText(t2.getText()); }}

阅读(6794) | 评论(0)


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

评论

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