Regular GUI design help

Reply

Join Date: Oct 2007
Posts: 88
Reputation: leroi green is an unknown quantity at this point 
Solved Threads: 0
leroi green leroi green is offline Offline
Junior Poster in Training

Regular GUI design help

 
0
  #1
Feb 18th, 2008
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

  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,633
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 222
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Regular GUI design help

 
0
  #2
Feb 18th, 2008
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
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 88
Reputation: leroi green is an unknown quantity at this point 
Solved Threads: 0
leroi green leroi green is offline Offline
Junior Poster in Training

Re: Regular GUI design help

 
0
  #3
Feb 21st, 2008
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?

  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

  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,810
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Regular GUI design help

 
0
  #4
Feb 21st, 2008
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 88
Reputation: leroi green is an unknown quantity at this point 
Solved Threads: 0
leroi green leroi green is offline Offline
Junior Poster in Training

Re: Regular GUI design help

 
0
  #5
Feb 21st, 2008
thanx. will do now

Originally Posted by VernonDozier View Post
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:
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC