我正在开发一个将数组传递给另一个类的程序。但是,当我尝试加载我传递一组数组值的类时,其中没有值。看我的代码:
Menu.java
public class Menu extends javax.swing.JFrame {
private String[] menu;
private Globals vars = new Globals();
private DefaultTableModel grill;
private DefaultTableModel seafoods;
private DefaultTableModel rice;
private DefaultTableModel drinks;
private int menuCount;
public Menu() {
initComponents();
this.setLocationRelativeTo(null);
menuCount = vars.countMenu();
menu = new String[menuCount];
menu = vars.setMenu();
grill = (DefaultTableModel) jTable1.getModel();
seafoods = (DefaultTableModel) jTable2.getModel();
rice = (DefaultTableModel) jTable3.getModel();
drinks = (DefaultTableModel) jTable4.getModel();
/*** SOME CODES HERE ***/
/*** item_name, item_code, item_qty, item_price are arrays ***/
/*** I have already tested them and they have values ***/
if (noValue > 0) {
JOptionPane.showMessageDialog(null, "Please input quantity");
return;
}
if (count == 0) {
JOptionPane.showMessageDialog(null, "Plese select some items");
return;
} else {
Transaction trns = new Transaction();
//JOptionPane.showMessageDialog(null, count);
trns.setSelectedItems(item_name, item_code, item_qty, item_price, count);
trns.setVisible(true);
//this.setVisible(false);
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Menu().setVisible(true);
}
});
}
Transaction.java
public class Transaction extends javax.swing.JFrame {
private String[] itemcode;
private double[] qty;
private double[] price;
private String[] items;
private String[] info;
private static Scanner iRead;
private int count;
public Transaction() {
initComponents();
this.setLocationRelativeTo(null);
itemcode = new String[count];
DefaultListModel listModel = new DefaultListModel();
String header = "| Item Code | Item Name | Price | Quantity";
listModel.addElement(header);
JOptionPane.showMessageDialog(null, count);
lsItems.setModel(listModel);
}
public void setSelectedItems(String[] itm, String[] cd, double[] qnty, double[] prc, int itemCnt) {
this.items = itm;
this.itemcode = cd;
this.qty = qnty;
this.price = prc;
this.count = itemCnt;
}
}
我正在尝试将{setSelectedItems()
类的数组[Menu
]传递给Transaction
类。但是,当我加载Transaction
类时,没有收到任何值。