| | |
Regular GUI design help
![]() |
•
•
Join Date: Oct 2007
Posts: 85
Reputation:
Solved Threads: 0
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
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)
import java.awt.FlowLayout; // specifies how components will be arranged import javax.swing.JFrame; // provides basic window features import javax.swing.JLabel; // displays text, images import javax.swing.SwingConstants; public class GUIEx extends JFrame { private JLabel label1; // just text (snap to grid) private JLabel label2; // just text (show grid) private JLabel label3; // just text (X:) private JLabel label4; // just text (Y:) //Label frames public LabelFrame() { super( "Align" ); setLayout( new FlowLayout() ); // set frame layout // label1 label1 = new JLabel( "Snap to Grid"); label1.setToolTipText( "Snaps onto Grid Lines"); add(label1); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.LEFT); label1.setHorizontalTextPosition(SwingConstants.TOP); // label2 label1 = new JLabel( "Show Grid"); label1.setToolTipText( "Shows the gridlines in your workspace"); add(label2); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.LEFT); label1.setHorizontalTextPosition(SwingConstants.BOTTOM); // label3 label1 = new JLabel( "X: "); label1.setToolTipText( "The X axis"); add(label3); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.CENTER); label1.setHorizontalTextPosition(SwingConstants.TOP); // label4 label1 = new JLabel( "Y: "); label1.setToolTipText( "The Y axis"); add(label4); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.CENTER); label1.setHorizontalTextPosition(SwingConstants.BOTTOM); } // ends JLabel constructors } // ends class
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
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
•
•
Join Date: Oct 2007
Posts: 85
Reputation:
Solved Threads: 0
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?
where am i screwing up?
Java Syntax (Toggle Plain Text)
import java.awt.FlowLayout; // specifies how components will be arranged import javax.swing.JFrame; // provides basic window features import javax.swing.JLabel; // displays text, images import javax.swing.SwingConstants; public class LabelFrame extends JFrame { private JLabel label1; // just text (snap to grid) private JLabel label2; // just text (show grid) private JLabel label3; // just text (X:) private JLabel label4; // just text (Y:) //Label frames public LabelFrame() { super( "Align" ); setLayout( new FlowLayout() ); // set frame layout // label1 label1 = new JLabel( "Snap to Grid"); label1.setToolTipText( "Snaps onto Grid Lines"); add(label1); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.LEFT); label1.setHorizontalTextPosition(SwingConstants.TOP); // label2 label1 = new JLabel( "Show Grid"); label1.setToolTipText( "Shows the gridlines in your workspace"); add(label2); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.LEFT); label1.setHorizontalTextPosition(SwingConstants.BOTTOM); // label3 label1 = new JLabel( "X: "); label1.setToolTipText( "The X axis"); add(label3); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.CENTER); label1.setHorizontalTextPosition(SwingConstants.TOP); // label4 label1 = new JLabel( "Y: "); label1.setToolTipText( "The Y axis"); add(label4); // adds the label to the JFrame label1.setVerticalTextPosition(SwingConstants.CENTER); label1.setHorizontalTextPosition(SwingConstants.BOTTOM); } // ends JLabel constructors } // ends class
Java Syntax (Toggle Plain Text)
import javax.swing.JOptionPane; public class LTester { public static void main( String args[]) { LabelFrame labelFrame = new LabelFrame(); // create a frame for you labelFrame.setSize( 375, 180); // make the box the size you want labelFrame.setVisible(true); //display frame } // end main } // end class LTester
•
•
Join Date: Jan 2008
Posts: 3,752
Reputation:
Solved Threads: 491
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:
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.
Java Syntax (Toggle Plain Text)
label1.setVerticalTextPosition(SwingConstants.LEFT); label1.setHorizontalTextPosition(SwingConstants.TOP);
•
•
Join Date: Oct 2007
Posts: 85
Reputation:
Solved Threads: 0
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:
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.Java Syntax (Toggle Plain Text)
label1.setVerticalTextPosition(SwingConstants.LEFT); label1.setHorizontalTextPosition(SwingConstants.TOP);
![]() |
Similar Threads
- Help required for Sun Certified Java Developer Exam(SCJD) (Java)
- Web programmers making more then software programmers? (IT Professionals' Lounge)
- CTFMON32 Hijackthis (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Array of Strings???
- Next Thread: java.io.FileNotFoundException
| Thread Tools | Search this Thread |
911 actionlistener addball addressbook android applet application apps array automation binary bluetooth businessintelligence button card character class client code collision component consumer crashcourse css csv database desktop eclipse ee error fractal free ftp game givemetehcodez graphics gui html image integration j2me japplet java javaarraylist javac javadoc javaee javafx javaprojects jni jpanel julia jvm linked linux loan mac method migrate mobile netbeans objects online oriented phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server service set sms software sort sql swing test textfield textfields threads time tree trolltech ubuntu update utility windows






