Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: setSize() not working

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default setSize() not working

    Hello, Sorry if this question is noobish i just started java 2 days ago when tried to make the setSize() statement it gave this error that i don't understand

    Multiple markers at this line
    - Syntax error on tokens, delete these tokens
    - Syntax error on token(s), misplaced construct(s)
    - Syntax error on token "setSize", invalid

    And here is the code if you need it

    Page One

     
    public class jframeTest {
    public static void main(String args[]) {
     
     
    }
    }

    Second Page

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class GUI extends JFrame {
    	private static final long serialVersionUID = 1L;
     
    	// First Window
    	JFrame firstWindow = new JFrame("Calculator");
    	firstWindow.setSize(200, 150);
    	firstWindow.setVisable(true);
    }


  2. #2
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: setSize() not working

    Hi 812d,
    I will explain this as I understand it, which should not be taken as gospel or technically correct but should help you out. The area where you use setSize, and setVisible for that matter, is where you would normally declare/initialize variables. So, since setSize is a method that modifies the object (variable) firstWindow the compiler gets upset. Take a peek at what a class constructor is in Java and how they are used. If you do so I am sure you will find the answer to your problem. I should note that this is a case of "There's more than one way to skin a cat." but if you figure out this one way you may be able to figure out the others.

  3. The Following User Says Thank You to KucerakJM For This Useful Post:

    812d (July 19th, 2014)

  4. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: setSize() not working

    1) Class names should always start with capital letters.

    2) Your class GUI already extends JFrame, creating a new JFrame within is probably not what you want.

    3) Methods (like, for example, setSize(...)) must be called from within other methods. Define a method and put those statements within the method body.

  5. The Following User Says Thank You to Cornix For This Useful Post:

    812d (July 19th, 2014)

  6. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: setSize() not working

    Hello, Sorry if this question is noobish i just started java 2 days ago when tried to make the setSize() statement it gave this error that i don't understand
    If you've only 2 days of Java experience, you've leapt into GUI programming too quickly.

    The primary mistake you've made - Cornix' number 3 - indicates a lack of understanding or experience with basic program construction that will be remedied with more study in and practice with Java's basics. Please slow down and give yourself a decent chance by spending a few months (or more) working through the basics.

  7. The Following User Says Thank You to GregBrannon For This Useful Post:

    812d (July 19th, 2014)

Similar Threads

  1. Replies: 2
    Last Post: June 25th, 2013, 06:33 AM
  2. Replies: 7
    Last Post: April 25th, 2013, 01:12 PM
  3. using the setSize and setLocation methods of Rectangle class
    By etidd in forum Java Theory & Questions
    Replies: 1
    Last Post: March 6th, 2010, 04:03 PM
  4. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM

Tags for this Thread