Hi!
I am supposed to write a programm for making a window.First of all, I must make a window with some given default values. Below is the code that I have been given as a template

 public class Window  {
    private String name;
    private int height;
    private int width;
    private String isActive;
    private String color;
    int[] WindowPoint=new int[2];




     public Window()
    {
        name="MyWindow";
        height=6;
        width=12;
        WindowPoint[0] =0;
        WindowPoint[1] =0;
        color="white";
        isActive="active";


    }

There's something that I cannot understand: In order to make a window, shouldn't I import the JFrame package and say that the Window class is a subclass of JFrame? If so, how can I have a Window constructor instead of using the JFrame built-in constructor in order to make my window? Is there another way to make a window, without using the JFrame or something similar?
Could someone explain this to me? Thank you in advance!

yes. a JFrame is what you describe as a "Window". you'll need to have your Window class extend the JFrame class and configure and initialize it correctly.

Thanks for your response! So ,it seems that inside the Window constructor I must call the JFrame constructor and somehow pass the values I'm given, right?

Well, if I only write Window extends JFrame I get a small window at the upper left corner of my screen, without any title...

Ok, I got it! Here's the code and it works perfectly

  public Window()
    {
        setTitle("MyWindow");
        setSize(6,12);
        setLocation(0,0);
        getContentPane().setBackground(Color.white);

        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);




    }

Edited 3 Years Ago by ambageo: updated and resolved

This question has already been answered. Start a new discussion instead.