Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击“提交”按钮,然后在标签上显示客户端详细信息时,如何获取帐户id?_Java_Swing_Actionlistener - Fatal编程技术网

Java 单击“提交”按钮,然后在标签上显示客户端详细信息时,如何获取帐户id?

Java 单击“提交”按钮,然后在标签上显示客户端详细信息时,如何获取帐户id?,java,swing,actionlistener,Java,Swing,Actionlistener,在代码中有两个btnSubmit变量 // submit button JButton btnSubmit = new JButton("Submit"); btnSubmit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton btnSubmit = new JButton("Submit"); /

在代码中有两个btnSubmit变量

    // submit button
    JButton btnSubmit = new JButton("Submit");

    btnSubmit.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

    JButton btnSubmit = new JButton("Submit");
        //label that used to display the name, house number, postcode
    JLabel lblNameDisplay = new JLabel("-");

    JLabel lblHouseNoDisplay = new JLabel("-");

    JLabel lblPostCodeDisplay = new JLabel("-");

    Object accID = e.getSource();
    //when clicking the submit, should get account id and display the client details on the label
    if(accID==btnSubmit){


        }   
    }

JButton btnSubmit=新JButton(“提交”) 里面有代码吗

JButton btnSubmit = new JButton("Submit");     <-----

btnSubmit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JButton btnSubmit = new JButton("Submit");    <-----
将在单击“提交”按钮时执行,因为您创建了一个专门用于该按钮的匿名操作侦听器(因此使用匿名内部类)

因此,在actionPerformed(…)方法中真正需要做的就是分配新的标签(假设它们已经存在或者您在某处找到了它们)

e、 g


第一个,因为它应该用来获取帐户id和显示客户详细信息。是的,这就是为什么我无法获取帐户id。你知道吗?对不起,什么是帐户id?我看不见你的密码。actionListener绑定到您的btnSubmit按钮,因此getSource()将返回btnSubmit对象。JButton btnSubmit=new JButton(“提交”);btnSubmit.addActionListener(新建ActionListener(){public void actionPerformed(ActionEvent e){lblNameDisplay.setText(getfamilyName());lblHouseNodeDisplay.setText(gethouseNumber());lblPostCodeDisplay.setText(getpostCode());}}});在单击提交按钮之前,我需要插入帐户id。我只能在标签上显示客户的详细信息,如姓名、房屋和房屋号。我想你想说的是,当按下提交按钮时,你需要获得与帐户id相关的详细信息。在这种情况下,您需要在actionPerformed(…)方法中获取这些信息,然后设置标签。如果您试图访问帐户ID,请注意它应该是一个类变量或声明为final,以便在匿名内部类中可以访问它。
public void actionPerformed(ActionEvent e) { ... }
btnSubmit.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        lblExampleLabel.setText("This is what the label will become after clicking the button");
    }
});