my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Teacher said This is not a correct code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Teacher said This is not a correct code" Watch "Teacher said This is not a correct code" New topic
Author

Teacher said This is not a correct code

Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

the assignment was to make a JFrame then three sliders one textarea the move slider and change the color of textfield accordingly.
my code is..


OCPJP 6 86%
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39049
    
  23
No, I wouldn’t call it correct either.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39049
    
  23
Listeners not connected to the component they are listening.
Three static fields.
Three declarations on the same line.
Dreadful use of = inside ().
Having those components as fields rather than local variables.
[] after the identifier name. Any why do you want an array in the first place?
Using null layout.

And there is bound to be more.
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Campbell Ritchie wrote:Listeners not connected to the component they are listening.
Three static fields.
Three declarations on the same line.
Dreadful use of = inside ().
Having those components as fields rather than local variables.
[] after the identifier name. Any why do you want an array in the first place?
Using null layout.

And there is bound to be more.


Thanks sherrif, but the program running absolutely fine.
Then why ??
write more about why not static variables here, i am using only one object here then that should be correct ??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

"running fine" is an extremely poor metric to measure the quality of code. Crappy code can "run fine". Are you satisfied with crappy code?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39049
    
  23
Static members do not belong to objects, but to the class. And those fields have poor names. Bear was being kind calling your code crappy.
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Thanks Sherrif.
Thanks Marshal.
Actually this code is written by one of my Class-met. i told him that it is not a correct way to write a program, BUT i don't know why he always reply that the output is fine, so my program is correct.
i told him that your program is dependent only on one object , and when dependent word comes into programming unnecessarily then either you are not writing that code in java or you are not a java programmer.
But again his reply is same as before.
at last i had to post his code here on the same way he posted his code on our class' google group.
But No his reply is same as before.
At last i told him that he is a IMMUTABLE OBJECT and no method one can change the values in you.
if you like to say somthing to him then please open this link....
Google Group
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> if you like to say somthing to him then
> please open this link....

why? ...

so he can write better code for you to
submit as you own?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

If you indeed tried to submit your classmate's code as your own, then you're following the wrong path. You won't learn anything that way, and if you want to be a developer it will only hurt you in the long run.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Rob Spoor wrote:If you indeed tried to submit your classmate's code as your own, then you're following the wrong path. You won't learn anything that way, and if you want to be a developer it will only hurt you in the long run.


Rob Sir, I am totally agree with you. But i have submitted my own assignment 2 days before him.And these was no such mistake as in my class-met's assignment.
He submitted assignment after me .it is open for all means if someone submits his/her assignment so all other can see his/her assignment and if there is any mistake then anyone can tell him that there is a mistake in his/her assignment.So, i examined the code and caught the same mistake caught by sherrif.i told him but he denied. thats why i posted his code here for cnfirmation that if i am correct or not. and i am correct.
i requested here to the genius' that if they like then they can post the on my class' group too.
this was the whole story.
Am i wrong Sir ??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Wait, I think I'm missing something.

You first said that it was your code ("my code is.."). Then you said that a classmate wrote it. That made Michael and me think that you let your classmate write the code for you. Are you now saying that you wrote and submitted your own code that you have not posted here? Then why did you say "my code" in the first place?
 
GeeCON Prague 2014
 
subject: Teacher said This is not a correct code