gpt4 book ai didi

java - 如何只显示点击按钮的数据?

转载 作者:行者123 更新时间:2023-11-30 02:57:56 25 4
gpt4 key购买 nike

我正在从事一个面包店销售系统项目。我将订单页面和支付页面分成两个框架。我想仅在单击按钮时在订单框架中的付款框架中显示按钮后面的数据。

有办法吗?

这是我的订单页面代码:

import java.text.DecimalFormat; 
class Bun extends javax.swing.JFrame {
String decimal = "#.##";
DecimalFormat df = new DecimalFormat(decimal);
public final String [] bname = new String [] {"Tuna Sandwich","Garlic Bread","Redbean Bun","Sausage Bun","Chicken Burger","Ham Sandwich","Egg Mayo Bun","Chocolate Bread","Potato Bun"};
public final double [] bprice = new double [] {1.20, 2, 1.50, 2, 3, 2, 2, 1.50, 1.20};
public final double [] bsub = new double [] {0,0,0,0,0,0,0,0,0};
public double bsubtotal=0;

public Bun() {
initComponents();
}

private void BtnTunaSandwichActionPerformed(java.awt.event.ActionEvent evt) {
BtnTunaSandwich.setText(bname[1]+" - RM "+bprice[1]);
}

private void BtnGarlicBreadActionPerformed(java.awt.event.ActionEvent evt) {
BtnGarlicBread.setText(bname[2]+" - RM "+bprice[2]);
}

private void BtnRedbeanBunActionPerformed(java.awt.event.ActionEvent evt) {
BtnRedbeanBun.setText(bname[3]+" - RM "+bprice[3]);
}

private void BtnSausageBunActionPerformed(java.awt.event.ActionEvent evt) {
BtnSausageBun.setText(bname[4]+" - RM "+bprice[4]);
}

private void BtnChickenBurgerActionPerformed(java.awt.event.ActionEvent evt) {
BtnChickenBurger.setText(bname[5]+" - RM "+bprice[5]);
}

private void BtnHamSandwichActionPerformed(java.awt.event.ActionEvent evt) {
BtnHamSandwich.setText(bname[6]+" - RM "+bprice[6]);
}

private void BtnEggMayoBunActionPerformed(java.awt.event.ActionEvent evt) {
BtnEggMayoBun.setText(bname[7]+" - RM "+bprice[7]);
}

private void BtnChocolateBreadActionPerformed(java.awt.event.ActionEvent evt) {
BtnChocolateBread.setText(bname[8]+" - RM "+bprice[8]);
}

private void BtnPotatoBunActionPerformed(java.awt.event.ActionEvent evt) {
BtnPotatoBun.setText(bname[9]+" - RM "+bprice[9]);
}

private void numTunaSandwichActionPerformed(java.awt.event.ActionEvent evt) {
bsub[1] = Integer.parseInt(numTunaSandwich.getText())*bprice[1];
}

private void numGarlicBreadActionPerformed(java.awt.event.ActionEvent evt) {
bsub[2] = Integer.parseInt(numGarlicBread.getText())*bprice[2];
}

private void numRedbeanBunActionPerformed(java.awt.event.ActionEvent evt) {
bsub[3] = Integer.parseInt(numRedbeanBun.getText())*bprice[3];
}

private void numSausageBunActionPerformed(java.awt.event.ActionEvent evt) {
bsub[4] = Integer.parseInt(numSausageBun.getText())*bprice[4];
}

private void numChickenBurgerActionPerformed(java.awt.event.ActionEvent evt) {
bsub[5] = Integer.parseInt(numChickenBurger.getText())*bprice[5];
}

private void numHamSandwichActionPerformed(java.awt.event.ActionEvent evt) {
bsub[6] = Integer.parseInt(numHamSandwich.getText())*bprice[6];
}

private void numEggMayoBunActionPerformed(java.awt.event.ActionEvent evt) {
bsub[7] = Integer.parseInt(numEggMayoBun.getText())*bprice[7];
}

private void numChocolateBreadActionPerformed(java.awt.event.ActionEvent evt) {
bsub[8] = Integer.parseInt(numChocolateBread.getText())*bprice[8];
}

private void numPotatoBunActionPerformed(java.awt.event.ActionEvent evt) {
bsub[9] = Integer.parseInt(numPotatoBun.getText())*bprice[9];
}

public void Calculatetotalb(){
for(double i : bsub){
bsubtotal += i;
}
}

我还没有在付款框架中写任何内容。但我的订单框架如下所示:

Order Frame

这是我的付款框架:

Payment frame

我想将数据显示到该 Jlist 中。请帮忙,非常感谢。

最佳答案

将数据从一帧传输到另一帧只不过是在对象之间交换数据。你需要做的第一件事就是实现PaymentFrame 中的方法将接受数据并更改列表

class PaymentFrame{

public void setData(String list){
//get the list from the method and update the jlist
jlist.add(list);
}

}

下一步是从您的案例 Orderframe 中的另一个类调用此方法

class orderFrame{
paymentframe pay;
public void sendData(String data){
if(pay==null){
pay = new paymentframe();
}
pay.setdata(data);
pay.setvisible(true);
}

}

这是一个执行您所要求的操作的示例,如果您已经在项目中打开了 PaymentFrame,则应该从订单框架访问相同的对象。

关于java - 如何只显示点击按钮的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751108/

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