• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing quick question

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Sorry in the assignment I doing I was given the following criteria
"The user interface for this assignment must satisfy the following criteria:
It must be composed exclusively with components from the Java Foundation Classes (Swing components)"
Is it still possible to use the java.awt.* packages or can 1 only use the javax.swing.*; packages
Maybe confused by terminology here.
Thanks.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

If you only may use swing components, you can't use layouts, because they are all in the awt-package. In the ScjdFaq you'll find this question.

All components I used came from the swing package, but I used for example always the swing-alternative: javax.swing.JTextField
vs. java.awt.TextField, so always used JTextField. But for a GridBagLayout there isn't an alternative from the swing-package so used the awt one.

Kind regards,
Roel
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Mark!

Is it still possible to use the java.awt.* packages or can 1 only use the javax.swing.*; packages



It depends. If there are equivalent classes in the swing package, then you must use it (for instance, java.awt.Button and javax.swing.JButton). I used java.awt.event.ActionListener and didn't have problems with it!
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers, thanks for the responses. Just wished to get better understanding of terminology, that's great.!
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Sorry would appreciate people's opinion upon the following. Based upon question I posed, would one be expected to use the GroupLayout manager instead of the GridBagLayout manager, if they wished to use these types of layouts?
Thanks.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

From JDK 6 API specification:

GroupLayout is intended for use by builders, but may be hand-coded as well.


So it could show you used a GUI builder instead of doing it manually, which contradicts a requirement: only your own code should be used in this assignment (and no generated code).

But according to this thread it seems there is no problem using GroupLayout because it is a part of JDK6

Kind regards,
Roel

 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it still possible to use the GridbagLayout based upon my initial question seeing as it appears in the awt package? The reason I would prefer to use it is that it seems relatively simple to use if coding by hand compared to other layout managers.
Thanks.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I used GridBagLayout, FlowLayout and BorderLayout. So that's not a problem. I think Roberto Perillo's post contains an excellent rule for this problem:

It depends. If there are equivalent classes in the swing package, then you must use it (for instance, java.awt.Button and javax.swing.JButton).



Kind regards,
Roel
 
Greenhorn
Posts: 23
Android Scala VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:only your own code should be used in this assignment (and no generated code).



It never says that. the original wording is:

instructions.html wrote:but you must not submit any code that is not your own work



Generated code is never mentioned. And is here anybody who truly did not use generated code?

For example of I use eclipse then eclipse will create stubs for all abstract methods I need to implement. That function is a code generator as well.

You can continue from here. Simple editor macros to help with the layout manager, advanced editor macros, a editor plug-in, a GUI builder. No clear line between. Where does Sun draw the line?

I dare to argue that If I use the GUI builder myself then the result is my work. Well, here in the Forum. If I dare to argue the point with Sun or Prometric is a different matter.

Martin
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a big difference between generating some methods to implement and generating a complete GUI through some editor plug-in. And when I see a NullLayout, I know you didn't develop it yourself, because that's a layout manager a developer would hardly use (but which is frequently used by a gui building tool/plugin).
You have to develop a simple gui, nothing fancy, so I won't taking the risk of failure, but that's just my opinion.
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:

Roel De Nijs wrote:only your own code should be used in this assignment (and no generated code).



It never says that. the original wording is:

instructions.html wrote:but you must not submit any code that is not your own work



Generated code is never mentioned.



Champion, is "generated code" "your own work"? No, so it fits this rule. No generated code is allowed. If the assessor notice this, the candidate is automatically failed.
 
Martin Krischik
Greenhorn
Posts: 23
Android Scala VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roberto Perillo wrote:Champion, is "generated code" "your own work"?



Depends on which definition of work you are using. If you you use scientific definition:

wikipedia wrote:work is the amount of energy transferred by a force acting through a distance.



Then I would say it is my muscles who moved mouse and tapped the keyboard, so I did the work. Yes, generated code is my work when I handled the generator.

There may be other definitions, legal, copyright, empoyment etc. pp.

Roberto Perillo wrote:No generated code is allowed.



Code Re-factor? Introduce Variable, Constant, Method? Heck, "New class" won't open an empty file! Especially the "New class" in Eclipse is pretty powerful. It will generate constructors, main, implementations for all abstract methods.

This too is generated code. Hands up who did not use any of those features.

Roberto Perillo wrote:If the assessor notice this, the candidate is automatically failed.



Are you an assessor with inside knowledge? Because from the instructions I can't deduct this. For me my work is independed of the tool I use. And a GUI builder is just a tool. A speclialzed editor for specific types of code. Until I came here I interpreted the sentece in the way that I can't bundle org.desktop.GroupLayout with my work but which editor I use and how advanced or powerfull that editor might be is up to me. Including editors which use a graphical representation of my code. I also use UML round trip engeneering. Until I came here that is.

And I am not the only one. I read quite a few postings on the matter and all threads seem to start with a candidate coming to the forum with the same opinion that I had. And beeing freighted off.

Of course I too are freighted and won't take the risk on a highly ambiguous instruction. Just don't sell that sentence as absolute truth. It isn't. If it is true what you say then it is a trick question designed to make otherwise suitable candidates fail. Why else not just say “Code generators and GUI builder are not allowed!”.

Especially since both the SCJP and SCJD preparation courses use the netbeans GUI builder the as well and one of the SCJP questions stess the point that “writing GUI code by hand is cumbersome in production environments”.

Martin
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:Code Re-factor? Introduce Variable, Constant, Method? Heck, "New class" won't open an empty file! Especially the "New class" in Eclipse is pretty powerful. It will generate constructors, main, implementations for all abstract methods.

This too is generated code. Hands up who did not use any of those features.


While this is true, I think there's a sensible and easy distinction to make. Most of these features generate code exactly as a human would write it. They're just a short-cut. If I get Netbeans to create a bunch of accessors for me, there is absolutely no difference between what they generate and what I would generate if I type it all out by hand. And, importantly, they're unlikely to be doing anything I don't understand.

But your average GUI builder doesn't produce code in the style that a human would. It's usually very easy to tell if someone hand-coded it or not. And a GUI builder allows someone who doesn't understand Swing to produce a graphical interface. And that's what I think the rule is there for.

[If I really wanted to be awkward, I'd point out that technically using rmic to generate RMI stubs and skeletons breaks that particular rule, despite being a requirement if you're using RMI! ]
 
Martin Krischik
Greenhorn
Posts: 23
Android Scala VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matthew

Matthew Brown wrote:If I get Netbeans to create a bunch of accessors for me, there is absolutely no difference between what they generate and what I would generate if I type it all out by hand.



I am a great fan of property change events so a generated accessors won't do for me ;-).

Matthew Brown wrote:It's usually very easy to tell if someone hand-coded it or not.



Funny that you say. Being dissatisfied with GridBagLayout I went out to see how GroupLayout works. And I found the Sun tutorial which uses advocates same wacky chained method calls that NetBeans generates. If I follow that tutorial to the letter then there will be only two lines which distinguish my code from code being generated with Netbeans:



Makes me wonder. Should I not follow the lead of that tutorial - just in case? I don't want to auto-fail on blimey technicality.

Martin
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:Just don't sell that sentence as absolute truth. It isn't. If it is true what you say then it is a trick question designed to make otherwise suitable candidates fail. Why else not just say “Code generators and GUI builder are not allowed!”.


