Skip to main content
GameDev.net gamedev.net
🔒 Locked

properly formating the text from the image (need help)

Started by Enerjak Nov 7, 2012 at 8:45 PM 7 replies 2.1k views
Original Post
Enerjak
Enerjak
http://puu.sh/1nA8n

As you can see from this image, the current print out of the hardware store is suppose to be like that but I got it like this:

http://puu.sh/1nA7i


here is the code that prints the hardware store.


public void printReport()
{
// get the hardware stock from the store.
HardwareStock stock = store.getStock();

int length = stock.listSize();

String message = " ";

HardwareItem item = null;

message ="itemID ItemName pOrdered pInstore pSold manuPrice selling Price \n";
if(store.getFileLoaded() || length > 0)
{
for(int index = 0; index < length; index++)
{
item = stock.elementAt(index);

message += String.format("%d %s %d %d %d %.2f %.2f%n", item.getItemID(), item.getItemName(), item.getNumOfPartsOrdered(),
item.getNumOfPartsLeft(), item.getNumOfPartsSold(), item.getManufactuaterPrice(), item.getStoreSellingPrice());

}
this.reportTA.setText(message);
}
}


please let me know if there's anything else you need.
ppgamedev
ppgamedev
Try setting a monospaced font.
Lucida Console, Courier New, etc... or just the default Font.MONOSPACED font.
Check the java.awt.GraphicsEnvironment and java.awt.Font javadocs for info on how to get a Font.

Other option (nicer) is to use a JTable.
Enerjak
Enerjak

Try setting a monospaced font.
Lucida Console, Courier New, etc... or just the default Font.MONOSPACED font.
Check the java.awt.GraphicsEnvironment and java.awt.Font javadocs for info on how to get a Font.

Other option (nicer) is to use a JTable.


a JTable sounds good now i need to see how to use it. TO GOOGLE
ppgamedev
ppgamedev
Sun created some very good tutorials on Java. They are still available from Oracle:
http://docs.oracle.com/javase/tutorial/index.html

And here is the specific part related to JTable:
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
Enerjak
Enerjak

Sun created some very good tutorials on Java. They are still available from Oracle:
http://docs.oracle.c...rial/index.html

And here is the specific part related to JTable:
http://docs.oracle.c...ents/table.html


Thanks, I actually just tried my self and got this:

http://puu.sh/1nD85

now naturally that's all the items from the list and. Here is what i did:


// print the report (if there's anything in it.)
public void printReport()
{
// get the hardware stock from the store.
HardwareStock stock = store.getStock();

int length = stock.listSize();

String message = " ";

double TotalValue = 0.0;
int totalStock = 0;
HardwareItem item = null;

String[] colunmNames =
{
"Item ID",
"Item Name",
"pOrdered",
"pInStock",
"pSold",
"Manufacturer Price",
"Store selling price"
};

Object[][] data = null;

if(store.getFileLoaded() || length > 0)
{
for(int index = 0; index < length; index++)
{
item = stock.elementAt(index);

Object[][] data2 =
{
{ item.getItemID(),
item.getItemName(),
item.getNumOfPartsOrdered(),
item.getNumOfPartsLeft(),
item.getNumOfPartsSold(),
item.getManufactuaterPrice(),
item.getStoreSellingPrice()
}
};

this.reportTable.setModel(new DefaultTableModel(data2, colunmNames));

}


}


}



the program has 8 entries in the list so far, but it only shows one, am I on th right track?
ppgamedev
ppgamedev
You're making the same mistake you made before with the combobox.
Do you remember?
Enerjak
Enerjak

You're making the same mistake you made before with the combobox.
Do you remember?


I think so.......hmmm, let me see.
Enerjak
Enerjak

You're making the same mistake you made before with the combobox.
Do you remember?


the moron strikes again!! but seriously i got it, thanks
ppgamedev
ppgamedev
First time the code was given to you.
Second time just a hint.
Well done!
I bet next time you'll solve it by yourself.
This is called "learning process" and you're doing it fine. Congratulations

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.