Bad Credit Mortgages | Myspace Images | Proxy | Cell Phones | Internet Advertising
Java programming [Archive] - PCMech Forums

PDA

View Full Version : Java programming


nikerw
03-04-2003, 10:23 PM
Disclaimer: Im in a java programming class in college and the professor doesnt do very good at explaining things, so dont be suprised if you see me posting quite a few questions on the boards.

OK, my first question. I am making a multiplication table using nested for statements and MVC architecture, not really because it is the only way to do it, but because it is required for the class that we do it this way. Anyways, I made my multiplication table, but when I am displaying it the spaces get all messed up. Is there a tab command for java, and will it line up the numbers in vertical rows. To see what I am talking about I have attached my jar file. Thank you very much.

aym
03-06-2003, 06:12 AM
Hi,
I did some modifications to your files:
1)When you override JComponent.paintConponent(Graphics), make sure that you call the super function in the first line of the new function's body.

super.paintComponent(g);

2)Instead of using JFrame.setSize(int, int),I recommend using JComponent.setPreferredSize(int, int), or in your case, when subclassing JComponent, override JComponent.getPreferredSize()
3)To make sure that the program exits after closing the frame, use:

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

4)After creating the frame, call JFrame.pack()
5)You missed String[] parameter of function main in class StartUp.

Now, your program works, but it only displays headers, I didn't touch the model class, try to do it yourself, and if you have problems, just post!

nikerw
03-06-2003, 11:25 PM
I have it all figured out now, thank you very much, I made some stupid mistakes, and finally figured out the spacing. I also figured out why you probly couldnt see anything but the header. If another window gets infront of the display frame, and your things you painted on there wern't in the paintcomponent method then it doesnt repaint them. hmmm....java....fun language.....
Thanks a lot.

aym
03-08-2003, 08:51 AM
This happens because the window needs to repaint itself after reactivating, this isn't only in Java, it happens in MFC too.