I am just starting my Java endeavour and have just finished reading through the learning java sections on the oracle website. So I'm just looking through a few packages seeing what is what.
So I had a look at the awt package which I'm assuming is a graphics package of sort?
Anyhow, I have tried just creating a frame using the following:
import java.awt.*;
class WindowTest{
public static void main(String[] args){
Frame f = new Frame(GraphicsConfiguration gc);
Rectangle bounds = gc.getBounds();
f.setLocation(10 + bounds.x, 10 + bounds.y);
}
}
I receive a compilation error when I try to compile, which is the following:
main.java:5: error: ')' expected
Frame f = new Frame(GraphicsConfiguration gc);
^
main.java:5: error: illegal start of expression
Frame f = new Frame(GraphicsConfiguration gc);
^
2 errors
I know I can't instantiate the GraphicsConfiguration as it's an abstract class and I cant initialise it with:
GraphicsConfiguration[] gc = GraphicsDevice.getConfiguration();
as the Frame does not accept GraphicsConfiguration[] as a constructor.
Any help would be appreciated, thanks.
When you call a method or constructor, you pass arguments - values - you're not declaring the parameters like you do when you declare the method or constructor.
So it should be something like:
GraphicsConfiguration gc = ...; // Whatever you need to get a value
Frame f = new Frame(gc);
Note that this is nothing to do with AWT specifically. It's just the basic syntax of calling a method or constructor. For example:
public class Test {
public static void main(String[] args) {
someMethod(10); // Fine; uses an integer literal
int a = 10;
someMethod(a); // Fine; uses the value of a variable
someMethod(int b); // Invalid syntax
}
public static void someMethod(int x) {
System.out.println(x);
}
}
In this specific case though, unless you have a particular GraphicsConfiguration
you want to specify, just call the parameterless constructor:
Frame f = new Frame();
See more on this question at Stackoverflow