I give my own opinion (and I'm quiet certain Roberto just does the same). And we are not an assessor, certainly not one with inside knowledge. I don't sell anything for the absolute truth. It's nothing more than my interpretation of the instructions. So you don't have to agree at all.
And the reason why there is no rule like "GUI builder are not allowed" could be quiet easy: the instructions could simply be outdated and at the time it was created there were no gui builder tools/plugins. Just like the issue with the stubs who must be generated (according to the instructions), although since JDK 1.5 that's not necessary anymore. Many people passed already without generating these stubs (which I tell every time when someone asks about this must requirement).
Maybe you could use a generator for your GUI code and then we'll know if it is allowed or not. But at this moment it is my opinion you'll fail using a gui builder, so I advice against it.
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:Are you an assessor with inside knowledge?



It isn't necessary to be an assessor to notice something that is obvious.

Anyway, good luck with your choices.
 
Martin Krischik
Greenhorn
Posts: 23
Android Scala VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roberto Perillo wrote:It isn't necessary to be an assessor to notice something that is obvious.



Could you elaborate on that? I am not an native English speaker an I quite honestly fail to see obvious part. Remember the original wording is:

instructions.html wrote:You are permitted to use any IDE tool you choose, but you must not submit any code that is not your own work. The final program must have no dependencies on any libraries other than those of the Java 2 Platform.



In my understanding of the English language “any IDE tool you choose” would include any tool the IDE of my choice provides. As long as it does not introduce additional dependencies. And for me “not your own work” is not automaticly imply that I have to type the code one character at a time. But then I am not an native English speaker and if I missed s subtlety of the English language I am grateful to learn something new.

Until then I consider the instructions ambiguous and I appreciate the warning that using a GUI builder might get me into trouble and one should be better save the sorry.

Martin

PS: Did nobody ever try who2contact@sun.com to get an official stand? I guess we (including myself) are all cowards and far to afraid to fail to take any risks.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:Could you elaborate on that?



instructions.html wrote:You are permitted to use any IDE tool you choose, but you must not submit any code that is not your own work.


For me that's obvious and quiet easy (and I'm also not a native speaker): code generated by a gui builder is not my own, so I can't submit that. And my GUI code uses FlowLayout, GridBagLayout, BorderLayout,... I'm quiet sure a GUI builder will produce code that's completely different to mine.

Martin Krischik wrote:Did nobody ever try who2contact@sun.com to get an official stand?


First of all I guess this email address is not valid any more (since the acquisition by Oracle). Secondly they gave very little information and certainly not an official stand. I sent them an email asking if I could change Sun's interface just to add some javadoc to the methods. I didn't get any clear answer about that, so I didn't take any risk and kept Sun's interface as-is.

Kind regards,
Roel
 
Martin Krischik
Greenhorn
Posts: 23
Android Scala VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:For me that's obvious and quiet easy (and I'm also not a native speaker): code generated by a gui builder is not my own, so I can't submit that.



I already challenged that opinion and stated that I do not accept that stand as absolute and universal truth.

Of course I am well aware that neiter your nor my but only Suns opinion is important here. I will head the advice given here and I am thankfull.

Roel De Nijs wrote:I'm quiet sure a GUI builder will produce code that's completely different to mine.



Different to your code yes, but I already stated that the Netbeans generates code which looks exactly like the code suggested in the Sun tutorial for for use of GroupLayout in hand coded GUIs. GroupLayout is part of Java 6 so I am free to use it.

Roel De Nijs wrote:Secondly they gave very little information and certainly not an official stand. I sent them an email asking if I could change Sun's interface just to add some javadoc to the methods.



Thank you for shareing your experince with who2contact@sun.com - no point wasting ones time here then.

Martin
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:I already challenged that opinion and stated that I do not accept that stand as absolute and universal truth.


I never stated that what I say, is the "absolute and universal" truth. That's why it starts with "For me": just my opinion, nothing more nothing less.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey All,

Quick follow up question kind of regarding this.

I have views in my application that are JDialogs and JFrames. I have helper classes that work on both (simple things like setting up titles, frame icons, etc) - the only common is that they are both java.awt.Window classes.

So is it bad to have a helper method like doSomething(java.awt.Window window)?

I interpret the "no awt" rule is that you shouldn't use awt widgets.

Thanks!
Matt
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt,

That's not a problem. I have used a similar method and passed Just don't use awt controls, so use JTextField instead of TextField

Kind regards,
Roel
 
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Krischik wrote:Until then I consider the instructions ambiguous


Welcome to the world of the SCJD!

For my part, I (a) employed GridBagLayout, BorderLayout, BoxLayout, and FlowLayout, and (b) coded everything by hand. (I prefer type-and-test to drag-and-drop.)

One possible, common-sensical interpretation of the rule is that generating non-trivial code automatically is a no-no. There's a difference between code-completion of a line you've chosen to type and concept-completion that decides what line should be typed.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic