• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI - Save clients details to file, print, etc  RSS feed

 
Stefan eduard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy again. I hope someone can give me some help. I have the following file, GUI and I am required to make a program that accepts product details from user, then saves them in a file with the possibility to view them or print them.

I got the following program. I am sure i have some stuff wrong in it so if anyone able to help please. for the moment it accepts the data from user, it saves it, but instead of displaying it it just calculates it. thanks in advance




Screen3-Product-GUI-Copy.JPG
[Thumbnail for Screen3-Product-GUI-Copy.JPG]
Product GUI
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan eduard wrote: . . . I have the following file, GUI and I am required to make a program that accepts product details from user, then saves them in a file . . .
Welcome to the Ranch

I know you are going to hate me for this, but you are going around this all the wrong way. Start by forgetting about the existence of GUIs. Then forget about the existence of the float datatype. You can find out what you ought to use for money, and see examples of it working, here. Be sure to read all my posts there.
There are several ways you can write an object to a file. What you should be doing is to create an object with those 7 data as fields, and write it into a file. You do this from the command line, which should look like this
Enter code 123456
Enter name 13mm spanner
Enter sale price 2.99
Enter manf price 1.19
Enter manf date 28Oct2013
Enter warranty months 12
Enter description Spanner with ring and open ends, both 13mm size
You create a program whose API allows you to set all those 7 data and which has a write to file method. Then you get it to read from file and display those data: again you need to expose methods which allow you to read those data.
You test it and when you have got it working, then you can stick a GUI on top of it.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your code, which usually makes it looks better, but the long lines your IDE inserted make it very difficult to read. And I can't get the Ranch site to respond, so who knows what the post will look like
 
Stefan eduard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy again. I managed to make the GUI do something close to what I need. I will make red the pieces of code i need change.
After entering some data it gives me:
Product's code : 41231
Product's name : 23123.0 ------> I need the program to accept String or just Display the Name the User enters
Product's price : 12313.0
Manufacturing's Place: 12313.0 -----------> here i should accept only char and strings, location
Manufacturing's Date: 12.0 --------> Here it should be Date type
Warranty Period: 12312.0
Product Description: 313123.0

Product's code : 4123
Product's name : 12312.0
Product's price : 312.0
Manufacturing's Place: 312.0
Manufacturing's Date: 31231.0
Warranty Period: 3131.0
Product Description: 3131.0

The code ispart of it)
public class Products extends javax.swing.JFrame {

/**
* Creates new form Products
*/
float[] ProductCode=new float[5];
String[] ProductName=new String[5];
float[] ProductPrice=new float[5];
float[] ProductManufacturingPlace=new float[5];
float[] ProductManufacturingDate=new float[5];
float[] WarrantyPeriod=new float[5];
float[] ProductDescription=new float[5];
int i=0;
public Products() {
initComponents();
}

private void addActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
String s=pcode.getText();
String s1=Pname.getText();
String s2=Pprice.getText();
String s3=PrMnfP.getText();
String s4=PrMnfD.getText();
String s5=WrntP.getText();
String s6=PDescr.getText();
float x=Float.parseFloat(s);
float x2=Float.parseFloat(s2);
float x3=Float.parseFloat(s3);
float x4=Float.parseFloat(s4);
float x5=Float.parseFloat(s5);
float x6=Float.parseFloat(s6);
ProductCode[i]=x;
ProductName[i]=s1;
ProductPrice[i]=x2;
ProductManufacturingPlace[i]=x3;
ProductManufacturingDate[i]=x4;
WarrantyPeriod[i]=x5;
ProductDescription[i]=x6;
i++;
}
catch(ArrayIndexOutOfBoundsException e1)
{
output.setText("Only 5 numbers");
}
catch(NumberFormatException e2)
{
output.setText("There should be only numbers.");
}
pcode.setText("");
Pname.setText("");
Pprice.setText("");
PrMnfP.setText("");
PrMnfD.setText("");
WrntP.setText("");
PDescr.setText("");





 
Stefan eduard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The New GUI
screen4.JPG
[Thumbnail for screen4.JPG]
I have the GUI now under this form.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!