Java 紧急情况:;错误:非静态变量不能从静态上下文引用此变量;

Java 紧急情况:;错误:非静态变量不能从静态上下文引用此变量;,java,static,this,non-static,Java,Static,This,Non Static,我有4个小时的时间完成练习,但我收到多个“无法从静态上下文引用”错误 以下是全文: MainApp.java:281:错误:非静态变量无法从静态上下文引用此变量 list.addMouseListener(本); ^ java:289:错误:无法从静态上下文引用非静态方法setBounds(int,int,int,int) 立根(300300350150); ^ MainApp.java:292:错误:无法从静态上下文引用非静态方法getContentPane() 容器cp=getConten

我有4个小时的时间完成练习,但我收到多个“无法从静态上下文引用”错误

以下是全文:

MainApp.java:281:错误:非静态变量无法从静态上下文引用此变量
list.addMouseListener(本);
^
java:289:错误:无法从静态上下文引用非静态方法setBounds(int,int,int,int)
立根(300300350150);
^
MainApp.java:292:错误:无法从静态上下文引用非静态方法getContentPane()
容器cp=getContentPane();
^
java:299:错误:非静态变量无法从静态上下文引用此变量
按钮1.addActionListener(此按钮);
^
java:326:错误:无法从静态上下文引用非静态方法包()
包装();
^
java:328:错误:无法从静态上下文引用非静态方法setDefaultCloseOperation(int)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
^
java:330:错误:无法从静态上下文引用非静态方法RentShop(字符串、目录、DefaultListModel)
租赁店(“电影”、猫、列表模型);
^
java:343:错误:非静态变量无法从静态上下文引用此变量
清单2.addMouseListener(本);
^
java:351:错误:无法从静态上下文引用非静态方法setBounds(int,int,int,int)
立根(300300350150);
^
java:354:错误:无法从静态上下文引用非静态方法getContentPane()
容器cp2=getContentPane();
^
java:363:错误:非静态变量无法从静态上下文引用此变量
按钮2.addActionListener(此);
^
MainApp.java:391:错误:无法从静态上下文引用非静态方法包()
包装();
^
java:393:错误:无法从静态上下文引用非静态方法setDefaultCloseOperation(int)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
^
java:395:错误:无法从静态上下文引用非静态方法RentShop(String、Catalogs、DefaultListModel)
RentShop(“游戏”、cat、ListModel2);
^
java:407:错误:非静态变量无法从静态上下文引用此变量
清单3.addMouseListener(本);
^
java:414:错误:无法从静态上下文引用非静态方法setBounds(int,int,int,int)
立根(300300350150);
^
java:416:错误:无法从静态上下文引用非静态方法getContentPane()
容器cp3=getContentPane();
^
java:426:错误:非静态变量无法从静态上下文引用此变量
按钮3.addActionListener(此);
^
MainApp.java:447:错误:无法从静态上下文引用非静态方法包()
包装();
^
java:449:错误:无法从静态上下文引用非静态方法setDefaultCloseOperation(int)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
^
java:463:错误:无法从静态上下文引用非静态方法add(组件)
添加(选项卡窗格);
^
注意:MainApp.java使用未经检查或不安全的操作。
注意:使用-Xlint重新编译:未选中以获取详细信息。

21错误
您需要在main中创建MainApp的实例

您需要将所有代码转移到新的
private void run()
方法(或任何您想要调用的方法),而不是将所有代码都放在
main()

现在,因为您有一个实例,所以要去掉所有的
private静态变量,而只使用
private

私有静态字符串ans

变成

私有字符串

类似于。。。(我没有测试过这个)。注意,我也将MainPro更改为实例方法。删除了所有的静力学

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

import java.awt.BorderLayout;
import javax.swing.DefaultListModel;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JList;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

import java.util.*;


public class MainApp extends JFrame implements ActionListener, MouseListener
{

    private String ans;
    private int ans2;
    private boolean over;

    private int li=-1;
    private int li2=-1;
    private int li3=-1;

    private JFrame frame;

    private JButton button1;
    private JButton button2;
    private JButton button3;

    private JButton gfbutton;
    private JButton rbutton;

    private JLabel label;
    private JLabel label2;
    private JLabel label3;

    private JTextArea area;
    private JTextArea area2;
    private JTextArea area3;

    private JList list;
    private JList list2;
    private JList list3;

    private DefaultListModel ListModel;
    private DefaultListModel ListModel2;
    private DefaultListModel ListModel3;

    public static Catalogs cat = new Catalogs();
    public static String Items;
    public static String RentsList;



    public void lists(JTextArea area, JLabel label, JList list) //For games and films
    {
        boolean flag=false;
        int i=0;

        while(i<cat.items.size() && flag==false)
        {
            if( cat.items.get(i).getProname().equals ( list.getSelectedValue() ) )
            {
                area.setText(cat.items.get(i).toString());

                String pathimage = "Images/" + cat.items.get(i).getProname() + ".jpg";

                label.setIcon(new ImageIcon(pathimage));

                flag=true;
            }

            i++;
        }

        if(cat.items.get(i).getRentnum()>0)
            cat.rentItems.add(cat.items.get(i).RentItem());     
         else   
            JOptionPane.showMessageDialog(null,"Sorry...","There are no available copies left",JOptionPane.INFORMATION_MESSAGE); 
    }




    public void mouseClicked(MouseEvent event)
    {                       

        if (list.getSelectedIndex() != li) 
        {
            lists(area, label, list);
        }

        else if (list2.getSelectedIndex() != li2) 
        {
            lists(area2, label2, list2);
        }

        else if (list3.getSelectedIndex() != li3) 
        {
            boolean flag=false;
            int i=0;

            while(i<cat.rentItems.size() && flag==false) 
            {
                if( cat.rentItems.get(i).getProname().equals ( list.getSelectedValue() ) )
                {
                    area.setText(cat.rentItems.get(i).toString());

                    String pathimage = "Images/" + cat.rentItems.get(i).getProname() + ".jpg";

                    label.setIcon(new ImageIcon(pathimage));

                    flag=true;
                }

                i++;
            }
        }

        li = list.getSelectedIndex();
        li2 = list2.getSelectedIndex();
        li3 = list3.getSelectedIndex();
    }

    public void mouseExited(MouseEvent event){}
    public void mouseEntered(MouseEvent event){}
    public void mouseReleased(MouseEvent event){}
    public void mousePressed(MouseEvent event){}


    public void actionPerformed(ActionEvent e) 
    {
        if  (e.getSource() == button1) {
            cat.items.get(list.getSelectedIndex()).RentItem();
        }

        else if  (e.getSource() == button2) {
            cat.items.get(list2.getSelectedIndex()).RentItem();
        }

        else if (e.getSource() == button3) 
        {
            boolean flag=false;
            int i = list3.getSelectedIndex();

            if (i != -1) 
            {

                while(i<cat.items.size() && flag==false) //Find the product in items via renting name
                {
                    if( cat.items.get(i).getProname().equals( cat.rentItems.get(i).getProname() ) )
                    {
                        cat.items.get(i).setRentnum( cat.items.get(i).getRentnum() + 1 );
                        flag=true;
                    }

                    i++;
                }

                ListModel3.remove(i);
                cat.rentItems.remove(i);
            }
        }

    }



    public void RentShop(String type, Catalogs cat, DefaultListModel ListModel) //Function for renting each product
    {
        for(Products product : cat.items)
        {   
                if ( product.getType().equals(type) ) 
                    ListModel.addElement( product.getProname() );           
        }
    }


