Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

JFrame point object returns...what?

Thread view: 
UKP - 26 Sep 2007 05:12 GMT
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 - 26 Sep 2007 05:44 GMT
>public QuarterScreenFrame(String title, Point topLeft) // creates a
>frame with title
[quoted text clipped - 9 lines]
>
>        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

Signature

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

Andrew Thompson - 26 Sep 2007 06:14 GMT
...
>        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.

Signature

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

UKP - 26 Sep 2007 09:18 GMT
Thanks guys, I modified my code in a different way.
Andrew Thompson - 26 Sep 2007 12:23 GMT
>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'?

Signature

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

Roedy Green - 26 Sep 2007 23:46 GMT
>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
Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.