HI,
I am having some trouble with my assignment. I have created the gui and i am now writing the event handling. My problem is with the arrays. I have 3 seperate arrays all the same length.1 is a string and the other two are ints. in each array the positions each hold data that relate to the same object, ie the string [1] is beans, with the int [1] is the barcode for the beans and the other array[1] holds the price for the beans. I want to be able to show all 3 pieces of info in a textfield when the item is selected from a jcombobox.
Any help would be grateful. I will post my code in case you need to see it. Peace to all.
Glenn

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Observer;  //new
import java.util.Observable;//new
import javax.swing.BorderFactory; 
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
 
public class MySuperMktPro {
    
    public MySuperMktPro() {
        CheckoutView Check1 = new CheckoutView(1,0,0);
        CheckoutView Check2 = new CheckoutView(2,300,0);
        CheckoutView Check3 = new CheckoutView(3,600,0);
        CheckoutView Check4 = new CheckoutView(4,0,350);
        CheckoutView Check5 = new CheckoutView(5,600,350);
        OfficeView off111 = new OfficeView();
    }
    
    public static void main(String[] args) {
        System.out.println("Starting My Supermarket Project...");
        MySuperMktPro startup = new MySuperMktPro();
    }
}
 
class CheckoutView implements ItemListener , ActionListener {
    
    private OfficeView off1;
    private JFrame chk1;
    private Container cont1;
    private Dimension screensize,tempDim;
    private JPanel pan1,pan2,pan3,pan4,pan5;
    private JButton buyBut,prodCode;
    private JButton purchase,cashBack,manual,remove,disCo;
    private JButton but1,but2,finaLi1,but4,but5,but6;
    private JTextArea tArea1,tArea2;
    private JTextField tf1,tf2,tf3,list2;
    private JComboBox prodList;
    private JLabel lab1,lab2,lab3,lab4,lab5,lab6,lab7;
    private int checkoutID; //New private int for all methods of this class
    private int passedX,passedY;
    private String prods[];
    private JButton rb1,rb2,rb3,rb4;
    private double price[]; // not used
    private int code[];
 
    public CheckoutView(int passedInteger, int passedX, int passedY) {
        checkoutID = passedInteger; //Store the int passed into the method
        this.passedX = passedX;
        this.passedY = passedY;
        drawCheckoutGui();
    }
    
