The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Storing input in a multi-dimensional array?

Posted by confused on September 26, 2001 at 8:26 AM

I'm a newbie to Java and I have a question regarding a program I am writing as a part of an asignment. I need to create a GUI to accept some input in two text fields, click on an "accept button" which calls a method store() to save that input into an array. I am having troubles with this store method and storing the input into the array. Can someone help with the code for the store method as it is driving me *crazy*. Thanks in advance. A data structure the array is created in Shop.java and Sales.java is the main program. The store method is at the bottom.

//Shop.java
public class Shop{
String Code;
double Qty;
//public Shop(){
//}
public Shop(String code, double qty){
Code = code;
Qty = qty;
}
String getCode(){
return Code;
}
String getAll(){
return Code + " " + Qty;
}
}


//Sales.java

public class Sales extends JPanel implements ActionListener{
JButton acceptB, displayB, totalB, exitB;
JTextField Code, Qty;
Shop purchase[][];
String TempDate;
List display;
int counter1 = 0;
int counter2 = 0;
String tempCode = "";
double tempQty = 0;
String Exit = "00";

public Sales(){

purchase = new Shop[100][100];

add(new JLabel("Product Code : "));
Code = new JTextField(" ", 15);
add(Code);
add(new JLabel("Quantity : "));
Qty = new JTextField(" ", 15);
add(Qty);
acceptB = new JButton("Accept");
acceptB.addActionListener(this);
add(acceptB);
displayB = new JButton("Display");
displayB.addActionListener(this);
add(displayB);
totalB = new JButton("Total");
totalB.addActionListener(this);
add(totalB);
exitB = new JButton("Exit");
exitB.addActionListener(this);
add(exitB);
display = new List();
add(display);
}

public void actionPerformed(ActionEvent e){
String what = e.getActionCommand();
if(what == "Accept"){
tempCode = Code.getText().trim();
tempQty = convert(Qty.getText());
store();
}
if(what == "Display"){
displayItem();
}
if(what == "Total"){
End_List();
}
if(what == "Exit"){
System.exit(0);
}
}

public void store(){
try{

//Problem coding this method

}catch(Exception et){System.out.println("Help");}
}





Replies:
  • ? Chin Loong September 26, 2001 at 9:50 AM (4)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us