Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 21st, 2007, 4:50 AM   #1
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Shouldnt this work?

ok, i'm confused why this doesnt work
java Syntax (Toggle Plain Text)
  1.  
  2. import java.awt.*;
  3. import javax.swing.*;
  4.  
  5. public class GuiExample extends JApplet
  6. {
  7. Button okButton;
  8.  
  9. TextField nameField;
  10.  
  11. CheckboxGroup radioGroup;
  12.  
  13. Checkbox radio1;
  14. Checkbox radio2;
  15.  
  16. Checkbox option;
  17.  
  18. public void init()
  19. {
  20. //setLayout(null);
  21.  
  22. okButton = new Button("A Button");
  23.  
  24. nameField = new TextField("A TextField", 100);
  25.  
  26. radioGroup = new CheckboxGroup();
  27.  
  28. radio1 = new Checkbox("Radio 1", radioGroup, false);
  29.  
  30. radio2 = new Checkbox("Radio 2", radioGroup, true);
  31.  
  32. option = new Checkbox("Option", false);
  33.  
  34. okButton.setBounds(20,20,100,30);
  35. nameField.setBounds(20,70,100,40);
  36. radio1.setBounds(20,120,100,30);
  37. radio2.setBounds(140,120,100,30);
  38. option.setBounds(20,170,100,30);
  39.  
  40. add(okButton);
  41. add(nameField);
  42. add(radio1);
  43. add(radio2);
  44. add(option);
  45. }
  46. }

it compiles, but when i run it in blueJ it give me this "applet not initialized"
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Jun 21st, 2007, 9:45 AM   #2
Tsar_of_Cows
Newbie
 
Join Date: Jun 2007
Posts: 15
Rep Power: 0 Tsar_of_Cows is on a distinguished road
It's been a while sicne I extended a class, but I seem to remember you tended to need certain methods or you'd get an error like that.

Are you sure you have all the required methods for it to work? (I've never sued applets so I wouldn't know)
Tsar_of_Cows is offline   Reply With Quote
Old Jun 21st, 2007, 10:10 AM   #3
Tsar_of_Cows
Newbie
 
Join Date: Jun 2007
Posts: 15
Rep Power: 0 Tsar_of_Cows is on a distinguished road
Ah, I just realised exactly what's wrong!

IIRC, the fist thing you have to do when extending a class is call the super class in the contruction method.

Try this:

java Syntax (Toggle Plain Text)
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class GuiExample extends JApplet
  5. {
  6. Button okButton;
  7.  
  8. TextField nameField;
  9.  
  10. CheckboxGroup radioGroup;
  11.  
  12. Checkbox radio1;
  13. Checkbox radio2;
  14.  
  15. Checkbox option;
  16.  
  17. //Constructor method
  18. public GuiExample()
  19. {
  20.  
  21. super();
  22.  
  23. init();
  24.  
  25. }
  26.  
  27. public void init()
  28. {
  29. //setLayout(null);
  30.  
  31. okButton = new Button("A Button");
  32.  
  33. nameField = new TextField("A TextField", 100);
  34.  
  35. radioGroup = new CheckboxGroup();
  36.  
  37. radio1 = new Checkbox("Radio 1", radioGroup, false);
  38.  
  39. radio2 = new Checkbox("Radio 2", radioGroup, true);
  40.  
  41. option = new Checkbox("Option", false);
  42.  
  43. okButton.setBounds(20,20,100,30);
  44. nameField.setBounds(20,70,100,40);
  45. radio1.setBounds(20,120,100,30);
  46. radio2.setBounds(140,120,100,30);
  47. option.setBounds(20,170,100,30);
  48.  
  49. add(okButton);
  50. add(nameField);
  51. add(radio1);
  52. add(radio2);
  53. add(option);
  54. }
  55. }
Tsar_of_Cows is offline   Reply With Quote
Old Jun 21st, 2007, 3:40 PM   #4
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
@Tsar_of_Cows: When a GuiExample object is created, the super class, JApplet's constructor will automatically be called right before the GuiExample's constructor. It's all OOP.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Jun 21st, 2007, 4:51 PM   #5
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Now it says "do not use GuiExample.add() use GuiExample.getContentPane().add() instead." then it gives me the original error
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Jun 21st, 2007, 5:39 PM   #6
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Your code (crawforddavid2006) works fine for me (although the window layout leaves much to be desired). There may be some special way to initialize an applet in BlueJ before it can run; however, I suggest you find a real IDE/compiler instead.
titaniumdecoy is offline   Reply With Quote
Old Jun 22nd, 2007, 5:44 PM   #7
Tsar_of_Cows
Newbie
 
Join Date: Jun 2007
Posts: 15
Rep Power: 0 Tsar_of_Cows is on a distinguished road
Quote:
Originally Posted by reggaeton_king View Post
@Tsar_of_Cows: When a GuiExample object is created, the super class, JApplet's constructor will automatically be called right before the GuiExample's constructor. It's all OOP.
Is that specific to Applets?
Tsar_of_Cows is offline   Reply With Quote
Old Jun 22nd, 2007, 6:54 PM   #8
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
No; it's specific to the Java language.

Last edited by titaniumdecoy; Jun 22nd, 2007 at 7:09 PM.
titaniumdecoy is offline   Reply With Quote
Old Jun 23rd, 2007, 3:56 AM   #9
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
It's not even really specific to Java. When you create an object, if you do not explicity call the super constructor, then the superclass' default constructor will be called... sort of. That way, all of the super class' memory space gets initialized at the very least. It wouldn't really make sense if it didn't. If you don't get it, don't worry. I didn't really get it until I wrote an entire program, which you are planning on doing now anyway, right?

Cheers.



The applet works for me. Here is my html code (pretty much taken from the example)

<HTML>
<HEAD>
<TITLE> Query Output </TITLE>
</HEAD>
<BODY>

Output from query 
select NAME, PRICE from COFFEES 
<APPLET CODE="GuiExample.class" WIDTH=250 HEIGHT=200>
</APPLET>
</BODY>
<script language="JavaScript" src="/js/omi/jsc/s_code_remote.js"></script></HTML>

I used JDK 6.1 on Vista Business to test this.

Last edited by Harakim; Jun 23rd, 2007 at 4:09 AM. Reason: I felt like it.
Harakim is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thinking about moving to USA to work in software - advice please! funkey_monkey Coder's Corner Lounge 3 Jan 23rd, 2007 7:56 AM
tables dont work in firefox; they work in IE angry_asian HTML / XHTML / CSS 3 Aug 5th, 2006 6:00 PM
Help:::::::: Why Wont This Work?????? paulchwd ASP 1 Jul 10th, 2005 1:34 PM
Can't get loop to work rockybalboa Java 3 Mar 20th, 2005 6:19 PM
40 Things you'd like to say out loud at work big_k105 Coder's Corner Lounge 11 Jan 25th, 2005 2:13 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC