Results 1 to 20 of 27
Thread: Swing vs AWT
- 06-19-2012, 06:57 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
- 06-19-2012, 07:00 PM #2
Re: Swing vs AWT
Have you tried google? Or the API? What have you tried?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-19-2012, 07:01 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Re: Swing vs AWT
I've tried google, all I can find is stuff for Swing and not AWT.
-
Re: Swing vs AWT
There's a lot more stuff posted regarding Swing because it has largely supplanted AWT, but yet if you search, you will find plenty of posts showing AWT code. I don't think our posting any random "sample" code is going to help you much. If you have a specific question, please ask it, as we're much better at helping this way.
- 06-19-2012, 07:31 PM #5
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Re: Swing vs AWT
Well, can you atleast tell me the difference between them both? As in what is the difference in syntax of the code pertaining to one another.
-
Re: Swing vs AWT
This has all been well discussed previously both here and on other sites. Surely you've Googled something like "difference between swing and awt" and have gone through some of the hits. Surely you're not asking us to re-enumerate that which has already been well discussed previously. Surely you'll instead tell us if you have any specific points of confusion.
- 06-19-2012, 07:42 PM #7
Re: Swing vs AWT
The Java language sets the syntax for coding a program. Its the classes that are AWT or Swing. Many of the Swing classes are in the javax.swing package and have classnames that start with the letter: J
If you don't understand my response, don't ignore it, ask a question.
- 06-19-2012, 07:47 PM #8
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Re: Swing vs AWT
Never mind. You guys do some Yoda **** with my questions...
Last edited by KevinWorkman; 06-19-2012 at 08:33 PM. Reason: Let's keep it PG, please!
- 06-19-2012, 08:35 PM #9
Re: Swing vs AWT
That's the spirit! All we've asked you to do was clarify what you're confused about so we can better help you. What part of the API has you confused? What did you find on google that didn't make sense?
If you think it's unreasonable for us to ask what you've done so far before we help you, for free, in our spare time, then much luck to you in your programming endeavors...How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-19-2012, 09:26 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,377
- Blog Entries
- 7
- Rep Power
- 17
Re: Swing vs AWT
I'm so happy Darryl told us the trick how to see the old version of a post ;-)
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-19-2012, 10:42 PM #11
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Re: Swing vs AWT
Can someone tell me why it keeps showing that I have an error atJava Code:package gui; import java.awt.*; import java.awt.event.*; public class MouseClicks { TextField objTF1; TextField objTF2; public static void main(String [] args){ MouseClicks MC = new MouseClicks(); } public MouseClicks(){ Frame f = new Frame(); Button button = new Button("Button :D"); button.setBounds(30, 30, 40, 10); button.addMouseListener(new MyMouseListener()); objTF1 = new TextField("Text 1", 100); objTF2 = new TextField("Text 2", 100); objTF1.setBounds(90, 70, 20, 10); objTF2.setBounds(90, 70, 20, 10); f.add(objTF1); f.add(objTF2); f.add(button); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent we){ System.exit(0); } }); } f.setSize(600, 600); f.setVisible(true); } class MyMouseListener extends MouseAdapter{ public void mouseClicked(MouseEvent me){ } }
Java Code:f.setSize(600, 600); f.setVisible(true);
- 06-19-2012, 10:51 PM #12
Re: Swing vs AWT
Please post the full text of the error message.it keeps showing that I have an errorIf you don't understand my response, don't ignore it, ask a question.
- 06-19-2012, 11:09 PM #13
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Re: Swing vs AWT
I got that error corrected but now, when i run it all I have is a very large button. Like my whole frame is a button.Java Code:package gui; import java.awt.*; import java.awt.event.*; public class MouseClicks { TextField objTF1; TextArea objTF2; public static void main(String [] args){ MouseClicks MC = new MouseClicks(); } public MouseClicks(){ Frame f = new Frame(); f.setSize(600, 600); f.setVisible(true); Button button = new Button("Button :D"); button.setBounds(40, 30, 40, 10); //button.addMouseListener(new MyMouseListener()); objTF1 = new TextField("Text 1", 100); objTF2 = new TextArea("Text 2", 100, 100); objTF1.setBounds(90, 70, 20, 10); f.add(objTF1); f.add(objTF2); f.add(button); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent we){ System.exit(0); } }); } } /**class MyMouseListener extends MouseAdapter{ public void mouseClicked(MouseEvent me){ } } **/
-
Re: Swing vs AWT
The issue is one of the layout managers. You're adding a bunch of things to a Frame which by default uses BorderLayout. If you add components to a BorderLayout using container, it will add it BorderLayout.CENTER and will fill the whole container, covering anything that was added previously. The solution is to read up on the layout managers (link coming soon), and to use appropriate layouts for your GUI.
Edit:
Please see: Layout Manager Tutorial
- 06-20-2012, 12:25 AM #15
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
-
Re: Swing vs AWT
- 06-20-2012, 12:39 AM #17
Member
- Join Date
- Jun 2012
- Location
- ON, Canada.
- Posts
- 25
- Rep Power
- 0
Re: Swing vs AWT
What the heck??? I agree 100% with you army.. Do you people know how annoying it is when you ask a question on a forum and people say "Go search it on Google?" Have you any idea how dumb you sound? Why is the forum existent then? If you're just gonna say "Go search for the answer elsewhere." Why run a damn forum and allow public access to ask questions??? "SURELY YOU MUST BE AN IDIOT!" Instead of doing your best to answer the question presented, you firstly look for faults, finding reason to make the question out to be an unworthy one, then follow up by beating around the bush, never addressing the question properly and giving vague answers that doesn't even scratch the surface of the question! So what the question is answered elsewhere, answer it a-frigging-gain! Or better yet, if your'e so sure it's answered elsewhere, post the damn link! Simple. If you don't have anything good to say/contribute, don't say anything at all. I've only been a member of this forum just recently and I've already seen this kinda crap dozens of times, and it's always coming from the "Moderators" supposedly the best this site has to offer... REALITY CHECK: It's not cool, not cool at all.
(Nothing personal, someone had to tell you people)"And that's not all Linus.."
- Agent Caldwell.
Anyways, to your question bro...
AWT (Abstract Window Toolkit) and Swing are both basically the same thing in that they are both GUI (Graphical User Interface) Components. AWT was developed earlier than swing, so you can say swing is a more sophisticated (modern if you may) version of AWT. Swing overall is more lightweight and friendly to the user because in addition to things like buttons, and check boxes, Swing provides even more advanced components such as tabbed panel, scroll panes, trees, tables, and lists. So it's a bit more flexible and robust. Compared to AWT where you have to render each component (TextField, Button, TextArea, etc..) that's specific to that particular dialog you're creating.
Here's a simple greeting program using the AWT:
And here's a program doing pretty much the same thing using swing:Java Code:import java.awt.*; import java.awt.event.*; public class AWTTextbox extends Frame implements ActionListener { public static void main (String args []) { new AWTTextbox (); } DialogTest dt; static TextField tf1; public AWTTextbox () { Button btn = new Button ("Click Here."); tf1 = new TextField (10); btn.addActionListener (this); add (btn, "North"); add (tf1, "South"); tf1.setBackground (Color.green); dt = new DialogTest (this); setSize (200, 80); setVisible (true); } public void actionPerformed (ActionEvent e) { dt.setVisible (true); } public static void confirm (String name) { tf1.setText ("Hello! " + name); } } class DialogTest extends Dialog implements ActionListener { TextField tf2; public DialogTest (Frame f1) { super (f1, "AWT Dialog Box", true); setLayout (new FlowLayout ()); Button btn1 = new Button ("Enter"); tf2 = new TextField (10); btn1.addActionListener (this); add (new Label ("What is your Name?")); add (tf2); add (btn1); setSize (200, 125); } public void actionPerformed (ActionEvent e) { AWTTextbox.confirm (tf2.getText ()); setVisible (false); } }
Right away you'll notice that the swing code is nearly 10 times shorter. Mainly because in the code for the AWT program there's creating and rendering of buttons, TextFieds, ActionListners, button positions, size, etc.. The program even calls and runs through several user-defined methods; a tedious and sometimes complex task especially for a programmer new to java.Java Code:import javax.swing.*; public class swingGUI { public static void main(String[] args) { String name = JOptionPane.showInputDialog("What is your name?"); JOptionPane.showMessageDialog(null, "Hello " + name + "!"); } }
In the case of swing, all that is done automatically, so it's simple as JOptionPane.showxxxxxDialog! And even still, the appearance of swing is customizeable in many ways from the imageIcons, buttons, labels etc... (I love swing, so I'm a bit biased for it). Anyways that being said, it's a good practice to use a combination of AWT and swing in your GUI.
Images of AWT Dialogs:



Images of swing Dialogs:


And there it is... your full answer, simple and uncomplicated.
CHEERS!
"The great majority of mankind are satisfied with appearances, as though they were realities, and are often more influenced by the things that seem than by those that are."
- Niccolò Machiavelli.Last edited by Tha Boss; 06-20-2012 at 01:29 AM.
E.Hughes☆™"I'm sometimes hard to please... because I'm only satisfied with the very best." - Fernand Point.
- 06-20-2012, 01:05 AM #18
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
Re: Swing vs AWT
Wow, thanks dude! I was kind of taken aback by how much less code Swing is compared to AWT!
I have another question, how do you use an Applet and Swing together? Since you need certain methods like init(),start(), paint(), etc. how would you use the components form Swing when to me it seems like you can't use your f.add() or normal object items...Last edited by Army; 06-20-2012 at 01:10 AM.
- 06-20-2012, 01:10 AM #19
Re: Swing vs AWT
There is a difference between helping someone learn how to solve programming problems and providing them with the solution.
Heard the one about the the hungry man and giving him a fish vs teaching him how to fish.
The more you exercise your brain the stronger it will get. Copying and pasting does not provide much thought.
You have to make the mistakes to learn. You have to try all the different deadends to be a better programmer.
I'm not here to solve people's problems. I want to help them learn how to solve problems on their own.
Several things an OP should know: How to find things with google.
How to read the API doc.
How to ask a question and provide all needed info to describe the problem.Last edited by Norm; 06-20-2012 at 01:17 AM.
If you don't understand my response, don't ignore it, ask a question.
- 06-20-2012, 01:20 AM #20
Member
- Join Date
- Jun 2012
- Location
- ON, Canada.
- Posts
- 25
- Rep Power
- 0
Re: Swing vs AWT
Yeah yeah yeah.... I expected one of you mods to be saying that sooner or later...
But get this... teaching someone is showing them by example... no beating around the bush when they ask you a question and pointing them back and forth giving waffled tidbits of information they cant work with. Any case he's not the only one that's going to benefit.. I made it very informative. Maybe even better than professional tutorials you'll find elsewhere...
DISCUSSION CONTINUED ON PAGE 2!"Don't hate... Appreciate"Last edited by Tha Boss; 06-20-2012 at 02:33 AM.
E.Hughes☆™"I'm sometimes hard to please... because I'm only satisfied with the very best." - Fernand Point.
Similar Threads
-
I need help about swing...
By CANN1 in forum AWT / SwingReplies: 2Last Post: 03-31-2012, 02:50 PM -
Swing To Jsp
By jim in forum Advanced JavaReplies: 1Last Post: 10-09-2011, 11:51 PM -
help with Swing (GUI)
By Bagzli in forum New To JavaReplies: 8Last Post: 04-04-2011, 12:18 AM -
where is the swing jar?
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:58 PM -
map javax.swing.text.Element to javax.swing.text.View
By elizabeth in forum New To JavaReplies: 1Last Post: 07-30-2007, 07:02 PM


3Likes
LinkBack URL
About LinkBacks


Bookmarks