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 2 of 2

Thread: Separate method to create Window

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    4
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Separate method to create Window

    Hello!

    Just wondering where I need to extend JFrame to get this working...

    //imports
    import javax.swing.JFrame;
     
    //main class
    public class mainClass extends JFrame {
    	//class level variables
    	private static final long serialVersionUID = 1L;
    	double wX,wY,wW,wH;
    	public static void main(String[] args) {
    /*
     *  Main method calls and creates windows, sprite, etc.
     *  Separate methods will be made to manage the calls
     *  */
    		createWindow(0,0,800,400,"Workbed");
    	}
     
    //create window method
    	static void createWindow(double wX,double wY,double wW,double wH,String windowTitle){
    		//window properties
    		setTitle(windowTitle);
    		setSize(wW,wH);
    		setLocation(wX,wY);
    		setVisible(true);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		//window arguments
    	}

    When I extend it from the mainClass, it comes up with errors in the createWindow method...


    Thank you! Any other tips for this would be great!


  2. #2
    Member
    Join Date
    Jan 2013
    Posts
    39
    My Mood
    Relaxed
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Separate method to create Window

    You are actaly not creating a window. You extend the class with JFrame. I find this really annoying, i always import it and use it as a instance, wich makes you more capable of making more windows at once.

Similar Threads

  1. How to create this recursive method.
    By exodus2041 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2013, 10:26 AM
  2. create an equals() method that overrides the object equals() method
    By slinky29 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2013, 11:11 PM
  3. [SOLVED] How to create a Java generic method, similar to a C++ template method?
    By Sharmeen in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2012, 02:33 AM
  4. Trying to create a window...
    By Tedstriker in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 16th, 2012, 11:39 AM
  5. Replies: 2
    Last Post: October 31st, 2011, 09:19 AM