Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从另一个类调用arraylist_Java_Eclipse_User Interface - Fatal编程技术网

Java 从另一个类调用arraylist

Java 从另一个类调用arraylist,java,eclipse,user-interface,Java,Eclipse,User Interface,这是我的arraylist类代码; 套餐餐厅 import java.util.ArrayList; public class Controlclass { public static void main(String[] args) { // Create ArrayList for foodItems subclasses ArrayList<Mains> MainsList = new Array

这是我的arraylist类代码; 套餐餐厅

 import java.util.ArrayList;



    public class Controlclass {

        public static void main(String[] args) {
            // Create ArrayList for foodItems subclasses
            ArrayList<Mains> MainsList = new ArrayList<Mains>();
    //add items to the MainsList
            Mains  CurriedFriedRice = new Mains (" Curried fried rice ", 4.00, " Yummy curried fried rice " , 500);
            Mains  LambChopsWithCarrotPuree = new Mains (" Lamb chops with carrot puree ", 6.00, " Delicious Lamb chops with carrot puree " , 580);
            Mains  PadThaiNoodles = new Mains (" Pad Thai noodles ", 5.00, " Amazing thai noodles " , 480);
            Mains  SalmonAndAsparagusFajitas = new Mains (" Salmon and asparagus fajitas ", 4.90, " Fajita you will always come back for " , 450);


    MainsList.add(CurriedFriedRice);
            MainsList.add(LambChopsWithCarrotPuree);
            MainsList.add(PadThaiNoodles);
            MainsList.add(SalmonAndAsparagusFajitas);


    for (Mains mains: MainsList){
                System.out.println(mains);
            }
import java.util.ArrayList;
公共类控制类{
公共静态void main(字符串[]args){
//为foodItems子类创建ArrayList
ArrayList MainsList=新的ArrayList();
//将项目添加到主列表
主食咖喱饭=新主食(“咖喱炒饭”,4.00,“美味咖喱炒饭”,500);
主食羊排配胡萝卜泥=新主食(“羊排配胡萝卜泥”,6.00,“美味羊排配胡萝卜泥”,580);
主电源PadThaiNoodles=新主电源(“Pad Thai面条”,5.00,“神奇泰国面条”,480);
SalmonAndAsparagusFajitas干管=新干管(“鲑鱼和芦笋法吉塔”,4.90,“法吉塔,你永远会回来吃”,450);
主列表添加(CurriedFriedRice);
添加(羊排加胡萝卜泥);
主列表添加(PadThaiNoodles);
主列表添加(SalmonAndAsparagusFajitas);
用于(主电源:主列表){
系统输出打印LN(电源);
}
这就是我需要在其中使用这些ArrayList的GUI类

*

public class TheFoodLoversLounge {
    private final GridLayout layout; // layout of this frame
    private JFrame frame;
    private final JPanel buttonbar;
    private final JPanel combobar;
    private final JPanel receiptbar;
private final JComboBox<String> mainsc; 
public class TheFoodLoversLounge {
    private final GridLayout layout; // layout of this frame
    private JFrame frame;
    private final JPanel buttonbar;
    private final JPanel combobar;
    private final JPanel receiptbar;
    private final JComboBox<String> starters; 
    private final JComboBox<String> mainsc; 
    private final JComboBox<String> dessert; 
    private final JButton getTotalPrice;
    private final JLabel l2;
    private final JLabel l3;
    private final JLabel l4;
    private final JLabel l5;
    private final JLabel l6;
    private final JLabel l7;
    private final JLabel l8;
    private final JLabel l9;
    private final JLabel l10;
    private final JLabel r1;
    private final JLabel r2;
    private final JLabel r3;
    private final JLabel r4;
    private final JLabel r5;
    private final JLabel r6;
    private final JLabel r7;
    private final JLabel r8;
    private final JLabel r9;
    private Controlclass control;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    TheFoodLoversLounge window = new TheFoodLoversLounge();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    /**
     * Create the application.
     */
    public TheFoodLoversLounge() {
        MAXTABLES=10;
        MAXDINERS=10;
        initialize();
        control = new Controlclass();
        layout = new GridLayout(0,1,0,5);
        starters=new JComboBox<>(); 
        mainsc=new JComboBox<>(); 
        dessert=new JComboBox<>(); 

        for (Starters starterI: control.StarterList){
            starters.addItem(starterI.toString());
        }
        starters.setMaximumRowCount(5);
        for (Mains mainsI: control.MainsList){
            mainsc.addItem(mainsI.toString());
        }
        mainsc.setMaximumRowCount(5);
        for (Dessert dessertI: control.DessertList){
            dessert.addItem(dessertI.toString());
        }
buttonbar= new JPanel(layout);
        buttonbar.setBackground(Color.LIGHT_GRAY);
        buttonbar.add(getTotalPrice); buttonbar.add(l10);
combobar= new JPanel(layout);
        combobar.setBackground(Color.PINK);
        combobar.add(l1); combobar.add(starters);
        combobar.add(l2); combobar.add(mainsc);
        combobar.add(l4); combobar.add(dessert);
private void initialize() {
        frame = new JFrame();
        frame.setLocationRelativeTo(null);
        //frame.setResizable(false);
        frame.setSize(768, 800);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
private class TheListener implements ActionListener
    {
        // process text field events
        @Override
        public void actionPerformed(ActionEvent event)
        { 
            String string = "";
            double arr [];
            Orders ord = new Orders();
            if (event.getSource() ==getTotalPrice){
                ord.diners= Integer.parseInt((String) diners.getItemAt(diners.getSelectedIndex()));
                ord.tableno=Integer.parseInt((String) tableno.getItemAt(tableno.getSelectedIndex()));
                ord.item[0]=starters.getItemAt(starters.getSelectedIndex());
                // ord.qty[1]=
                        ord.rate[0]=control.StarterList.get(starters.getSelectedIndex()).price;
                        ord.item[1]=mainsc.getItemAt(mainsc.getSelectedIndex());
                        // ord.qty[2]=
                        ord.rate[1]=control.MainsList.get(mainsc.getSelectedIndex()).price;
                        ord.item[2]=dessert.getItemAt(dessert.getSelectedIndex());
                        // ord.qty[3]=
                        ord.rate[2]=control.DessertList.get(dessert.getSelectedIndex()).price;
}
        }}}
*
公众休息室{
私有最终GridLayout;//此框架的布局
私有JFrame;
私人最终JPanel buttonbar;
私人最终JPanel组合栏;
私人最终JPanel receiptbar;
私人最终JComboBox mainsc;
公众休息室{
私有最终GridLayout;//此框架的布局
私有JFrame;
私人最终JPanel buttonbar;
私人最终JPanel组合栏;
私人最终JPanel receiptbar;
私人最终JComboBox启动器;
私人最终JComboBox mainsc;
私人最终JComboBox甜点;
私人最终JButton getTotalPrice;
私有最终JLabel l2;
私人最终JLabel l3;
私人终场JLabel l4;
私人最终JLabel l5;
私人最终JLabel l6;
私人最终JLabel l7;
私人最终JLabel l8;
私人最终JLabel l9;
私人最终JLabel l10;
私人最终JLabel r1;
私有最终JLabel r2;
私人最终JLabel r3;
私人最终JLabel r4;
私人最终JLabel r5;
私人最终JLabel r6;
私人最终JLabel r7;
私人最终JLabel r8;
私人最终JLabel r9;
私有控制类控制;
/**
*启动应用程序。
*/
公共静态void main(字符串[]args){
invokeLater(新的Runnable(){
公开募捐{
试一试{
TheFoodLoversLounge窗口=新建TheFoodLoversLounge();
window.frame.setVisible(true);
}捕获(例外e){
e、 printStackTrace();
}
}
});
}
/**
*创建应用程序。
*/
公众休息室(){
MAXTABLES=10;
MAXDINERS=10;
初始化();
control=新的Controlclass();
布局=新的网格布局(0,1,0,5);
启动器=新JComboBox();
mainsc=新的JComboBox();
甜点=新的JComboBox();
用于(启动器启动器I:control.StarterList){
starter.addItem(starterI.toString());
}
启动器。设置最大行数(5);
for(mainsI:control.MainsList){
mainsc.addItem(mainsI.toString());
}
mainsc.setMaximumRowCount(5);
for(甜点甜点:控制。甜点列表){
甜点.addItem(dessertI.toString());
}
buttonbar=新JPanel(布局);
纽扣杆.立根(颜色.浅灰色);
buttonbar.add(getTotalPrice);buttonbar.add(l10);
combobar=新的JPanel(布局);
组合栏。背景(颜色。粉红色);
combobar.add(l1);combobar.add(启动器);
combobar.add(l2);combobar.add(mainsc);
combobar.add(l4);combobar.add(甜点);
私有void初始化(){
frame=新的JFrame();
frame.setLocationRelativeTo(空);
//frame.setresizeable(false);
框架设置尺寸(768800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
私有类Listener实现ActionListener
{
//处理文本字段事件
@凌驾
已执行的公共无效操作(操作事件)
{ 
字符串=”;
双arr[];
订单ord=新订单();
if(event.getSource()==getTotalPrice){
ord.diners=Integer.parseInt((字符串)diners.getItemAt(diners.getSelectedIndex());
ord.tableno=Integer.parseInt((字符串)tableno.getItemAt(tableno.getSelectedIndex());
ord.item[0]=starters.getItemAt(starters.getSelectedIndex());
//订单数量[1]=
ord.rate[0]=control.StarterList.get(starters.getSelectedIndex()).price;
ord.item[1]=mainsc.getItemAt(mainsc.getSelectedIndex());
//订单数量[2]=
ord.rate[1]=control.MainsList.get(mainsc.getSelectedIndex()).price;
ord.item[2]=甜点.getItemAt(甜点.getSelectedIndex());
//订单数量[3]=
ord.rate[2]=control.DessertList.get(desrt.getSelectedIndex()).price;
}
}}}
* 请大家忽略语法错误,因为它不是完整的代码,我只想关注arraylist,因为每次我试图编译它时,它都会给我以下错误,而实际代码的语法是正确的。 线程“AWT-EventQueue-0”java.lang中出现异常。错误:未解决的编译问题:

StarterList cannot be resolved or is not a field
    MainsList cannot be resolved or is not a field
    DessertList cannot be resolved or is not a field
    DrinksList cannot be resolved or is not a field
    FishList cannot be resolved or is not a field
    StarterList cannot be resolved or is not a field
    MainsList cannot be resolved or is not a field
    DessertList cannot be resolved or is not a field
    FishList cannot be resolved or is not a field
    DrinksList cannot be resolved or is not a field

    at Restaurant.TheFoodLoversLounge.<init>(TheFoodLoversLounge.java:121)
    at Restaurant.TheFoodLoversLounge$1.run(TheFoodLoversLounge.java:91)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
StarterList无法解析或不是字段
MainsList无法解析或不是字段
甜点列表无法解析或不是字段
DrinkList无法解析或不是字段
无法解析鱼列表
public class Controlclass {
   private ArrayList<Mains> MainsList;

   public ControlClass() {
       MainsList = new ArrayList<Mains>()
   }

   public ArrayList<Mains> getMainsList() {
        return MainsList;
   }
}
for (Mains mainsI: control.getMainsList()){
import java.util.ArrayList;
import java.util.List;

public class Controlclass {

        private List<...> starterList;
        private List<...> mainsList;
        private List<...> dessertList;
        private List<...> drinksList;
        private List<...> fishList;

    public static void main(String[] args) {
        Controlclass controlClass = new Controlclass();
    }

    public Controlclass() {
        starterList = new ArrayList<>(25);
        mainsList = new ArrayList<>(25);
        dessertList = new ArrayList<>(25);
        drinksList = new ArrayList<>(25);
        fishList = new ArrayList<>(25);

        // Populate the values...
    }

    public List<...> getStarterList() {
        return starterList;
    }

    public List<...> getMainsList() {
        return mainsList;
    }

    public List<...> getDessertList() {
        return dessertList;
    }

    public List<...> getDrinksList() {
        return drinksList;
    }

    public List<...> getFishList() {
        return fishList;
    }
}
public class TheFoodLoversLounge {
    //...
    private Controlclass control;

    public TheFoodLoversLounge(Controlclass control) {
        this.control = control
        //...
for (Starters starterI: control.getStarterList()) {
    starters.addItem(starterI.toString());
}