Jump to content

  • Log In with Google      Sign In   
  • Create Account


properly formating the text from the image (need help)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Enerjak   Members   -  Reputation: 226

Like
0Likes
Like

Posted 07 November 2012 - 02:45 PM

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.

Sponsor:

#2 ppgamedev   Members   -  Reputation: 311

Like
1Likes
Like

Posted 07 November 2012 - 03:56 PM

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.

Edited by ppgamedev, 07 November 2012 - 03:58 PM.


#3 Enerjak   Members   -  Reputation: 226

Like
0Likes
Like

Posted 07 November 2012 - 04:11 PM

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

#4 ppgamedev   Members   -  Reputation: 311

Like
1Likes
Like

Posted 07 November 2012 - 04:26 PM

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

#5 Enerjak   Members   -  Reputation: 226

Like
0Likes
Like

Posted 07 November 2012 - 04:56 PM

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?

#6 ppgamedev   Members   -  Reputation: 311

Like
1Likes
Like

Posted 07 November 2012 - 05:06 PM

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

#7 Enerjak   Members   -  Reputation: 226

Like
0Likes
Like

Posted 07 November 2012 - 06:14 PM

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


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

#8 Enerjak   Members   -  Reputation: 226

Like
0Likes
Like

Posted 07 November 2012 - 06:30 PM

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

#9 ppgamedev   Members   -  Reputation: 311

Like
0Likes
Like

Posted 07 November 2012 - 07:13 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS