JFrame point object returns...what?

U

UKP

If you check this method in the main class - JFrame frame = new
QuarterScreenFrame("This is a test", 1);

I'm just not sure what value of topLeft to put..

This is the main class --

public class QuarterScreenTester {

public static void main(String[] args) {
JFrame frame = new QuarterScreenFrame("This is a test", 0,1);
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


-*-*-*-*******************************


This is the sub-class ---


public QuarterScreenFrame(String title, Point topLeft) // creates a
frame with title
{

super(title);
int width;
int height;
int x,y;

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dimensions =toolkit.getScreenSize();

topLeft = new Point (dimensions.width, dimensions.height);
x = topLeft.x;
y = topLeft.y;

setBounds(0,0,x,y);
}
 
R

Roedy Green

public QuarterScreenFrame(String title, Point topLeft) // creates a
frame with title
{

super(title);
int width;
int height;
int x,y;

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dimensions =toolkit.getScreenSize();

topLeft = new Point (dimensions.width, dimensions.height);

This makes no sense. Why do you pass a topLeft parameter then override
it?

Top Left is 0,0, yet topLeft points to bottom, right so your frame
will appear off screen to the bottom right.

see http://mindprod.com/jgloss/coordinates.html
 
A

Andrew Thompson

UKP wrote:
...
setBounds(0,0,x,y);

Roedy has already covered some of the questions
that others might ask about this code. But just
noticing that 'setBounds' I should point out that
it is almost always a sign of a very poor, fragile
GUI.

The best way to get the desired size is to overide
or set the preferred size, then pack() or validate()
the GUI. Calling setLocation() puts the frame
wherever on screen that it needs to be.

Further, the preferred size is usually best done
on components within frames, rather than the
frame itself. My basis for saying that, is the
almost inevitable (re)use of anything but the
most trivial components, in dialogs or option
panes, applets, or windows.

Use of appropriate layouts can arrange the UI
elements as needed.

There is a group specialised for GUI matters, it is
comp.lang.java.gui.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top