Results 1 to 5 of 5
  1. #1
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

    Default Finding where to draw

    If I run the program below on Linux with OpenJDK Runtime Environment (IcedTea6 1.6) (suse-0.1.3-x86_64), it tells me:
    Size: 1440x900
    Offset: 0,25

    With Java(TM) SE Runtime Environment (build 1.6.0_15-b03):
    Size: 1440x900
    Offset: 0,0

    Now 0,0 is a bit a problem: if I start to draw in my frame at that offset, it'll disappear behind the window-titlebar.

    So my question is: what is the way (the standard in java) to find out where to start drawing in your frame?

    Java Code:
    import java.awt.*;
    import java.awt.geom.Rectangle2D;
    
    public class test4 extends Frame
    {
    	public test4()
    	{
                    /* retrieve max window size */
                    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                    GraphicsDevice[] gs = ge.getScreenDevices();
                    GraphicsConfiguration [] gc = gs[0].getConfigurations();
                    Rectangle r = gc[0].getBounds();
                    setSize(r.width, r.height);
                    setVisible(true);
    
                    Rectangle useable = getBounds();
    		System.out.println("Size: " + useable.width + "x" + useable.height);
    		System.out.println("Offset: " + useable.x + "," + useable.y);
    	}
    
    	public void paint(Graphics g)
    	{
    	}
    
    	public static void main(String [] args)
    	{
    		new test4();
    	}
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Ignore me. I read extends JFrame.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by PhHein View Post
    Ignore me. I read extends JFrame.
    But that brings up a valid point: why use AWT (Frame) for your GUI library and not the more versatile and powerful Swing (JFrame)?

    If you do decide to switch to Swing, PhHein was going to tell you to do your drawing in a JPanel or JComponent's paintComponent override method and to add that component to the JFrame's contentPane (or something to that effect).

  4. #4
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    But that brings up a valid point: why use AWT (Frame) for your GUI library and not the more versatile and powerful Swing (JFrame)?
    If you do decide to switch to Swing, PhHein was going to tell you to do your drawing in a JPanel or JComponent's paintComponent override method and to add that component to the JFrame's contentPane (or something to that effect).
    I guess I'll do that. In my Frame-version I had a seperate method for paint() and update(). Both did totally different things; one painted the whole thing, the other only a counter. I took that functionality out of that and moved it to my main-loop. Cleaner anyway.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    I had a seperate method for paint() and update(). Both did totally different things; one painted the whole thing, the other only a counter. I took that functionality out of that and moved it to my main-loop. Cleaner anyway.
    That is special code only used for AWT. Swing has a cleaner way of doing custom painting and you would never override those methods.

    How do people keep finding those 10 year old examples withouth finding the new Swing examples? I suggest you start by reading the Swing tutorial for current examples.

Similar Threads

  1. Finding Open ports
    By bharanidharanit in forum Networking
    Replies: 6
    Last Post: 01-14-2009, 06:04 PM
  2. finding length on a number
    By thekrazykid in forum New To Java
    Replies: 8
    Last Post: 12-12-2008, 08:07 PM
  3. Finding the character set of a FILE
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 01-22-2008, 06:36 AM
  4. Finding largest no
    By bugger in forum New To Java
    Replies: 11
    Last Post: 11-29-2007, 12:49 PM
  5. Finding GCF in java
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 05:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •