943,922 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1628
  • Java RSS
Feb 18th, 2008
0

Regular GUI design help

Expand Post »
hey all, the noob is back. and with more questions that you guys will probably make fun of me for but...whatever.

I am creating a GUI design where there are four labels (it doesn't need functionality) with an OK, HELP and CANCEL button on the right side. i haven't started on the buttons yet because I've got a error already.

the error is "invalid method declaration" on the line 18 LabelFrame() part. but it's weird because this is a part where i'm still copying everything from the book (because the buttons are the real exercise). any suggestions. or do i need to finish the test program to get it to work?

Okay...Go ahead

Java Syntax (Toggle Plain Text)
  1. import java.awt.FlowLayout; // specifies how components will be arranged
  2. import javax.swing.JFrame; // provides basic window features
  3. import javax.swing.JLabel; // displays text, images
  4. import javax.swing.SwingConstants;
  5.  
  6.  
  7. public class GUIEx extends JFrame
  8. {
  9. private JLabel label1; // just text (snap to grid)
  10. private JLabel label2; // just text (show grid)
  11. private JLabel label3; // just text (X:)
  12. private JLabel label4; // just text (Y:)
  13.  
  14. //Label frames
  15. public LabelFrame()
  16. {
  17. super( "Align" );
  18. setLayout( new FlowLayout() ); // set frame layout
  19.  
  20. // label1
  21. label1 = new JLabel( "Snap to Grid");
  22. label1.setToolTipText( "Snaps onto Grid Lines");
  23. add(label1); // adds the label to the JFrame
  24. label1.setVerticalTextPosition(SwingConstants.LEFT);
  25. label1.setHorizontalTextPosition(SwingConstants.TOP);
  26.  
  27. // label2
  28. label1 = new JLabel( "Show Grid");
  29. label1.setToolTipText( "Shows the gridlines in your workspace");
  30. add(label2); // adds the label to the JFrame
  31. label1.setVerticalTextPosition(SwingConstants.LEFT);
  32. label1.setHorizontalTextPosition(SwingConstants.BOTTOM);
  33.  
  34. // label3
  35. label1 = new JLabel( "X: ");
  36. label1.setToolTipText( "The X axis");
  37. add(label3); // adds the label to the JFrame
  38. label1.setVerticalTextPosition(SwingConstants.CENTER);
  39. label1.setHorizontalTextPosition(SwingConstants.TOP);
  40.  
  41. // label4
  42. label1 = new JLabel( "Y: ");
  43. label1.setToolTipText( "The Y axis");
  44. add(label4); // adds the label to the JFrame
  45. label1.setVerticalTextPosition(SwingConstants.CENTER);
  46. label1.setHorizontalTextPosition(SwingConstants.BOTTOM);
  47. } // ends JLabel constructors
  48. } // ends class
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
leroi green is offline Offline
93 posts
since Oct 2007
Feb 18th, 2008
0

Re: Regular GUI design help

The class is called GUIEx and you have a method called LabelFrame() in which you call super().
Meaning that super(), should called only inside the constructor and LabelFrame is not a constructor since the class's name is GUIEx
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007
Feb 21st, 2008
0

Re: Regular GUI design help

okay, i've been following along a little on the chap 11 pages and it leads you to write a testing program. both will compile for me but then not run...not sure exactly where to go & i've gone thru the index a couple times (2 double check myself).

where am i screwing up?

Java Syntax (Toggle Plain Text)
  1. import java.awt.FlowLayout; // specifies how components will be arranged
  2. import javax.swing.JFrame; // provides basic window features
  3. import javax.swing.JLabel; // displays text, images
  4. import javax.swing.SwingConstants;
  5.  
  6.  
  7. public class LabelFrame extends JFrame
  8. {
  9. private JLabel label1; // just text (snap to grid)
  10. private JLabel label2; // just text (show grid)
  11. private JLabel label3; // just text (X:)
  12. private JLabel label4; // just text (Y:)
  13.  
  14.  
  15. //Label frames
  16. public LabelFrame()
  17. {
  18. super( "Align" );
  19. setLayout( new FlowLayout() ); // set frame layout
  20.  
  21. // label1
  22. label1 = new JLabel( "Snap to Grid");
  23. label1.setToolTipText( "Snaps onto Grid Lines");
  24. add(label1); // adds the label to the JFrame
  25. label1.setVerticalTextPosition(SwingConstants.LEFT);
  26. label1.setHorizontalTextPosition(SwingConstants.TOP);
  27.  
  28. // label2
  29. label1 = new JLabel( "Show Grid");
  30. label1.setToolTipText( "Shows the gridlines in your workspace");
  31. add(label2); // adds the label to the JFrame
  32. label1.setVerticalTextPosition(SwingConstants.LEFT);
  33. label1.setHorizontalTextPosition(SwingConstants.BOTTOM);
  34.  
  35. // label3
  36. label1 = new JLabel( "X: ");
  37. label1.setToolTipText( "The X axis");
  38. add(label3); // adds the label to the JFrame
  39. label1.setVerticalTextPosition(SwingConstants.CENTER);
  40. label1.setHorizontalTextPosition(SwingConstants.TOP);
  41.  
  42. // label4
  43. label1 = new JLabel( "Y: ");
  44. label1.setToolTipText( "The Y axis");
  45. add(label4); // adds the label to the JFrame
  46. label1.setVerticalTextPosition(SwingConstants.CENTER);
  47. label1.setHorizontalTextPosition(SwingConstants.BOTTOM);
  48. } // ends JLabel constructors
  49. } // ends class

Java Syntax (Toggle Plain Text)
  1. import javax.swing.JOptionPane;
  2.  
  3. public class LTester
  4. {
  5. public static void main( String args[])
  6. {
  7. LabelFrame labelFrame = new LabelFrame(); // create a frame for you
  8. labelFrame.setSize( 375, 180); // make the box the size you want
  9. labelFrame.setVisible(true); //display frame
  10. } // end main
  11. } // end class LTester
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
leroi green is offline Offline
93 posts
since Oct 2007
Feb 21st, 2008
0

Re: Regular GUI design help

I believe you have these SwingConstants backwards in the two lines below. I ran your code through NetBeans and it gave me exceptions on these lines:
Java Syntax (Toggle Plain Text)
  1. label1.setVerticalTextPosition(SwingConstants.LEFT);
  2. label1.setHorizontalTextPosition(SwingConstants.TOP);
Swapping the positions of LEFT and TOP in the above lines got me farther in the code. TOP goes with Vertical and LEFT with HORIZONTAL, not the way you have it. Try swapping them for label1 and the other labels.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Feb 21st, 2008
0

Re: Regular GUI design help

thanx. will do now

I believe you have these SwingConstants backwards in the two lines below. I ran your code through NetBeans and it gave me exceptions on these lines:
Java Syntax (Toggle Plain Text)
  1. label1.setVerticalTextPosition(SwingConstants.LEFT);
  2. label1.setHorizontalTextPosition(SwingConstants.TOP);
Swapping the positions of LEFT and TOP in the above lines got me farther in the code. TOP goes with Vertical and LEFT with HORIZONTAL, not the way you have it. Try swapping them for label1 and the other labels.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
leroi green is offline Offline
93 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Array of Strings???
Next Thread in Java Forum Timeline: java.io.FileNotFoundException





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC