java GUI编程 swing 给按钮添加的事件中获取JLabel输入框的值
外面JLabel的代码段
JTextField txtName = new JTextField();
txtName.setBounds(150, 65, 146, 18);
add(txtName);
txtName.setColumns(10);
JButton里面的代码
JButton btnNewButton = new JButton("添加");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String name=txtName.getText();//在这里直接用getText方法就可以获取JLabel里面的值了