    public void drawCheckoutGui() {
        prods= new String[]{"Beans", "Eggs", "bread", "Jam", "Butter", 
                "Cream", "Sugar", "Peas", "Milk", "Bacon", "Spaghetti", 
                "Corn Flakes", "Carrots", "Oranges", "Bananas", "Snickers", 
                "Wine", "Beer", "Lager", "Cheese"};
        
        code = new int [20];
        for(int b = 0; b < code.length; b++) {
            code[b] = b+1;
        }
        
        price = new double[]{0.65, 0.84, 0.98, 0.75, 0.45, 0.65, 
                1.78, 1.14, 0.98, 0.99, 0.98, 0.65, 1.69, 2.99, 
                0.99, 2.68, 0.89, 5.99, .54, 2.99};
        
        screensize = Toolkit.getDefaultToolkit().getScreenSize();
        chk1 = new JFrame();
        chk1.setTitle("Checkout #" + checkoutID); //Use the new stored int
        chk1.setSize(300,350);
        chk1.setLocation(passedX,passedY);
        chk1.setLayout(new GridLayout(5,1));
        //chk1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        cont1 = chk1.getContentPane();
        //chk1.setLayout(new BorderLayout());
        
        pan1 = new JPanel();
        pan2 = new JPanel();
        pan3 = new JPanel();
        pan4 = new JPanel();
        pan5 = new JPanel();
        
        //panel 1
        pan1.setLayout(new FlowLayout());
        pan1.setBackground(Color.black);        
        prodList = new JComboBox(prods);
        prodList.setMaximumRowCount(2);
        prodList.addItemListener(this);
        but1 = new JButton("Buy");
        but1.addActionListener(this);
        lab1 = new JLabel("Products");
        lab1.setForeground(Color.white);
        lab1.setBorder(BorderFactory.createLineBorder(Color.white));
        pan1.add(lab1);
        pan1.add(prodList);     
        pan1.add(but1);
        
        //panel 2
        pan2 = new JPanel();
        pan2.setLayout(new BorderLayout());
        pan2.setBackground(Color.black);
        lab3 = new JLabel("                                Enter Product Code");
        lab3.setForeground(Color.white);
        tArea2 = new JTextArea(8,10);
        tArea2.setBorder(BorderFactory.createLineBorder(Color.white));
        lab5 = new JLabel("  Tesco's   ");
        lab5.setForeground(Color.white);
        lab5.setBorder(BorderFactory.createLineBorder(Color.white));
        lab6 = new JLabel("Checkout");
        lab6.setForeground(Color.white);
        lab6.setBorder(BorderFactory.createLineBorder(Color.white));
        lab7 = new JLabel("You  selected                      ");
        lab7.setForeground(Color.cyan);
        //lab7.setBorder(BorderFactory.createLineBorder(Color.white));
        pan2.add(lab7,"North");
        pan2.add(lab6,"East");
        pan2.add(tArea2,"Center");
        pan2.add(lab5,"West");
        pan2.add(lab3,"South");
        
        // panel 3
        pan3 = new JPanel();
        pan3.setLayout(new FlowLayout());
        pan3.setBackground(Color.black);
        manual = new JButton("Manual");
        manual.addActionListener(this);
        manual.setBorder(BorderFactory.createLineBorder(Color.white));
        remove = new JButton("Remove");
        remove.addActionListener(this);
        remove.setBorder(BorderFactory.createLineBorder(Color.white));
        tf1 = new JTextField(5);
        pan3.add(manual);
        pan3.add(tf1);
        pan3.add(remove);
        
        // panel 4
        pan4 = new JPanel();
        pan4.setLayout(new FlowLayout());
        pan4.setBackground(Color.black);
        finaLi1 = new JButton("Finalise");
        // finaLi1.addActionListener(this);
        cashBack = new JButton("Cashback");
        JTextField list2 = new JTextField(5);
        but4 = new JButton(" Sum Total");
        but4.addActionListener(this);
        but4.setBorder(BorderFactory.createLineBorder(Color.white));
        cashBack.setBorder(BorderFactory.createLineBorder(Color.white));
        pan4.add(cashBack);
        pan4.add(list2);
        pan4.add(but4);
        
        // panel 5 
        pan5 = new JPanel();
        pan5.setLayout(new GridLayout(2,3));
        pan5.setBackground(Color.black);
        disCo = new JButton("Discount");
        disCo.addActionListener(this);
        disCo.setBorder(BorderFactory.createLineBorder(Color.black));
        but6 = new JButton("Finalise");
        but6.addActionListener(this);
        but6.setBorder(BorderFactory.createLineBorder(Color.black));
        rb1 = new JButton("Cash");
        rb1.addActionListener(this);
        rb1.setBorder(BorderFactory.createLineBorder(Color.black));
        rb2 = new JButton("Card");
        rb2.addActionListener(this);
        rb2.setBorder(BorderFactory.createLineBorder(Color.black));
        rb3 = new JButton("Cheque");
        rb3.addActionListener(this);
        rb3.setBorder(BorderFactory.createLineBorder(Color.black));
        rb4 = new JButton("Voucher");
        rb4.addActionListener(this);
        rb4.setBorder(BorderFactory.createLineBorder(Color.black));
        pan5.add(disCo);
        pan5.add(but6);
        pan5.add(rb1);
        pan5.add(rb2);
        pan5.add(rb3);
        pan5.add(rb4);
        //add the panels to the container       
        cont1.add(pan1);
        cont1.add(pan4);    
        cont1.add(pan2);
        cont1.add(pan3);        
        cont1.add(pan5);        
        chk1.setContentPane(cont1);
        chk1.setVisible(true);      
    }
    
    public void itemStateChanged(ItemEvent e) {
        Object item = e.getItem();
        System.out.println("Selected item: "+item);
    }
    
    public void actionPerformed(ActionEvent e) {
        Object source = e.getActionCommand();
        System.out.println("Action performed from: "+source);
    }   
}
class OfficeView {
    
    private OfficeView off111;
    private JFrame offMod1;
    private JPanel pane1;
    private JButton refill;
    private Container cont11;
    private Dimension screensize;
    private JTextField tf11,tf12;
        
    public OfficeView() {
        drawOfficeGUI();
    }
    
    public void drawOfficeGUI() {
        screensize = Toolkit.getDefaultToolkit().getScreenSize();
        offMod1 = new JFrame("Office Control");
        int frameWidth = 300;
        int frameHeight = 250;
        offMod1.setSize(frameWidth,frameHeight);
        offMod1.setLocation(300,350);
        offMod1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        cont11 = offMod1.getContentPane();
        pane1 = new JPanel();
        pane1.setBackground(Color.cyan);
        refill = new JButton("Refill");
        tf11 = new JTextField(25);
        tf12 = new JTextField(25);
        pane1.add(tf11);
        pane1.add(refill);
        pane1.add(tf12);
        cont11.add(pane1);
        offMod1.setContentPane(cont11);
        offMod1.setVisible(true);         
    }

1) First thing , why are you using itemStateChanged ....??
Every time you select a item, value of 2 items will be changed. The last item selected and the newly selected item.

2) You can use same actionPerformed method for taht function. Where you want to display the values of other arrays ? I mean price and code .

I modified your code for only Check1 and displayed the item selected , code of selected item and price in the tArea2. Run it and you can do the same to display it anywhere else.

package com.gaurav;
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Observer; //new
import java.util.Observable;//new
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
 
public class MySuperMktPro {
 
public MySuperMktPro() {
CheckoutView Check1 = new CheckoutView(1, 0, 0);
 OfficeView off111 = new OfficeView();
}
 
public static void main(String[] args) {
System.out.println("Starting My Supermarket Project...");
MySuperMktPro startup = new MySuperMktPro();
}
}
 
class CheckoutView implements ActionListener {
 
private OfficeView off1;
 
private JFrame chk1;
 
private Container cont1;
 
private Dimension screensize, tempDim;
 
private JPanel pan1, pan2, pan3, pan4, pan5;
 
private JButton buyBut, prodCode;
 
private JButton purchase, cashBack, manual, remove, disCo;
 
private JButton but1, but2, finaLi1, but4, but5, but6;
 
private JTextArea tArea1, tArea2;
 
private JTextField tf1, tf2, tf3, list2;
 
private JComboBox prodList;
 
private JLabel lab1, lab2, lab3, lab4, lab5, lab6, lab7;
 
private int checkoutID; // New private int for all methods of this class
 
private int passedX, passedY;
 
private String[] prods;
 
private JButton rb1, rb2, rb3, rb4;
 
private double[] price; // not used
 
private int[] code;
 
public CheckoutView(int passedInteger, int passedX, int passedY) {
checkoutID = passedInteger; // Store the int passed into the method
this.passedX = passedX;
this.passedY = passedY;
drawCheckoutGui();
}
 
public void drawCheckoutGui() {
prods = new String[] { "Beans", "Eggs", "bread", "Jam", "Butter",
"Cream", "Sugar", "Peas", "Milk", "Bacon", "Spaghetti",
"Corn Flakes", "Carrots", "Oranges", "Bananas", "Snickers",
"Wine", "Beer", "Lager", "Cheese" };
 
code = new int[20];
for (int b = 0; b < code.length; b++) {
code[b] = b + 1;
}
 
price = new double[] { 0.65, 0.84, 0.98, 0.75, 0.45, 0.65, 1.78, 1.14,
0.98, 0.99, 0.98, 0.65, 1.69, 2.99, 0.99, 2.68, 0.89, 5.99,
.54, 2.99 };
 
screensize = Toolkit.getDefaultToolkit().getScreenSize();
chk1 = new JFrame();
chk1.setTitle("Checkout #" + checkoutID); // Use the new stored int
chk1.setSize(300, 350);
chk1.setLocation(passedX, passedY);
chk1.setLayout(new GridLayout(5, 1));
// chk1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cont1 = chk1.getContentPane();
// chk1.setLayout(new BorderLayout());
 
pan1 = new JPanel();
pan2 = new JPanel();
pan3 = new JPanel();
pan4 = new JPanel();
pan5 = new JPanel();
 
// panel 1
pan1.setLayout(new FlowLayout());
pan1.setBackground(Color.black);
prodList = new JComboBox(prods);
prodList.setMaximumRowCount(2);
prodList.addActionListener(this);
but1 = new JButton("Buy");
but1.addActionListener(this);
lab1 = new JLabel("Products");
lab1.setForeground(Color.white);
lab1.setBorder(BorderFactory.createLineBorder(Color.white));
pan1.add(lab1);
pan1.add(prodList);
pan1.add(but1);
 
// panel 2
pan2 = new JPanel();
pan2.setLayout(new BorderLayout());
pan2.setBackground(Color.black);
lab3 = new JLabel(" Enter Product Code");
lab3.setForeground(Color.white);
tArea2 = new JTextArea(8, 10);
tArea2.setBorder(BorderFactory.createLineBorder(Color.white));
lab5 = new JLabel(" Tesco's ");
lab5.setForeground(Color.white);
lab5.setBorder(BorderFactory.createLineBorder(Color.white));
lab6 = new JLabel("Checkout");
lab6.setForeground(Color.white);
lab6.setBorder(BorderFactory.createLineBorder(Color.white));
lab7 = new JLabel("You selected ");
lab7.setForeground(Color.cyan);
// lab7.setBorder(BorderFactory.createLineBorder(Color.white));
pan2.add(lab7, "North");
pan2.add(lab6, "East");
pan2.add(tArea2, "Center");
pan2.add(lab5, "West");
pan2.add(lab3, "South");
 
// panel 3
pan3 = new JPanel();
pan3.setLayout(new FlowLayout());
pan3.setBackground(Color.black);
manual = new JButton("Manual");
manual.addActionListener(this);
manual.setBorder(BorderFactory.createLineBorder(Color.white));
remove = new JButton("Remove");
remove.addActionListener(this);
remove.setBorder(BorderFactory.createLineBorder(Color.white));
tf1 = new JTextField(5);
pan3.add(manual);
pan3.add(tf1);
pan3.add(remove);
 
// panel 4
pan4 = new JPanel();
pan4.setLayout(new FlowLayout());
pan4.setBackground(Color.black);
finaLi1 = new JButton("Finalise");
// finaLi1.addActionListener(this);
cashBack = new JButton("Cashback");
JTextField list2 = new JTextField(5);
but4 = new JButton(" Sum Total");
but4.addActionListener(this);
but4.setBorder(BorderFactory.createLineBorder(Color.white));
cashBack.setBorder(BorderFactory.createLineBorder(Color.white));
pan4.add(cashBack);
pan4.add(list2);
pan4.add(but4);
 
// panel 5
pan5 = new JPanel();
pan5.setLayout(new GridLayout(2, 3));
pan5.setBackground(Color.black);
disCo = new JButton("Discount");
disCo.addActionListener(this);
disCo.setBorder(BorderFactory.createLineBorder(Color.black));
but6 = new JButton("Finalise");
but6.addActionListener(this);
but6.setBorder(BorderFactory.createLineBorder(Color.black));
rb1 = new JButton("Cash");
rb1.addActionListener(this);
rb1.setBorder(BorderFactory.createLineBorder(Color.black));
rb2 = new JButton("Card");
rb2.addActionListener(this);
rb2.setBorder(BorderFactory.createLineBorder(Color.black));
rb3 = new JButton("Cheque");
rb3.addActionListener(this);
rb3.setBorder(BorderFactory.createLineBorder(Color.black));
rb4 = new JButton("Voucher");
rb4.addActionListener(this);
rb4.setBorder(BorderFactory.createLineBorder(Color.black));
pan5.add(disCo);
pan5.add(but6);
pan5.add(rb1);
pan5.add(rb2);
pan5.add(rb3);
pan5.add(rb4);
// add the panels to the container
cont1.add(pan1);
cont1.add(pan4);
cont1.add(pan2);
cont1.add(pan3);
cont1.add(pan5);
chk1.setContentPane(cont1);
chk1.setVisible(true);
}
 
public void actionPerformed(ActionEvent e) {
int index = prodList.getSelectedIndex();
tArea2.setText(prods[index] + " ; Code is " + code[index]
+ " ; Price is " + price[index]);
Object source = e.getActionCommand();
System.out.println("Action performed from: " + source);
}
}
 
class OfficeView {
 
private OfficeView off111;
 
private JFrame offMod1;
 
private JPanel pane1;
 
private JButton refill;
 
private Container cont11;
 
private Dimension screensize;
 
private JTextField tf11, tf12;
 
public OfficeView() {
drawOfficeGUI();
}
 
public void drawOfficeGUI() {
screensize = Toolkit.getDefaultToolkit().getScreenSize();
offMod1 = new JFrame("Office Control");
int frameWidth = 300;
int frameHeight = 250;
offMod1.setSize(frameWidth, frameHeight);
offMod1.setLocation(300, 350);
offMod1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cont11 = offMod1.getContentPane();
pane1 = new JPanel();
pane1.setBackground(Color.cyan);
refill = new JButton("Refill");
tf11 = new JTextField(25);
tf12 = new JTextField(25);
pane1.add(tf11);
pane1.add(refill);
pane1.add(tf12);
cont11.add(pane1);
offMod1.setContentPane(cont11);
offMod1.setVisible(true);
}
}

Hi,
I didn't know i could use Action performed to get the selection from a list, despite hours of searching through sun's tutorials.
I have cut and pasted the code you posted for me and when i tested it, it does not work. I will continue to look at your example to see if i can work out why this is so.
Regards
Glenn
Edit: I have now got it to display the code index and the product in the text area. Thankyou.

Post your error stack trace so we can help you out . it should work. Jus now i tested it and it's working.

Hi
I have managed to make it work now so that it displays the elements of the array as intended.
I am now trying to work out how to stop the text area being cleared when a further selection is made from the combobox. My intention is for the selections to be stored and then when the finalise button is clicked i get a total. I am looking into how to do it now in the tutorials. any pointers would be great.
Thanks for your help
Regards
glenn

If you don't want to clear the text box then don't define the setText code in your actionPerformed method. Jus store the index value of the item in that method. Define a new method for setting the text by passing the index as argument to it.

Define counter as global variable with initial value 0;

Now in actionPerformed you can do like this.

public void actionPerformed(ActionEvent e) {
int index = prodList.getSelectedIndex();
if(counter==0)
{
setTextMethod(index);
counter =1;
}
if(counter==1)
{
Object source = e.getActionCommand();
System.out.println("Action performed from: " + source);
if (source.toString() == "Finalise") {
setTextMethod(index);
}
}
}

in setTextMethod you can do like this

public void setTextMethod(int index)
{
tArea2.setText(prods[index] + " ; Code is " + code[index]
+ " ; Price is " + price[index]);
}

Sorry for the late reply but i have been in lectures all day.
thanks for the help my friend, i will study the code now and post an update.
Kindest regards
glenn

I have now got he program to act as i wanted in respect of putting the price and product where i require and also putting the product barcode where i want. am now wanting to to create a total which will add up all the products that have been selected and display in the tArea2 textarea. I am unsure how to go about this, i obviously need to create the variable total and then create an algorithm. Any advice on how to do this would be most grateful.

My Code so far is.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Observer;  //new
import java.util.Observable;//new
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
public class MySuperMktPro {
public MySuperMktPro() {
CheckoutView Check1 = new CheckoutView(1,0,0);
CheckoutView Check2 = new CheckoutView(2,300,0);
CheckoutView Check3 = new CheckoutView(3,600,0);
CheckoutView Check4 = new CheckoutView(4,0,350);
CheckoutView Check5 = new CheckoutView(5,600,350);
OfficeView off111 = new OfficeView();
}
public static void main(String[] args) {
System.out.println("Starting My Supermarket Project...");
MySuperMktPro startup = new MySuperMktPro();
}
}
class CheckoutView implements  ActionListener {
private OfficeView off1;
private JFrame chk1;
private Container cont1;
private Dimension screensize,tempDim;
private JPanel pan1,pan2,pan3,pan4,pan5;
private JButton buyBut,prodCode;
private JButton purchase,cashBack,manual,remove,disCo;
private JButton but1,but2,finaLi1,but4,but5,but6;
private JTextArea tArea1,tArea2;
private JTextField tf1,tf2,tf3,list2;
private JComboBox prodList;
private JLabel lab1,lab2,lab3,lab4,lab5,lab6,lab7;
private int checkoutID; //New private int for all methods of this class
private int passedX,passedY,counter;
private String prods[];
private JButton rb1,rb2,rb3,rb4;
private double price[]; // not used
private int code[];
public CheckoutView(int passedInteger, int passedX, int passedY) {
checkoutID = passedInteger; //Store the int passed into the method
this.passedX = passedX;
this.passedY = passedY;
drawCheckoutGui();
}
public void drawCheckoutGui() {
prods= new String[]{"Products","Beans", "Eggs", "bread", "Jam", "Butter",
"Cream", "Sugar", "Peas", "Milk", "Bacon", "Spaghetti",
"Corn Flakes", "Carrots", "Oranges", "Bananas", "Snickers",
"Wine", "Beer", "Lager", "Cheese"};
code = new int [21];
for(int b = 0; b < code.length; b++) {
code = b+1;
}
price = new double[]{0.0,0.65, 0.84, 0.98, 0.75, 0.45, 0.65,
1.78, 1.14, 0.98, 0.99, 0.98, 0.65, 1.69, 2.99,
0.99, 2.68, 0.89, 5.99, .54, 2.99};
screensize = Toolkit.getDefaultToolkit().getScreenSize();
chk1 = new JFrame();
chk1.setTitle("Checkout #" + checkoutID); //Use the new stored int
chk1.setSize(300,350);
chk1.setLocation(passedX,passedY);
chk1.setLayout(new GridLayout(5,1));
//chk1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cont1 = chk1.getContentPane();
//chk1.setLayout(new BorderLayout());
pan1 = new JPanel();
pan2 = new JPanel();
pan3 = new JPanel();
pan4 = new JPanel();
pan5 = new JPanel();
//panel 1
pan1.setLayout(new FlowLayout());
pan1.setBackground(Color.black);
prodList = new JComboBox(prods);
prodList.setMaximumRowCount(2);
prodList.addActionListener(this);
but1 = new JButton("Buy");
but1.addActionListener(this);
lab1 = new JLabel("Products");
lab1.setForeground(Color.white);
lab1.setBorder(BorderFactory.createLineBorder(Color.white));
pan1.add(lab1);
pan1.add(prodList);
pan1.add(but1);
//panel 2
pan2 = new JPanel();
pan2.setLayout(new BorderLayout());
pan2.setBackground(Color.black);
lab3 = new JLabel("                                Enter Product Code");
lab3.setForeground(Color.white);
tArea2 = new JTextArea(8,10);
tArea2.setBorder(BorderFactory.createLineBorder(Color.white));
tArea2.setEditable(false);
lab5 = new JLabel("  Tesco's   ");
lab5.setForeground(Color.white);
lab5.setBorder(BorderFactory.createLineBorder(Color.white));
lab6 = new JLabel("Checkout");
lab6.setForeground(Color.white);
lab6.setBorder(BorderFactory.createLineBorder(Color.white));
lab7 = new JLabel("Your preferred payment method is     ");
lab7.setForeground(Color.cyan);
//lab7.setBorder(BorderFactory.createLineBorder(Color.white));
pan2.add(lab7,"North");
pan2.add(lab6,"East");
pan2.add(tArea2,"Center");
pan2.add(lab5,"West");
pan2.add(lab3,"South");
// panel 3
pan3 = new JPanel();
pan3.setLayout(new FlowLayout());
pan3.setBackground(Color.black);
manual = new JButton("Manual");
manual.addActionListener(this);
manual.setBorder(BorderFactory.createLineBorder(Color.white));
remove = new JButton("Remove");
remove.addActionListener(this);
remove.setBorder(BorderFactory.createLineBorder(Color.white));
tf1 = new JTextField(5);
pan3.add(manual);
pan3.add(tf1);
pan3.add(remove);
// panel 4
pan4 = new JPanel();
pan4.setLayout(new FlowLayout());
pan4.setBackground(Color.black);
finaLi1 = new JButton("Finalise");
// finaLi1.addActionListener(this);
cashBack = new JButton("Cashback");
JTextField list2 = new JTextField(5);
but4 = new JButton(" Sum Total");
but4.addActionListener(this);
but4.setBorder(BorderFactory.createLineBorder(Color.white));
cashBack.setBorder(BorderFactory.createLineBorder(Color.white));
pan4.add(cashBack);
pan4.add(list2);
pan4.add(but4);
// panel 5
pan5 = new JPanel();
pan5.setLayout(new GridLayout(2,3));
pan5.setBackground(Color.black);
disCo = new JButton("Discount");
disCo.addActionListener(this);
disCo.setBorder(BorderFactory.createLineBorder(Color.black));
but6 = new JButton("Finalise");
but6.addActionListener(this);
but6.setBorder(BorderFactory.createLineBorder(Color.black));
rb1 = new JButton("Cash");
rb1.addActionListener(this);
rb1.setBorder(BorderFactory.createLineBorder(Color.black));
rb2 = new JButton("Card");
rb2.addActionListener(this);
rb2.setBorder(BorderFactory.createLineBorder(Color.black));
rb3 = new JButton("Cheque");
rb3.addActionListener(this);
rb3.setBorder(BorderFactory.createLineBorder(Color.black));
rb4 = new JButton("Voucher");
rb4.addActionListener(this);
rb4.setBorder(BorderFactory.createLineBorder(Color.black));
pan5.add(disCo);
pan5.add(but6);
pan5.add(rb1);
pan5.add(rb2);
pan5.add(rb3);
pan5.add(rb4);
//add the panels to the container
cont1.add(pan1);
cont1.add(pan4);
cont1.add(pan2);
cont1.add(pan3);
cont1.add(pan5);
chk1.setContentPane(cont1);
chk1.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==rb1)
{
lab7.setText("                            Paying by cash");
}
if(e.getSource()==rb2)
{
lab7.setText("                            Paying by Card");
}
if(e.getSource()==rb3)
{
lab7.setText("                            Paying by Cheque");
}
if(e.getSource()==rb4)
{
lab7.setText("                            Paying by Voucher");
}
int index = prodList.getSelectedIndex();
if(counter==0)
{
setTextMethod(index);
counter =1;
}
if(counter==1)
{
Object source = e.getActionCommand();
System.out.println("Action performed from: " + source);
if (source.toString() == "Buy") {
setTextMethod(index);
}
}
}
public void setTextMethod(int index)
{
tArea2.setText(prods[index]
+ "  -----------------------  £" + price[index]);
tf1.setText(""+code[index]);
}
}
class OfficeView {
private OfficeView off111;
private JFrame offMod1;
private JPanel pane1;
private JButton refill;
private Container cont11;
private Dimension screensize;
private JTextField tf11,tf12;
public OfficeView() {
drawOfficeGUI();
}
public void drawOfficeGUI() {
screensize = Toolkit.getDefaultToolkit().getScreenSize();
offMod1 = new JFrame("Office Control");
int frameWidth = 300;
int frameHeight = 250;
offMod1.setSize(frameWidth,frameHeight);
offMod1.setLocation(300,350);
offMod1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cont11 = offMod1.getContentPane();
pane1 = new JPanel();
pane1.setBackground(Color.cyan);
refill = new JButton("Refill");
tf11 = new JTextField(25);
tf12 = new JTextField(25);
pane1.add(tf11);
pane1.add(refill);
pane1.add(tf12);
cont11.add(pane1);
offMod1.setContentPane(cont11);
offMod1.setVisible(true);
}
}

I just wanted to let you know that i worked it out for myself. Thanks to all that helped me out earlier in the thread.
Peace be with you all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.