This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple GUI question

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone.

I apologize the simplicity of this question, but this is my first time really working with GUI's. My test instructions state something to the effect that I must build my GUI from components from the Java Foundation Classes (Swing components). However, in my studies I am seeing an import for java.awt in addition to .swing. So, is .awt considered to be a Swing component? Can I use it? I notice the SCJD book imports both, but seeing as how it is now a few years old, I thought I should ask.

Thanks to everyone.

Matt
 
Paul Clapham
Sheriff
Pie
Posts: 20160
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me put it this way... String isn't a Swing component. Would you conclude that you couldn't use String in your program?

Of course you wouldn't. That would be absurd. Of course you can use classes which support your use of those Swing components. For example you might need to use a Font object. A java.awt.Font object, to be specific.
 
Roel De Nijs
Sheriff
Posts: 9088
73
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not supposed to use an awt component if a swing version exists. For example: you have java.awt.TextField and javax.swing.JTextField, so you should use the JTextField. But if you have a look at the class hierarchy you'll see it extends java.awt.Component. And the layout managers are all in the awt-package, so your gui classes certainly will have imports from the awt-package.

 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is also allowed to have an ActionListener in a button. Its fully qualified name is java.awt.event.ActionListener.
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very helpful. Thank you, guys.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic