Results 1 to 5 of 5
Thread: Finding where to draw
- 11-24-2009, 10:56 AM #1
Member
- Join Date
- Sep 2009
- Location
- Gouda, the Netherlands
- Posts
- 24
- Rep Power
- 0
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(); } }
- 11-24-2009, 11:05 AM #2
Ignore me. I read extends JFrame.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
-
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).
- 11-24-2009, 04:45 PM #4
Member
- Join Date
- Sep 2009
- Location
- Gouda, the Netherlands
- Posts
- 24
- Rep Power
- 0
- 11-24-2009, 05:55 PM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
That is special code only used for AWT. Swing has a cleaner way of doing custom painting and you would never override those methods.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.
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
-
Finding Open ports
By bharanidharanit in forum NetworkingReplies: 6Last Post: 01-14-2009, 06:04 PM -
finding length on a number
By thekrazykid in forum New To JavaReplies: 8Last Post: 12-12-2008, 08:07 PM -
Finding the character set of a FILE
By javaplus in forum Advanced JavaReplies: 1Last Post: 01-22-2008, 06:36 AM -
Finding largest no
By bugger in forum New To JavaReplies: 11Last Post: 11-29-2007, 12:49 PM -
Finding GCF in java
By lenny in forum Advanced JavaReplies: 1Last Post: 07-31-2007, 05:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks