I created a Dimension and a Point object but I do not need to name both of these objects and call its constructor inside the argument of the method call. May I have an explanation why this is possible? I have been far too used to giving my objects name that I am need explanation to my question.
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JFrame;
public class GameFrame extends JFrame {
public GameFrame()
{
// call this method to the GameFrame object
// if you do not call this method the JFrame subclass will not actually close
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set size to an appropriate size
// create a dimension object
setSize(new Dimension(600,600));
// upon creating the object set the location of the frame to the center of the screen
setLocation(new Point (500,300));
// prevent the user from resizing the GameFrame object
setResizable(false);
}
}
When you write
you are actually saving a reference of the
Dimensionobject as you create the object and pass it to the method.This works well and recommended if you need not use the object further for any computation separately.