一个简单的布局和时间的组合程序,没什么可借鉴的的地方,只是作为曾经做过的一个标志。
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());
}
}
评论