JAVA JTextField的。getText()获取不了
程序代码:
/* * 登陆.java * * Created on __DATE__, __TIME__ */ package ATM; import javax.swing.JFrame; import javax.swing.JPasswordField; import org.junit.Test; /** * * @author __USER__ */ public class 登陆 extends javax.swing.JFrame { /** Creates new form 登陆 */ public 登陆() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ //GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jPasswordField1 = new javax.swing.JPasswordField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("\u7528\u6237\u767b\u9646"); jLabel2.setText("\u7528\u6237ID\uff1a"); jLabel3.setText("\u5bc6\u7801\uff1a"); jButton1.setText("\u767b\u9646"); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) { jButton1MouseReleased(evt); } }); jButton2.setText("\u6ce8\u518c"); jButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) { jButton2MouseReleased(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout( getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addGap(158, 158, 158) .addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup( layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel3)) .addPreferredGap( javax.swing.) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup( layout.createSequentialGroup() .addComponent( jButton1) .addPreferredGap( javax.swing., javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jButton2)) .addComponent( jPasswordField1) .addComponent( jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))) .addContainerGap(91, Short.MAX_VALUE))); layout.setVerticalGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(38, 38, 38) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent( jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing., 38, Short.MAX_VALUE) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addGap(32, 32, 32))); pack(); }// </editor-fold> //GEN-END:initComponents private void jButton2MouseReleased(java.awt.event.MouseEvent evt) { // TODO add your handling code here: new RegeditView(); } @Test public Account temp(){ String id2 = null; try { id2 = jTextField1.getText().toString().trim(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("ID2"+id2); String password = jPasswordField1.getPassword().toString(); System.out.println("pw"+password); return null; } private void jButton1MouseReleased(java.awt.event.MouseEvent evt) { // TODO add your handling code here: 登陆 d=new 登陆(); d.temp(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new 登陆().setVisible(true); } }); } //GEN-BEGIN:variables // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPasswordField jPasswordField1; private javax.swing.JTextField jTextField1; // End of variables declaration//GEN-END:variables }