JFrame point object returns...what?  
Author Message
UKP





PostPosted: 2007-9-26 12:13:00 Top

java-programmer, JFrame point object returns...what? 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);
}

 
Roedy Green





PostPosted: 2007-9-26 12:45:00 Top

java-programmer >> JFrame point object returns...what? On Wed, 26 Sep 2007 04:12:58 -0000, UKP <email***@***.com> wrote,
quoted or indirectly quoted someone who said :

>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

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Andrew Thompson





PostPosted: 2007-9-26 13:15:00 Top

java-programmer >> JFrame point object returns...what? 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.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via http://www.javakb.com

 
 
UKP





PostPosted: 2007-9-26 16:19:00 Top

java-programmer >> JFrame point object returns...what? Thanks guys, I modified my code in a different way.

 
 
Andrew Thompson





PostPosted: 2007-9-26 19:23:00 Top

java-programmer >> JFrame point object returns...what? UKP wrote:
>Thanks guys, I modified my code in a different way.

OK - fine, so... are you going to discuss *how* you
changed it, or are you just going to treat us as if we
were your personal 'help-desk servants'?

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1

 
 
Roedy Green





PostPosted: 2007-9-27 6:47:00 Top

java-programmer >> JFrame point object returns...what? On Wed, 26 Sep 2007 05:14:58 GMT, "Andrew Thompson" <u32984@uwe>
wrote, quoted or indirectly quoted someone who said :

>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.

In other words, use a LayoutManager or write your own. Don't pepper
business logic with absolute positioning.

http://mindprod.com/jgloss/layout.html
http://mindprod.com/jgloss/layoutmanager.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com