第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

獲取秋千標(biāo)簽文本并將其傳遞給父類

獲取秋千標(biāo)簽文本并將其傳遞給父類

拉莫斯之舞 2023-02-16 17:20:09
我有一個(gè)帶有 swing gui 的程序來訂購某些產(chǎn)品。處理訂單的類有一個(gè),JFrame有JPanel一個(gè)JButton。按下該按鈕時(shí),我需要處理訂單的類中的輸入。但是無法弄清楚如何一直獲得該輸入。包含按鈕的面板:public class PayPanel extends JPanel {    private double paidAmount;    private JButton payButton;    public PayPanel() {        setBorder(BorderFactory.createTitledBorder("Make Payment"));        JLabel payLabel = new JLabel("Pay with: ");        JTextField payField = new JTextField(12);        this.payButton = new JButton("Pay");        this.payButton.setPreferredSize(new Dimension(100, 20));        this.payButton.addActionListener(new ActionListener() {            public double paidAmount;            public void actionPerformed(ActionEvent e) {                this.paidAmount = Double.parseDouble(payField.getText());            }            public double getPaidAmount() {                return this.paidAmount;            }        });        setLayout(new GridBagLayout());        GridBagConstraints gridBagConstraints = new GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 1;        add(payLabel, gridBagConstraints);        gridBagConstraints.gridx = 1;        gridBagConstraints.gridy = 1;        add(payField, gridBagConstraints);        gridBagConstraints.weighty = 10;        gridBagConstraints.gridx = 2;        gridBagConstraints.gridy = 1;        add(payButton, gridBagConstraints);    }    public double getPaidAmount() {        ActionListener[] payButtonListeners = this.payButton.getActionListeners();        ActionListener payButtonActionListener = payButtonListeners[0];        return payButtonActionListener.getPaidAmount(); // this function is not recognized even though i defined it in the action listener like shown above in the contructor.     }我paidAmount在ActionListener聲明中添加了變量,這樣我就可以ActionListener從付款按鈕中獲取,然后調(diào)用該getPaidAmount()函數(shù)。但是當(dāng)我ActionListener從中獲取payButton.getActionListeners()然后調(diào)用我聲明的函數(shù)時(shí),java 無法識(shí)別該getPaidAmount()函數(shù)。我的問題是,我如何獲取它paidAmount并將其從按鈕傳輸?shù)矫姘?,然后從面板傳輸?shù)娇蚣?,再從框架傳輸?shù)綋碛锌蚣艿念悾?
查看完整描述

1 回答

?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊

嘗試將函數(shù)放在 actionListener 之外并放在類中PayPanel

    public double getPaidAmount() { 
               return this.paidAmount;
    }

并使用payPanelObject.getPaidAmount()


查看完整回答
反對 回復(fù) 2023-02-16
  • 1 回答
  • 0 關(guān)注
  • 117 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號