-1

I'm trying to make a GUI, and I can accomplish it all in one method, but I would like to make the code simpler and make multiple methods. However, I can't get it to work. I am new to Java programming.

public class Main {
    public static void main(String[] args) {
        FirstWindow fw = new FirstWindow();

        fw.setVisible(true);
        fw.setSize(600,400);
    }
}

public class FirstWindow extends JFrame {

    public FirstWindow() {
        checkbox c = new checkbox();
        c();
    }
}


public class checkbox extends JFrame {

    public checkbox() {
          //code
    }
}
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
  • 6
    `I am new to java programming.` - Time to do some reading. Start with the section from the Swing tutorial on [How to Make Frames](http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html) It contains examples along with explanations to help you better structure your code. And don't forget to look at the table of contents for examples of using other Swing components. – camickr Dec 31 '13 at 22:38
  • 1
    This question is a bit vague. What are you even asking? – Epiglottal Axolotl Dec 31 '13 at 22:48
  • Why are you using multiple frames? – MadProgrammer Dec 31 '13 at 22:55
  • My question was a bit vague, I'm sorry. I can get the program to work correctly in one class/method FirstWindow, but the code for the method is very long. I am trying to separate the code into multiple methods to have the code more organized and still be able to use one frame. I'll read up more and thanks for all the help. – user3150314 Dec 31 '13 at 23:31
  • Before studying Swing, you will want to get a basic Java book and first study Java. – Hovercraft Full Of Eels Jan 01 '14 at 03:47

1 Answers1

1

I'm not sure what you're trying to do, but here's something to consider: c(); won't do anything. c is an instance of the class checkbox and not a method to be called. So consider this:

public class FirstWindow extends JFrame {

    public FirstWindow() {
        checkbox c = new checkbox();
        c.yourMethod(yourParameters); // call the method you made in checkbox
    }
}

public class checkbox extends JFrame {

    public checkbox(yourParameters) { 
        // this is the constructor method used to initialize instance variables
    }

    public void yourMethod() // doesn't have to be void
    {
        // put your code here
    }
}
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97