• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple GUI question

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • 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
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • 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: 10591
140
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very helpful. Thank you, guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic