Computer Science Canada [source] Credit Limit w/ AWT GUI, neat code tricks used |
Author: | the_short1 [ Thu Apr 13, 2006 10:37 am ] |
Post subject: | [source] Credit Limit w/ AWT GUI, neat code tricks used |
Hey fellow compsciers, after a long vacation from compsci, I'm BACK! That is, now that I got the time (robotics season with FIRST is over) Anyways, the purpose of this class assignment was to calculate the balance of a users creditcard, based on the purchases made, starting balance, and see if you went over limit. Being in gr12, we were told to do it with GUI, and I thought I would share it since I used some fun tricks to manipulate the data. Please dont plagiarise, youll get caught by your teacher!!! <<students>> Tell me what you think? any glitches (besides if you entered letters instead of numbers)? Comments? -Kevin |
Author: | wtd [ Thu Apr 13, 2006 1:03 pm ] | ||||
Post subject: | |||||
If I may ask... why not use Swing? I'm pretty sure even RTP should support it. As for your actual UI: I would highly suggest you use layout managers. They'll seem harder, but they'll make your life easier. Ask the Win32 people, for instance. They have no layout managers. When exposed to one they act like they've seen a miracle. I would also suggest you use labels. I would suggest you create ActionListeners for each widget that needs one, rather than a single implementation that then has to differentiate between the different widgets. You'll want to understand anonymous inner classes for this. Oh, and this:
and this:
Makes a pretty good case for using an array. The fact that all of these variables are static... what do you think that means when more than one instance of the class CreditLimit (window) is instantiated? A hint: it isn't pretty. Also... I would get get rid of the "X" button, and let the window's close button do its job. You've made a lot of common mistakes, but the fact that you're trying is good. Now, make it better. |
Author: | the_short1 [ Mon Apr 24, 2006 10:45 am ] |
Post subject: | .. |
Thanks for the suggestions wtd, thanks to you, I took it upon myself to learn how to do arrays of objects, so in the game that im currently creating, i used an array of buttons and indeed it makes code neater Also i used a grid layout to make it easier, although for that credit limit assignment, i chose to make my own layout on purpose, i like having full control over the placement of my widgets. "I would suggest you create ActionListeners for each widget that needs one" .. how would one go about doing that? our teacher is busy helping the gr11s so us gr12s have to learn GUI by ourselves :S Swing/AWT both have their strongpoints, ill use swing if i cant do it with awt, but i prefer awt over swing for my own reasons yea .. i didnt know how to use WindowListener at the time, but i do now.. and smacking myself in the forehead for using an noobish close button.. lol -kevin |
Author: | wtd [ Mon Apr 24, 2006 11:26 am ] | ||||
Post subject: | |||||
Let's say you have a button in a window... Java:
Scala (just because I like Scala):
|