    private void run() {
        //First window for importing

        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        frame = new JFrame("Importing...");

        frame.setLayout(new FlowLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton gfbutton = new JButton("Select File for Games and Films");
        JButton rbutton = new JButton("Select File for Rents");

        gfbutton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                JFileChooser fi = new JFileChooser();
                int returnValue = fi.showOpenDialog(null);

                if (returnValue == fi.APPROVE_OPTION) {
                   Items = fi.getSelectedFile().getPath();
                }

                if(over==true) frame.dispose();
                over = true;
            }

        });

        rbutton.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent ae) 
            {
                JFileChooser fi = new JFileChooser();
                int returnValue = fi.showOpenDialog(null);

                if (returnValue == fi.APPROVE_OPTION) {
                    RentsList = fi.getSelectedFile().getPath();
////////////////////??????????
                }

                if(over==true) 
                {
                    frame.dispose();
                    MainPro();
                }
                over = true;
            }
        });
    }


    //--------------------------------------------------Main program

    public static void main(String args[]) 
    {   
        new MainApp().run();
    }


    /**
      * I have no idea what you're doing here but this should also not be static
      */
    private void MainPro(){

        frame = new JFrame("Video Club"); //?

        frame.setBounds(500,300,400,500);
        frame.add(gfbutton);
        frame.add(rbutton);
        frame.pack();
        frame.setVisible(true);


        L_File lf = new L_File(cat,"Items.txt", "RentsList.txt"); //Importing
        lf.loadFile();


        //Main window, 1st tab

        JTabbedPane tabbedPane = new JTabbedPane();

        JPanel panel1 = new JPanel();

        tabbedPane.addTab("Movies",null,panel1,"Movies");

        JList list = new JList();


        list.addMouseListener(this);
        panel1.add(list);

        JTextArea area = new JTextArea("Details");
        panel1.add(area,BorderLayout.SOUTH);
        ListModel = new DefaultListModel();


        setBounds(300, 300, 350, 150);


        Container cp = getContentPane();
        cp.setLayout(new BorderLayout());


        panel1.setLayout(new FlowLayout());

        button1= new JButton("Rent");
        button1.addActionListener(this);

        panel1.add(button1);

        area.setFont(new Font("Serif", Font.ITALIC, 18));
        area.setForeground(Color.BLUE);
        area.setEditable(false);

        cp.add(panel1, BorderLayout.LINE_START);


        // A JList presents the user with a group of items (DefaultListModel)

        list = new JList(ListModel);
        list.setSelectedIndex(0);

        // A JScrollPane provides a scrollable view of a component

        JScrollPane listScroller = new JScrollPane(list);
        listScroller.setPreferredSize(new Dimension(150, 100));
        cp.add(listScroller, BorderLayout.CENTER);


        label = new JLabel();
        //label.setIcon(new ImageIcon(products.get(0).getImagePath()));
        cp.add(label, BorderLayout.LINE_END);

        pack();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        RentShop("Film",cat,ListModel);



        //2nd tab

        JPanel panel2 = new JPanel();

        tabbedPane.addTab("Games",null,panel2,"Games");

        JList list2 = new JList();


        list2.addMouseListener(this);
        panel2.add(list2,BorderLayout.SOUTH);

        JTextArea area2 = new JTextArea("Details");
        panel2.add(area2);
        DefaultListModel ListModel2 = new DefaultListModel();


        setBounds(300, 300, 350, 150);


        Container cp2 = getContentPane();
        cp2.setLayout(new BorderLayout());


        panel2.setLayout(new FlowLayout());

        button2= new JButton("Rent");

        panel2.add(button2);
        button2.addActionListener(this);


        area2.setFont(new Font("Serif", Font.ITALIC, 18));
        area2.setForeground(Color.BLUE);
        area2.setEditable(false);


        cp2.add(panel2, BorderLayout.LINE_START);


        // A JList presents the user with a group of items (DefaultListModel)

        list2 = new JList(ListModel);
        list2.setSelectedIndex(0);

        // A JScrollPane provides a scrollable view of a component

        JScrollPane listScroller2 = new JScrollPane(list);
        listScroller2.setPreferredSize(new Dimension(150, 100));
        cp2.add(listScroller2, BorderLayout.CENTER);


        label2 = new JLabel();
        //label2.setIcon(new ImageIcon(products.get(0).getImagePath()));
        cp2.add(label2, BorderLayout.LINE_END);


        pack();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        RentShop("Game",cat,ListModel2);


    //3rd tab

        JPanel panel3 = new JPanel();

        tabbedPane.addTab("Rents",null,panel3,"Rents");

        JList list3 = new JList();


        list3.addMouseListener(this);
        panel3.add(list3,BorderLayout.SOUTH);

        JTextArea area3 = new JTextArea("Details");
        panel3.add(area3);
        DefaultListModel ListModel3 = new DefaultListModel();

        setBounds(300, 300, 350, 150);

        Container cp3 = getContentPane();
        cp3.setLayout(new BorderLayout());


        panel3.setLayout(new FlowLayout());

        button3= new JButton("Remove Rent");


        panel3.add(button3);
        button3.addActionListener(this);

        area3.setFont(new Font("Serif", Font.ITALIC, 18));
        area3.setForeground(Color.BLUE);
        area3.setEditable(false);


        cp3.add(panel3, BorderLayout.LINE_START);


        // A JList presents the user with a group of items (DefaultListModel)

        list3 = new JList(ListModel2);
        list3.setSelectedIndex(0);

        // A JScrollPane provides a scrollable view of a component

        JScrollPane listScroller3 = new JScrollPane(list);
        listScroller3.setPreferredSize(new Dimension(150, 100));
        cp3.add(listScroller3, BorderLayout.CENTER);

        pack();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



        //After designing:

        for(Rents rent : cat.rentItems)
        {    
            ListModel3.addElement( rent.getProname() );         
        }


        JOptionPane.showMessageDialog(null,"Total Cost","The total renting cost is " + cat.CalculateTotalCost() + " drachmes",JOptionPane.PLAIN_MESSAGE); 

        add(tabbedPane);


    }

}
导入java.awt.FlowLayout;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.io.File;
导入javax.swing.JButton;
导入javax.swing.JDialog;
导入javax.swing.JFileChooser;
导入javax.swing.JFrame;
导入java.awt.BorderLayout;
导入javax.swing.DefaultListModel;
导入javax.swing.JTabbedPane;
导入javax.swing.JLabel;
导入javax.swing.JPanel;
导入javax.swing.JButton;
导入javax.swing.JList;
导入java.awt.*;
导入javax.swing.*;
导入java.awt.event.*;
导入java.util.*;
公共类MainApp扩展JFrame实现ActionListener、MouseStener
{
私有字符串ans;
私人互联网2;
私有布尔覆盖;
private int li=-1;
私有整数li2=-1;
私有整数li3=-1;
私有JFrame;
私人按钮1;
私人按钮2;
私人按钮3;
私人按钮;
私人JButton rbutton;
私人标签;
私人JLabel标签2;
私人JLabel标签3;
私人住宅区;
私人住宅区第2区;
私人住宅区第3区;
私人名单;
私人名单2;
私人名单3;
私有默认列表模型列表模型;
私有DefaultListModel ListModel2;
私有DefaultListModel ListModel3;
公共静态目录cat=新目录();
公共静态字符串项;
公共静态字符串出租列表;
公共无效列表(JTextArea区域、JLabel标签、JList列表)//用于游戏和电影
{
布尔标志=假;
int i=0;
while(i0)
cat.rentItems.add(cat.items.get(i.RentItem());
其他的
JOptionPane.showMessageDialog(空,“对不起…”,“没有可用副本了”,JOptionPane.INFORMATION\u消息);
}
公共void mouseClicked(MouseEvent事件)
{
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

import java.awt.BorderLayout;
import javax.swing.DefaultListModel;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JList;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

import java.util.*;


public class MainApp extends JFrame implements ActionListener, MouseListener
{

    private String ans;
    private int ans2;
    private boolean over;

    private int li=-1;
    private int li2=-1;
    private int li3=-1;

    private JFrame frame;

    private JButton button1;
    private JButton button2;
    private JButton button3;

    private JButton gfbutton;
    private JButton rbutton;

    private JLabel label;
    private JLabel label2;
    private JLabel label3;

    private JTextArea area;
    private JTextArea area2;
    private JTextArea area3;

    private JList list;
    private JList list2;
    private JList list3;

    private DefaultListModel ListModel;
    private DefaultListModel ListModel2;
    private DefaultListModel ListModel3;

    public static Catalogs cat = new Catalogs();
    public static String Items;
    public static String RentsList;



    public void lists(JTextArea area, JLabel label, JList list) //For games and films
    {
        boolean flag=false;
        int i=0;

        while(i<cat.items.size() && flag==false)
        {
            if( cat.items.get(i).getProname().equals ( list.getSelectedValue() ) )
            {
                area.setText(cat.items.get(i).toString());

                String pathimage = "Images/" + cat.items.get(i).getProname() + ".jpg";

                label.setIcon(new ImageIcon(pathimage));

                flag=true;
            }

            i++;
        }

        if(cat.items.get(i).getRentnum()>0)
            cat.rentItems.add(cat.items.get(i).RentItem());     
         else   
            JOptionPane.showMessageDialog(null,"Sorry...","There are no available copies left",JOptionPane.INFORMATION_MESSAGE); 
    }




    public void mouseClicked(MouseEvent event)
    {                       

        if (list.getSelectedIndex() != li) 
        {
            lists(area, label, list);
        }

        else if (list2.getSelectedIndex() != li2) 
        {
            lists(area2, label2, list2);
        }

        else if (list3.getSelectedIndex() != li3) 
        {
            boolean flag=false;
            int i=0;

            while(i<cat.rentItems.size() && flag==false) 
            {
                if( cat.rentItems.get(i).getProname().equals ( list.getSelectedValue() ) )
                {
                    area.setText(cat.rentItems.get(i).toString());

                    String pathimage = "Images/" + cat.rentItems.get(i).getProname() + ".jpg";

                    label.setIcon(new ImageIcon(pathimage));

                    flag=true;
                }

                i++;
            }
        }

        li = list.getSelectedIndex();
        li2 = list2.getSelectedIndex();
        li3 = list3.getSelectedIndex();
    }

    public void mouseExited(MouseEvent event){}
    public void mouseEntered(MouseEvent event){}
    public void mouseReleased(MouseEvent event){}
    public void mousePressed(MouseEvent event){}


    public void actionPerformed(ActionEvent e) 
    {
        if  (e.getSource() == button1) {
            cat.items.get(list.getSelectedIndex()).RentItem();
        }

        else if  (e.getSource() == button2) {
            cat.items.get(list2.getSelectedIndex()).RentItem();
        }

        else if (e.getSource() == button3) 
        {
            boolean flag=false;
            int i = list3.getSelectedIndex();

            if (i != -1) 
            {

                while(i<cat.items.size() && flag==false) //Find the product in items via renting name
                {
                    if( cat.items.get(i).getProname().equals( cat.rentItems.get(i).getProname() ) )
                    {
                        cat.items.get(i).setRentnum( cat.items.get(i).getRentnum() + 1 );
                        flag=true;
                    }

                    i++;
                }

                ListModel3.remove(i);
                cat.rentItems.remove(i);
            }
        }

    }



    public void RentShop(String type, Catalogs cat, DefaultListModel ListModel) //Function for renting each product
    {
        for(Products product : cat.items)
        {   
                if ( product.getType().equals(type) ) 
                    ListModel.addElement( product.getProname() );           
        }
    }


    private void run() {
        //First window for importing

        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        frame = new JFrame("Importing...");

        frame.setLayout(new FlowLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton gfbutton = new JButton("Select File for Games and Films");
        JButton rbutton = new JButton("Select File for Rents");

        gfbutton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                JFileChooser fi = new JFileChooser();
                int returnValue = fi.showOpenDialog(null);

                if (returnValue == fi.APPROVE_OPTION) {
                   Items = fi.getSelectedFile().getPath();
                }

                if(over==true) frame.dispose();
                over = true;
            }

        });

        rbutton.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent ae) 
            {
                JFileChooser fi = new JFileChooser();
                int returnValue = fi.showOpenDialog(null);

                if (returnValue == fi.APPROVE_OPTION) {
                    RentsList = fi.getSelectedFile().getPath();
////////////////////??????????
                }

                if(over==true) 
                {
                    frame.dispose();
                    MainPro();
                }
                over = true;
            }
        });
    }


    //--------------------------------------------------Main program

    public static void main(String args[]) 
    {   
        new MainApp().run();
    }


    /**
      * I have no idea what you're doing here but this should also not be static
      */
    private void MainPro(){

        frame = new JFrame("Video Club"); //?

        frame.setBounds(500,300,400,500);
        frame.add(gfbutton);
        frame.add(rbutton);
        frame.pack();
        frame.setVisible(true);


        L_File lf = new L_File(cat,"Items.txt", "RentsList.txt"); //Importing
        lf.loadFile();


        //Main window, 1st tab

        JTabbedPane tabbedPane = new JTabbedPane();

        JPanel panel1 = new JPanel();

        tabbedPane.addTab("Movies",null,panel1,"Movies");

        JList list = new JList();


        list.addMouseListener(this);
        panel1.add(list);

        JTextArea area = new JTextArea("Details");
        panel1.add(area,BorderLayout.SOUTH);
        ListModel = new DefaultListModel();


        setBounds(300, 300, 350, 150);


        Container cp = getContentPane();
        cp.setLayout(new BorderLayout());


        panel1.setLayout(new FlowLayout());

        button1= new JButton("Rent");
        button1.addActionListener(this);

        panel1.add(button1);

        area.setFont(new Font("Serif", Font.ITALIC, 18));
        area.setForeground(Color.BLUE);
        area.setEditable(false);

        cp.add(panel1, BorderLayout.LINE_START);


        // A JList presents the user with a group of items (DefaultListModel)

        list = new JList(ListModel);
        list.setSelectedIndex(0);

        // A JScrollPane provides a scrollable view of a component

        JScrollPane listScroller = new JScrollPane(list);
        listScroller.setPreferredSize(new Dimension(150, 100));
        cp.add(listScroller, BorderLayout.CENTER);


        label = new JLabel();
        //label.setIcon(new ImageIcon(products.get(0).getImagePath()));
        cp.add(label, BorderLayout.LINE_END);

        pack();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        RentShop("Film",cat,ListModel);



        //2nd tab

        JPanel panel2 = new JPanel();

        tabbedPane.addTab("Games",null,panel2,"Games");

        JList list2 = new JList();


        list2.addMouseListener(this);
        panel2.add(list2,BorderLayout.SOUTH);

        JTextArea area2 = new JTextArea("Details");
        panel2.add(area2);
        DefaultListModel ListModel2 = new DefaultListModel();


        setBounds(300, 300, 350, 150);


        Container cp2 = getContentPane();
        cp2.setLayout(new BorderLayout());


        panel2.setLayout(new FlowLayout());

        button2= new JButton("Rent");

        panel2.add(button2);
        button2.addActionListener(this);


        area2.setFont(new Font("Serif", Font.ITALIC, 18));
        area2.setForeground(Color.BLUE);
        area2.setEditable(false);


        cp2.add(panel2, BorderLayout.LINE_START);


        // A JList presents the user with a group of items (DefaultListModel)

        list2 = new JList(ListModel);
        list2.setSelectedIndex(0);

        // A JScrollPane provides a scrollable view of a component

        JScrollPane listScroller2 = new JScrollPane(list);
        listScroller2.setPreferredSize(new Dimension(150, 100));
        cp2.add(listScroller2, BorderLayout.CENTER);


        label2 = new JLabel();
        //label2.setIcon(new ImageIcon(products.get(0).getImagePath()));
        cp2.add(label2, BorderLayout.LINE_END);


        pack();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        RentShop("Game",cat,ListModel2);


    //3rd tab

        JPanel panel3 = new JPanel();

        tabbedPane.addTab("Rents",null,panel3,"Rents");

        JList list3 = new JList();


        list3.addMouseListener(this);
        panel3.add(list3,BorderLayout.SOUTH);

        JTextArea area3 = new JTextArea("Details");
        panel3.add(area3);
        DefaultListModel ListModel3 = new DefaultListModel();

        setBounds(300, 300, 350, 150);

        Container cp3 = getContentPane();
        cp3.setLayout(new BorderLayout());


        panel3.setLayout(new FlowLayout());

        button3= new JButton("Remove Rent");


        panel3.add(button3);
        button3.addActionListener(this);

        area3.setFont(new Font("Serif", Font.ITALIC, 18));
        area3.setForeground(Color.BLUE);
        area3.setEditable(false);


        cp3.add(panel3, BorderLayout.LINE_START);


        // A JList presents the user with a group of items (DefaultListModel)

        list3 = new JList(ListModel2);
        list3.setSelectedIndex(0);

        // A JScrollPane provides a scrollable view of a component

        JScrollPane listScroller3 = new JScrollPane(list);
        listScroller3.setPreferredSize(new Dimension(150, 100));
        cp3.add(listScroller3, BorderLayout.CENTER);

        pack();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



        //After designing:

        for(Rents rent : cat.rentItems)
        {    
            ListModel3.addElement( rent.getProname() );         
        }


        JOptionPane.showMessageDialog(null,"Total Cost","The total renting cost is " + cat.CalculateTotalCost() + " drachmes",JOptionPane.PLAIN_MESSAGE); 

        add(tabbedPane);


    }

}