gpt4 book ai didi

java - JOptionPane 到 JCombobox 或如果可能的话将它们组合起来。?

转载 作者:行者123 更新时间:2023-11-30 04:40:05 25 4
gpt4 key购买 nike

我的 friend 创建了一个银行/ATM 交易程序。它允许用户存款、取款和检查余额。但问题是,它不允许用户选择他/她想要进行的交易,它总是要求用户先存款,然后才能取款或再次检查余额。所以我有一个想法提供一个组合框,但我的另一个问题是我不知道如何做到这一点,因为我只是 Java 编程的初学者。

import javax.swing.JOptionPane;

public class atm {
public static void main (String[] args){
while(true){
String intro = "Welcome to ATM Transactions";
JOptionPane.showMessageDialog(null,intro);
String number1 = JOptionPane.showInputDialog("Please enter the amount to deposit:");
String number2 = "The amount deposited is:" + number1;
JOptionPane.showMessageDialog(null,number2);
String number3 = JOptionPane.showInputDialog("Please enter the amount to withdraw:");
int number4 = (Integer.parseInt(number1)) - (Integer.parseInt(number3));
String answer = "The remaining balance is:" +number4;
JOptionPane.showMessageDialog(null,answer);
String[] choices = {"Yes", "No"};
int response = JOptionPane.showOptionDialog(null,"Do you want another
transactions?","Question",
JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,choices,"No");
if (response==1)
System.exit(0);
}
}
}

所以我的问题是,如何将其制作成一个组合框,以便用户可以选择他/她想要执行的交易,并且用户可以在不执行第一步的情况下进行多次存款或取款?

最佳答案

要在 JOptionPane 对话框中包含 JComboBox,您必须将其视为对话框的 message 属性。根据the documentation消息可以是一个组件,然后显示在对话框中。确认对话框并将控制权返回到您的代码后,您可以查询下拉列表中选定的值。

关于java - JOptionPane 到 JCombobox 或如果可能的话将它们组合起来。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12495354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com