| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 682 人关注过本帖
标题:JAVA JTextField的。getText()获取不了
取消只看楼主 加入收藏
_c_c
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2014-3-26
结帖率:100%
收藏
 问题点数:0 回复次数:3 
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

}

搜索更多相关主题的帖子: color JAVA java 
2015-08-02 01:41
_c_c
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2014-3-26
收藏
得分:0 
中间是布局,不用看
2015-08-02 01:42
_c_c
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2014-3-26
收藏
得分:0 
程序代码:
[code] 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;
    }
[/code]
主要是这个
2015-08-02 01:43
_c_c
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2014-3-26
收藏
得分:0 
没人吗? id2 = jTextField1.getText().toString().trim();点击按钮获取的是null啊
2015-08-02 01:56
快速回复:JAVA JTextField的。getText()获取不了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038447 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved