![](/img/trans.png)
[英]How to display only few items of the entire recycler list based on which button is clicked in previous activity?
[英]How to display only the data which button was clicked ?
我當時正在做一個面包店銷售系統項目。 我將訂單頁面和付款頁面分為兩個框架。 我想僅在單擊按鈕時才在“訂單”框架的“付款”框架中顯示按鈕后面的數據。
有辦法嗎?
這是我的訂單頁面代碼:
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;
}
}
我尚未在“付款”框中寫任何內容。 但是這是我的訂單框架,如下所示:
這是我的付款方式:
我想將數據顯示到該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,請執行bt的操作,您應該從訂單框架訪問相同的對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.