packagetest;importjava.awt.BorderLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.*;publicclassTesttiquimplementsActionListen...
package test;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class Testtiqu implements ActionListener{JTextField field = new JTextField(20);String a = field.getText();public static void main (String[] args){Testtiqu tiqu = new Testtiqu();tiqu.go();}public void go(){JFrame frame = new JFrame("提取测试框");JPanel panel = new JPanel();JTextField field = new JTextField(20);JButton button = new JButton("提取");frame.getContentPane().add(BorderLayout.NORTH,panel);frame.getContentPane().add(BorderLayout.CENTER,button);panel.add(field);button.addActionListener(this);frame.setSize(300,300);frame.setVisible(true);}public void actionPerformed(ActionEvent event){System.out.println("1" + a);}}我在文本框输入字符串后,按提取按钮,结果只打印个“1”。是不是我哪儿写的不对啊?
展开