简体   繁体   English

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

[英]how do get the account id when clicking submit button then display the client details on the label?

    // 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){


        }   
    }

In your code you have two btnSubmit variables 在您的代码中,您有两个btnSubmit变量

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

btnSubmit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

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

If you do if(accID==btnSubmit) - Which one are you using? 如果执行if(accID==btnSubmit) -您正在使用哪一个?

But anyway, 但无论如何,

The actionListener is bound to your btnSubmit button so getSource() is going to return the btnSubmit object. actionListener绑定到您的btnSubmit按钮,因此getSource()将返回btnSubmit对象。

Any code within 内的任何代码

public void actionPerformed(ActionEvent e) { ... }

will be executed when clicking the "Submit" button because you created an anonymous action listener specifically for use with the button (hence use of anonymous inner class). 单击“提交”按钮时将执行该操作,因为您创建了专门用于该按钮的匿名操作侦听器(因此使用了匿名内部类)。

Therefore, all you really need to put in the actionPerformed(...) method would be the assignment of the new labels (assuming that they already exist or you got them somewhere). 因此,您真正需要放入actionPerformed(...)方法的就是分配新标签(假设它们已经存在或您将它们放在某个地方)。

eg 例如

btnSubmit.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        lblExampleLabel.setText("This is what the label will become after clicking the button");
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击 RecyclerView 中的项目时如何获取详细信息? - How to get details when clicking on an item in a RecyclerView? 如何在显示文本或单击按钮时获得振动? - How do I get vibration when displaying text or clicking a button? 单击“提交”按钮后如何显示输入的数据? - How to display my inputted data after clicking “submit” button? 如何通过单击FAB按钮获取ID - how to get id by clicking FAB button 单击按钮时如何显示颜色选择器? - How to display a color selector when clicking a button? 单击提交时如何在警报对话框上发布获取响应信息? - How to POST get response information on alert dialog when clicking submit? 在Android Studio中单击“提交”按钮后,如何将输入的值存储到变量并在屏幕上显示它们? - How to store entered values to variables and display them on screen after clicking submit button in Android Studio? 单击下一步按钮时如何获取其他详细信息? - How to get the other details when I click next button? 单击通知时如何显示相同的活动? - How do I display the same activity when clicking a notification? 单击按钮时的java swing jpanel显示 - java swing jpanel display when clicking a button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM