ladykh
asked on
Put text area contents into another text area depending on which item selected from combo box.
Please can anybody help?
I select items from a combobox menu which are written to a JTextArea (on customer order page). After selecting, I select from a further combox box of table names (array 0-5), and depending on which one selected, I need the information to go to one of 6 text areas (array0-5) on the table page.
I am totally stuck.
My code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class rms222 extends JApplet implements ActionListener{
//************************ *********
//MAIN PANEL VARIABLES
//Tabbed Pane
JTabbedPane tabs;
//Panels
JPanel pnlMain = new JPanel();
JPanel pnlOne = new JPanel(); //Welcome
JPanel pnlTwo = new JPanel(); //Customer Order
JPanel pnlThree = new JPanel(); //Tables
JPanel pnlFour = new JPanel(); //Manager
//************************ *********
//PANEL 1 VARIABLES (WELCOME)
//************************ *********
//PANEL 2 VARIABLES (CUSTOMER ORDER)
//5 Labels
JLabel lblTitle = new JLabel("Customer Orders");
JLabel lblStarter = new JLabel("Starter");
JLabel lblMain = new JLabel("Main Course");
JLabel lblDes = new JLabel("Dessert");
JLabel lblDrink = new JLabel("Drinks");
//4 Combo Boxes
JComboBox startCombo = new JComboBox();
JComboBox mainCombo = new JComboBox();
JComboBox desCombo = new JComboBox();
JComboBox drinkCombo = new JComboBox();
JComboBox tableCombo = new JComboBox();
//Panels for Customer Order Tab
JPanel pnlMenuTop = new JPanel();
JPanel pnlMenuBot = new JPanel();
JPanel pnlMenuLeft = new JPanel();
JPanel pnlMenuRight = new JPanel();
//Buttons Customer Order
Button btnClear = new Button("Reset Order");
Button btnRemove = new Button ("Remove Item");
Button btnEnter = new Button ("Enter");
Label spacer= new Label();
//Basket myBasket = new Basket();
CustomerOrder myCustomerOrder = new CustomerOrder();
//Area where customer order displayed
TextArea txtareaOrder = new TextArea(10,30);
//Arrays
String start_descriptions[]= new String[6];
double start_prices[]= new double[6];
String main_descriptions[]= new String[6];
double main_prices[]= new double[6];
String des_descriptions[]= new String[6];
double des_prices[]= new double[6];
String drink_descriptions[]= new String[6];
double drink_prices[]= new double[6];
String table_name[]= new String[6];
int tableindex;
boolean remv=false;
//************************ **********
//************************ *********
//PANEL 3 VARIABLES (TABLES)
JTextArea txtareaOrders[] = new JTextArea[6];
//************************ **********
public void init(){
JPanel pnlMain = new JPanel(); //Main Panel
tabs= new JTabbedPane();
//Dimension mySize =new Dimension(300,200);
Dimension mySize =new Dimension(178,100);
//this.setBackground(Color .yellow);
//************************ ********** ********** ********** ********** ********** ********** ********
//FIRST TAB - WELCOME
JPanel pnlOne = new JPanel();
pnlOne.setLayout(new BorderLayout());
pnlOne.setBackground(Color .blue);
JLabel lblOne = new JLabel("Restaurant System", JLabel.CENTER);
pnlOne.add(lblOne, BorderLayout.CENTER);
lblOne.setForeground(Color .white);
JLabel lblTwo = new JLabel("Please select the tabs at the top of the page to use the system", JLabel.CENTER);
pnlOne.add(lblTwo, BorderLayout.SOUTH);
lblTwo.setForeground(Color .white);
tabs.add("Welcome", pnlOne);//Add pnlOne to First Tab
//************************ ********** ********** ********** ********** ********** ********** ********
//SECOND TAB - CUSTOMER ORDER
//pnlTwo= new JPanel();
//pnlOrderBut = new JPanel();
//pnlOrderBut.setLayout(ne w GridLayout(4,1));
pnlTwo.setLayout(new BorderLayout());
pnlTwo.add(pnlMenuTop, BorderLayout.NORTH);
pnlTwo.add(pnlMenuBot, BorderLayout.CENTER);
pnlTwo.add(pnlMenuLeft, BorderLayout.EAST);
pnlTwo.add(pnlMenuRight, BorderLayout.SOUTH);
pnlMenuTop.setLayout(new GridLayout(0,4)); //As many rows as need and 4 coloumns
//Add objects to customer order
pnlMenuTop.add(lblStarter) ;
pnlMenuTop.add(lblMain);
pnlMenuTop.add(lblDes);
pnlMenuTop.add(lblDrink);
pnlMenuTop.add(startCombo) ;
pnlMenuTop.add(mainCombo);
pnlMenuTop.add(desCombo);
pnlMenuTop.add(drinkCombo) ;
pnlMenuBot.setBackground(C olor.cyan) ;
JLabel lblchoice = new JLabel("Customer Order Summary", JLabel.CENTER);
pnlMenuBot.add(lblchoice);
pnlMenuBot.add(txtareaOrde r);
pnlMenuBot.add(tableCombo) ;
pnlMenuRight.add(btnClear) ;
pnlMenuRight.add(spacer);
pnlMenuRight.add(btnRemove );
pnlMenuRight.add(spacer);
pnlMenuRight.add(btnEnter) ;
//Add Action Listener to buttons and combo boxes
startCombo.addActionListen er(this);
mainCombo.addActionListene r(this);
desCombo.addActionListener (this);
drinkCombo.addActionListen er(this);
tableCombo.addActionListen er(this);
btnClear.addActionListener (this);
btnRemove.addActionListene r(this);
btnEnter.addActionListener (this);
//Starter Arrays
for (int i=0;i<6;i++){
start_descriptions[i] = new String();
}//End for
start_descriptions[0]= "Prawn Cocktail";
start_descriptions[1]= "Chicken Pate";
start_descriptions[2]= "Tomato Soup";
start_descriptions[3]= "Melon";
start_descriptions[4]= "Smoked Mackeral";
start_descriptions[5]= "Garlic Bread";
start_prices[0]= 3.75;
start_prices[1]= 3.25;
start_prices[2]= 2.80;
start_prices[3]= 2.95;
start_prices[4]= 3.50;
start_prices[5]= 2.75;
for (int i=0;i<6;i++){
startCombo.addItem(start_d escription s[i]);
}//End for
//Main Course Arrays
for (int i=0;i<6;i++){
main_descriptions[i] = new String();
}//End for
main_descriptions[0]= "Roast Chicken";
main_descriptions[1]= "Scampi and Chips";
main_descriptions[2]= "Lemon Sole";
main_descriptions[3]= "Cheeseburger";
main_descriptions[4]= "Shepherds Pie";
main_descriptions[5]= "Gammon Steak";
main_prices[0]= 8.99;
main_prices[1]= 7.75;
main_prices[2]= 9.25;
main_prices[3]= 7.50;
main_prices[4]= 8.25;
main_prices[5]= 8.50;
for (int i=0;i<6;i++){
mainCombo.addItem(main_des criptions[ i]);
}//End for
//Dessert Arrays
for (int i=0;i<6;i++){
des_descriptions[i] = new String();
}//End for
des_descriptions[0]= "Vanilla Ice Cream";
des_descriptions[1]= "Chocolate Fudge Cake";
des_descriptions[2]= "Strawberry Meringue";
des_descriptions[3]= "Fruit Salad";
des_descriptions[4]= "Profiteroles";
des_descriptions[5]= "Apple Pie";
des_prices[0]= 2.99;
des_prices[1]= 3.20;
des_prices[2]= 3.25;
des_prices[3]= 2.99;
des_prices[4]= 3.20;
des_prices[5]= 3.10;
for (int i=0;i<6;i++){
desCombo.addItem(des_descr iptions[i] );
}//End for
//Drink Arrays
for (int i=0;i<6;i++){
drink_descriptions[i] = new String();
}//End for
drink_descriptions[0]= "Coca-Cola";
drink_descriptions[1]= "Mineral Water";
drink_descriptions[2]= "Lager";
drink_descriptions[3]= "White Wine";
drink_descriptions[4]= "Orange Juice";
drink_descriptions[5]= "Bacardi Breezer";
drink_prices[0]= 1.80;
drink_prices[1]= 1.20;
drink_prices[2]= 3.00;
drink_prices[3]= 3.50;
drink_prices[4]= 2.25;
drink_prices[5]= 2.90;
for (int i=0;i<6;i++){
drinkCombo.addItem(drink_d escription s[i]);
}//End for
//Table Arrays
for (int i=0;i<6;i++){
table_name[i] = new String();
}//End for
table_name[0]= "Table 1";
table_name[1]= "Table 2";
table_name[2]= "Table 3";
table_name[3]= "Table 4";
table_name[4]= "Table 5";
table_name[5]= "Table 6";
drink_prices[0]= 1.80;
drink_prices[1]= 1.20;
drink_prices[2]= 3.00;
drink_prices[3]= 3.50;
drink_prices[4]= 2.25;
drink_prices[5]= 2.90;
for (int i=0;i<6;i++){
tableCombo.addItem(table_n ame[i]);
//tableCombo[i].setActionC ommand("" + i);
}//End for
tabs.add("Customer Order",pnlTwo);//Add pnl2 to Second Tab
//************************ ********** ********** ********** ********** ********** ********** ********
//THIRD TAB - TABLES
JPanel pnlThree = new JPanel();
pnlThree.setLayout(new GridLayout(0,3,4,4));
JLabel lblTblOne = new JLabel("Table One");
pnlThree.add(lblTblOne);
JLabel lblTblTwo = new JLabel("Table Two");
pnlThree.add(lblTblTwo);
JLabel lblTblThree = new JLabel("Table Three");
pnlThree.add(lblTblThree);
JLabel lblTblFour = new JLabel("Table Four");
pnlThree.add(lblTblFour);
JLabel lblTblFive = new JLabel("Table Five");
pnlThree.add(lblTblFive);
JLabel lblTblSix = new JLabel("Table Six");
pnlThree.add(lblTblSix);
JTextArea txtareaOrders[] = new JTextArea[6];
for (int i=0;i<6;i++){
txtareaOrders[i]=new JTextArea(6,12);
pnlThree.add(txtareaOrders [i]);
}
tabs.add("Tables",pnlThree );//Add pnlThree to Third Tab
//************************ ********** ********** ********** ********** ********** ********** ****
//************************ ********** ********** ********** ********** ********** ********** ***
//FOURTH TAB - MANAGER
JPanel pnlFour = new JPanel();
JLabel lblFour = new JLabel("This is the kitchen label");
pnlFour.add(lblFour);
tabs.add("Manager",pnlFour );//Add pnlThree to Third Tab
//************************ ********** ********** ********** ********** ********** ********** ****
tabs.setBackground(Color.b lue); //Set color of tabs
lblOne.setFont(new Font("SansSerif",Font.BOLD ,24)); //Set font of first label on first tab
tabs.setPreferredSize(mySi ze);
pnlMain.setLayout(new GridLayout(0,1));
pnlMain.add(tabs); //Add tabs to panel
tabs.setFont(new Font("SansSerif",Font.BOLD ,16)); //Set font of tabs
setContentPane(pnlMain);// Put the JPanel on the JApplet
} // End init
public void actionPerformed(ActionEven t e){
//TAB 2 - CUSTOMER ORDER ************************** ********** ********** ******
//The get selected item picks words from the relevant combo box, adds to the
//string and puts in the text area on a new line each time.
if(e.getSource()==startCom bo){
int i= startCombo.getSelectedInde x();
OrderLine line = new OrderLine(i,start_descript ions[i],st art_prices [i]);
if(remv){myCustomerOrder.r emoveOrder Line(line) ;remv=fals e;
}else{
myCustomerOrder.addOrderLi ne(line);}
txtareaOrder.setForeground (Color.bla ck);
txtareaOrder.setText(myCus tomerOrder .showConte nts());
}//End if
if(e.getSource()==mainComb o){
int i= mainCombo.getSelectedIndex ();
OrderLine line = new OrderLine(i,main_descripti ons[i],mai n_prices[i ]);
if(remv){myCustomerOrder.r emoveOrder Line(line) ;remv=fals e;
}else{
myCustomerOrder.addOrderLi ne(line);}
txtareaOrder.setForeground (Color.bla ck);
txtareaOrder.setText(myCus tomerOrder .showConte nts());
}//End if
if(e.getSource()==desCombo ){
int i= desCombo.getSelectedIndex( );
OrderLine line = new OrderLine(i,des_descriptio ns[i],des_ prices[i]) ;
if(remv){myCustomerOrder.r emoveOrder Line(line) ;remv=fals e;
}else{
myCustomerOrder.addOrderLi ne(line);}
txtareaOrder.setForeground (Color.bla ck);
txtareaOrder.setText(myCus tomerOrder .showConte nts());
}//End if
if(e.getSource()==drinkCom bo){
int i= drinkCombo.getSelectedInde x();
OrderLine line = new OrderLine(i,drink_descript ions[i],dr ink_prices [i]);
if(remv){myCustomerOrder.r emoveOrder Line(line) ;remv=fals e;
}else{
myCustomerOrder.addOrderLi ne(line);}
txtareaOrder.setForeground (Color.bla ck);
txtareaOrder.setText(myCus tomerOrder .showConte nts());
}//End if
if(e.getSource()==btnClear ){
myCustomerOrder.clearIt();
txtareaOrder.setForeground (Color.red );
txtareaOrder.setText("Your basket is currently empty");
}//End if
if(e.getSource()==btnRemov e){remv=tr ue;}
}//End Action Performed
//************************ ********** ********** ********** ********** ********** *
} // End rms222
class OrderLine{
public int id;
public String description;
public double price;
public int quantity;
public OrderLine(int i,String des,double p){
this.id = i;
this.description = des;
this .price =p;
this.quantity = 1;
}
}//end OrderLinedef
class CustomerOrder{
ArrayList Order=new ArrayList();
public void clearIt(){Order.clear();}
public void addOrderLine(OrderLine line){
boolean there=false;
for(int j =0;j<Order.size();j++){
OrderLine read =(OrderLine)Order.get(j);
if(read.id == line.id){there=true; //Remove this line to prevent first line problem?
read.quantity++;//if it's there already update its quantity
}
}//end loop
if(!there){Order.add(line) ;}//otherw ise add
}//end addOrderLine
public void removeOrderLine(OrderLine line){
for(int j =0;j<Order.size();j++){
OrderLine read =(OrderLine)Order.get(j);
if(read.id == line.id)read.quantity--;
if(read.quantity<1){Order. remove(rea d);}
}
}//end removeOrderLine
public String showContents(){
String contents = new String();
double bill =0;
for(int j =0;j<Order.size();j++){
OrderLine read =(OrderLine)Order.get(j);
contents+=read.quantity+" "+read.description;
contents+="\n";
bill+=read.price*read.quan tity;
}
if(bill>0){contents+="\nTo tal cost = £"+bill;
return contents;
}else{
return "Your basket is currently empty" ;}
}//end showContents
}//end CustomerOrder
Please can anyone help?
Thanks
I select items from a combobox menu which are written to a JTextArea (on customer order page). After selecting, I select from a further combox box of table names (array 0-5), and depending on which one selected, I need the information to go to one of 6 text areas (array0-5) on the table page.
I am totally stuck.
My code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class rms222 extends JApplet implements ActionListener{
//************************
//MAIN PANEL VARIABLES
//Tabbed Pane
JTabbedPane tabs;
//Panels
JPanel pnlMain = new JPanel();
JPanel pnlOne = new JPanel(); //Welcome
JPanel pnlTwo = new JPanel(); //Customer Order
JPanel pnlThree = new JPanel(); //Tables
JPanel pnlFour = new JPanel(); //Manager
//************************
//PANEL 1 VARIABLES (WELCOME)
//************************
//PANEL 2 VARIABLES (CUSTOMER ORDER)
//5 Labels
JLabel lblTitle = new JLabel("Customer Orders");
JLabel lblStarter = new JLabel("Starter");
JLabel lblMain = new JLabel("Main Course");
JLabel lblDes = new JLabel("Dessert");
JLabel lblDrink = new JLabel("Drinks");
//4 Combo Boxes
JComboBox startCombo = new JComboBox();
JComboBox mainCombo = new JComboBox();
JComboBox desCombo = new JComboBox();
JComboBox drinkCombo = new JComboBox();
JComboBox tableCombo = new JComboBox();
//Panels for Customer Order Tab
JPanel pnlMenuTop = new JPanel();
JPanel pnlMenuBot = new JPanel();
JPanel pnlMenuLeft = new JPanel();
JPanel pnlMenuRight = new JPanel();
//Buttons Customer Order
Button btnClear = new Button("Reset Order");
Button btnRemove = new Button ("Remove Item");
Button btnEnter = new Button ("Enter");
Label spacer= new Label();
//Basket myBasket = new Basket();
CustomerOrder myCustomerOrder = new CustomerOrder();
//Area where customer order displayed
TextArea txtareaOrder = new TextArea(10,30);
//Arrays
String start_descriptions[]= new String[6];
double start_prices[]= new double[6];
String main_descriptions[]= new String[6];
double main_prices[]= new double[6];
String des_descriptions[]= new String[6];
double des_prices[]= new double[6];
String drink_descriptions[]= new String[6];
double drink_prices[]= new double[6];
String table_name[]= new String[6];
int tableindex;
boolean remv=false;
//************************
//************************
//PANEL 3 VARIABLES (TABLES)
JTextArea txtareaOrders[] = new JTextArea[6];
//************************
public void init(){
JPanel pnlMain = new JPanel(); //Main Panel
tabs= new JTabbedPane();
//Dimension mySize =new Dimension(300,200);
Dimension mySize =new Dimension(178,100);
//this.setBackground(Color
//************************
//FIRST TAB - WELCOME
JPanel pnlOne = new JPanel();
pnlOne.setLayout(new BorderLayout());
pnlOne.setBackground(Color
JLabel lblOne = new JLabel("Restaurant System", JLabel.CENTER);
pnlOne.add(lblOne, BorderLayout.CENTER);
lblOne.setForeground(Color
JLabel lblTwo = new JLabel("Please select the tabs at the top of the page to use the system", JLabel.CENTER);
pnlOne.add(lblTwo, BorderLayout.SOUTH);
lblTwo.setForeground(Color
tabs.add("Welcome", pnlOne);//Add pnlOne to First Tab
//************************
//SECOND TAB - CUSTOMER ORDER
//pnlTwo= new JPanel();
//pnlOrderBut = new JPanel();
//pnlOrderBut.setLayout(ne
pnlTwo.setLayout(new BorderLayout());
pnlTwo.add(pnlMenuTop, BorderLayout.NORTH);
pnlTwo.add(pnlMenuBot, BorderLayout.CENTER);
pnlTwo.add(pnlMenuLeft, BorderLayout.EAST);
pnlTwo.add(pnlMenuRight, BorderLayout.SOUTH);
pnlMenuTop.setLayout(new GridLayout(0,4)); //As many rows as need and 4 coloumns
//Add objects to customer order
pnlMenuTop.add(lblStarter)
pnlMenuTop.add(lblMain);
pnlMenuTop.add(lblDes);
pnlMenuTop.add(lblDrink);
pnlMenuTop.add(startCombo)
pnlMenuTop.add(mainCombo);
pnlMenuTop.add(desCombo);
pnlMenuTop.add(drinkCombo)
pnlMenuBot.setBackground(C
JLabel lblchoice = new JLabel("Customer Order Summary", JLabel.CENTER);
pnlMenuBot.add(lblchoice);
pnlMenuBot.add(txtareaOrde
pnlMenuBot.add(tableCombo)
pnlMenuRight.add(btnClear)
pnlMenuRight.add(spacer);
pnlMenuRight.add(btnRemove
pnlMenuRight.add(spacer);
pnlMenuRight.add(btnEnter)
//Add Action Listener to buttons and combo boxes
startCombo.addActionListen
mainCombo.addActionListene
desCombo.addActionListener
drinkCombo.addActionListen
tableCombo.addActionListen
btnClear.addActionListener
btnRemove.addActionListene
btnEnter.addActionListener
//Starter Arrays
for (int i=0;i<6;i++){
start_descriptions[i] = new String();
}//End for
start_descriptions[0]= "Prawn Cocktail";
start_descriptions[1]= "Chicken Pate";
start_descriptions[2]= "Tomato Soup";
start_descriptions[3]= "Melon";
start_descriptions[4]= "Smoked Mackeral";
start_descriptions[5]= "Garlic Bread";
start_prices[0]= 3.75;
start_prices[1]= 3.25;
start_prices[2]= 2.80;
start_prices[3]= 2.95;
start_prices[4]= 3.50;
start_prices[5]= 2.75;
for (int i=0;i<6;i++){
startCombo.addItem(start_d
}//End for
//Main Course Arrays
for (int i=0;i<6;i++){
main_descriptions[i] = new String();
}//End for
main_descriptions[0]= "Roast Chicken";
main_descriptions[1]= "Scampi and Chips";
main_descriptions[2]= "Lemon Sole";
main_descriptions[3]= "Cheeseburger";
main_descriptions[4]= "Shepherds Pie";
main_descriptions[5]= "Gammon Steak";
main_prices[0]= 8.99;
main_prices[1]= 7.75;
main_prices[2]= 9.25;
main_prices[3]= 7.50;
main_prices[4]= 8.25;
main_prices[5]= 8.50;
for (int i=0;i<6;i++){
mainCombo.addItem(main_des
}//End for
//Dessert Arrays
for (int i=0;i<6;i++){
des_descriptions[i] = new String();
}//End for
des_descriptions[0]= "Vanilla Ice Cream";
des_descriptions[1]= "Chocolate Fudge Cake";
des_descriptions[2]= "Strawberry Meringue";
des_descriptions[3]= "Fruit Salad";
des_descriptions[4]= "Profiteroles";
des_descriptions[5]= "Apple Pie";
des_prices[0]= 2.99;
des_prices[1]= 3.20;
des_prices[2]= 3.25;
des_prices[3]= 2.99;
des_prices[4]= 3.20;
des_prices[5]= 3.10;
for (int i=0;i<6;i++){
desCombo.addItem(des_descr
}//End for
//Drink Arrays
for (int i=0;i<6;i++){
drink_descriptions[i] = new String();
}//End for
drink_descriptions[0]= "Coca-Cola";
drink_descriptions[1]= "Mineral Water";
drink_descriptions[2]= "Lager";
drink_descriptions[3]= "White Wine";
drink_descriptions[4]= "Orange Juice";
drink_descriptions[5]= "Bacardi Breezer";
drink_prices[0]= 1.80;
drink_prices[1]= 1.20;
drink_prices[2]= 3.00;
drink_prices[3]= 3.50;
drink_prices[4]= 2.25;
drink_prices[5]= 2.90;
for (int i=0;i<6;i++){
drinkCombo.addItem(drink_d
}//End for
//Table Arrays
for (int i=0;i<6;i++){
table_name[i] = new String();
}//End for
table_name[0]= "Table 1";
table_name[1]= "Table 2";
table_name[2]= "Table 3";
table_name[3]= "Table 4";
table_name[4]= "Table 5";
table_name[5]= "Table 6";
drink_prices[0]= 1.80;
drink_prices[1]= 1.20;
drink_prices[2]= 3.00;
drink_prices[3]= 3.50;
drink_prices[4]= 2.25;
drink_prices[5]= 2.90;
for (int i=0;i<6;i++){
tableCombo.addItem(table_n
//tableCombo[i].setActionC
}//End for
tabs.add("Customer Order",pnlTwo);//Add pnl2 to Second Tab
//************************
//THIRD TAB - TABLES
JPanel pnlThree = new JPanel();
pnlThree.setLayout(new GridLayout(0,3,4,4));
JLabel lblTblOne = new JLabel("Table One");
pnlThree.add(lblTblOne);
JLabel lblTblTwo = new JLabel("Table Two");
pnlThree.add(lblTblTwo);
JLabel lblTblThree = new JLabel("Table Three");
pnlThree.add(lblTblThree);
JLabel lblTblFour = new JLabel("Table Four");
pnlThree.add(lblTblFour);
JLabel lblTblFive = new JLabel("Table Five");
pnlThree.add(lblTblFive);
JLabel lblTblSix = new JLabel("Table Six");
pnlThree.add(lblTblSix);
JTextArea txtareaOrders[] = new JTextArea[6];
for (int i=0;i<6;i++){
txtareaOrders[i]=new JTextArea(6,12);
pnlThree.add(txtareaOrders
}
tabs.add("Tables",pnlThree
//************************
//************************
//FOURTH TAB - MANAGER
JPanel pnlFour = new JPanel();
JLabel lblFour = new JLabel("This is the kitchen label");
pnlFour.add(lblFour);
tabs.add("Manager",pnlFour
//************************
tabs.setBackground(Color.b
lblOne.setFont(new Font("SansSerif",Font.BOLD
tabs.setPreferredSize(mySi
pnlMain.setLayout(new GridLayout(0,1));
pnlMain.add(tabs); //Add tabs to panel
tabs.setFont(new Font("SansSerif",Font.BOLD
setContentPane(pnlMain);//
} // End init
public void actionPerformed(ActionEven
//TAB 2 - CUSTOMER ORDER **************************
//The get selected item picks words from the relevant combo box, adds to the
//string and puts in the text area on a new line each time.
if(e.getSource()==startCom
int i= startCombo.getSelectedInde
OrderLine line = new OrderLine(i,start_descript
if(remv){myCustomerOrder.r
}else{
myCustomerOrder.addOrderLi
txtareaOrder.setForeground
txtareaOrder.setText(myCus
}//End if
if(e.getSource()==mainComb
int i= mainCombo.getSelectedIndex
OrderLine line = new OrderLine(i,main_descripti
if(remv){myCustomerOrder.r
}else{
myCustomerOrder.addOrderLi
txtareaOrder.setForeground
txtareaOrder.setText(myCus
}//End if
if(e.getSource()==desCombo
int i= desCombo.getSelectedIndex(
OrderLine line = new OrderLine(i,des_descriptio
if(remv){myCustomerOrder.r
}else{
myCustomerOrder.addOrderLi
txtareaOrder.setForeground
txtareaOrder.setText(myCus
}//End if
if(e.getSource()==drinkCom
int i= drinkCombo.getSelectedInde
OrderLine line = new OrderLine(i,drink_descript
if(remv){myCustomerOrder.r
}else{
myCustomerOrder.addOrderLi
txtareaOrder.setForeground
txtareaOrder.setText(myCus
}//End if
if(e.getSource()==btnClear
myCustomerOrder.clearIt();
txtareaOrder.setForeground
txtareaOrder.setText("Your
}//End if
if(e.getSource()==btnRemov
}//End Action Performed
//************************
} // End rms222
class OrderLine{
public int id;
public String description;
public double price;
public int quantity;
public OrderLine(int i,String des,double p){
this.id = i;
this.description = des;
this .price =p;
this.quantity = 1;
}
}//end OrderLinedef
class CustomerOrder{
ArrayList Order=new ArrayList();
public void clearIt(){Order.clear();}
public void addOrderLine(OrderLine line){
boolean there=false;
for(int j =0;j<Order.size();j++){
OrderLine read =(OrderLine)Order.get(j);
if(read.id == line.id){there=true; //Remove this line to prevent first line problem?
read.quantity++;//if it's there already update its quantity
}
}//end loop
if(!there){Order.add(line)
}//end addOrderLine
public void removeOrderLine(OrderLine line){
for(int j =0;j<Order.size();j++){
OrderLine read =(OrderLine)Order.get(j);
if(read.id == line.id)read.quantity--;
if(read.quantity<1){Order.
}
}//end removeOrderLine
public String showContents(){
String contents = new String();
double bill =0;
for(int j =0;j<Order.size();j++){
OrderLine read =(OrderLine)Order.get(j);
contents+=read.quantity+" "+read.description;
contents+="\n";
bill+=read.price*read.quan
}
if(bill>0){contents+="\nTo
return contents;
}else{
return "Your basket is currently empty" ;}
}//end showContents
}//end CustomerOrder
Please can anyone help?
Thanks
what exactly is your problem?
ASKER
I can't get the items in JTextArea on the customer page to go into one of the 6 text areas depending on which table name was selected from the combo box.
Why dod u need to get the items out of the text area, can u instead just determine what to go into the 6 ta's according to the cb states?
Remove the redefinition of txtareaOrders, your're defining it first at the class level, the again in init(), which shadows the class level variable.
Move all addActionListener() calls to the very end of init(). One of the draw backs with many of Swing components is that action events are fired as you're populating them with data. This causes a problem in your case.
Add the following to your actionPerformed() method:
if (e.getSource()==tableCombo ) {
txtareaOrders[tableCombo.g etSelected Index()].s etText(myC ustomerOrd er.showCon tents());
}
Move all addActionListener() calls to the very end of init(). One of the draw backs with many of Swing components is that action events are fired as you're populating them with data. This causes a problem in your case.
Add the following to your actionPerformed() method:
if (e.getSource()==tableCombo
txtareaOrders[tableCombo.g
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Javatm, that won't exactly help ladykh improve programming skills.
> Javatm, that won't exactly help ladykh improve programming skills.
Good catch there my friend, But I cant just answer and give all the answer because
we are not alowed to do that, thats why I just made som very few changes =-)
Good catch there my friend, But I cant just answer and give all the answer because
we are not alowed to do that, thats why I just made som very few changes =-)
ASKER
Thank you javatm, I do understand it much better now.
Sorry for late reply.
Thank you for your help.
Sorry for late reply.
Thank you for your help.