当swing面板中有很多密码输入框,有时需要填写一个其他的可以即时同步。而swing面板不同于HTML页面,需要添加事件监听事件addKeyListener()来进行同步。下面是简单的原理实现。
import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class textAreaTest extends JFrame{
JTextField name;
JTextField age;
JTextField address;
public textAreaTest(){
this.setTitle("文本框");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 250, 200);
JPanel contentPane=new JPanel();
contentPane.setBorder(new EmptyBorder(5,5,5,5));
this.setContentPane(contentPane);
contentPane.setLayout(new GridLayout(3,1,5,5));
JPanel pane1=new JPanel();