Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Applet size in Google Chrome issue:  (Read 1704 times)
0 Members and 1 Guest are viewing this topic.
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Posted 2011-10-19 03:54:59 »

Before I begin, I'm using Ubuntu 10.10.  This problem doesn't exist in Firefox, just in Chrome.  To check the width and height of the applet I've used these two methods:

1  
2  
3  
4  
5  
screenWidth = (int)getSize().getWidth();
screenHeight = (int)getSize().geHeight();
or
screenWidth = ((Dimension)getSize()).width;
screenHeight = ((Dimension)getSize()).height;


Even though the actual measurement of the applet is correct (set by the html code), screenWidth and screenHeight are always equal to 1000. 
Anyone else have this problem, or know of a work around?
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #1 - Posted 2011-10-19 04:27:21 »

JGO is just becoming my Rubber Duck Debugger   Grin  I figured out after submitting my question that maybe the init() was being ran before Chrome actually applied the size of the applet.  So I just added a componentListener to catch a resize event, and applied the values there too.

Edit:  I don't know why I didn't do this anyways... actually the importance was never stressed to me... but now it makes allowing the user to resize the applet (Ctrl + scrollwheel) even cooler.
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2011-10-19 05:15:14 »

Why do you cast at all in your code?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #3 - Posted 2011-10-19 05:23:05 »

Eclipse says that .getWidth and .getHeight return Doubles, screenWidth and screenHeight are ints, so I thought I had to.  As for the (Dimension), yea, I don't know.  I'm still new to Java.
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2011-10-19 05:45:53 »

getWidth(), getHeight(), getSize().getWidth(), and getSize().getHeight() all return ints.

Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #5 - Posted 2011-10-20 02:40:37 »

If I do this:
1  
int a = getSize().getHeight();

I get "Type mismatch: cannot convert from double to int"

... just sayin'.
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2011-10-20 04:26:45 »

Oh! Dimension has public int fields "width" and "height" but its getWidth() and getHeight() methods return doubles......strangest API I have ever seen.

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #7 - Posted 2011-10-20 12:01:57 »

java.awt.Rectangle is the same way - int fields but the getters for them return doubles.  Comes from the abstract classes they extend.  I think the design was to allow different subclasses to have different precision for the actual members (int, float, double, ...).
Offline theagentd
« Reply #8 - Posted 2011-10-21 10:47:09 »

It kind of does make it annoying to use them. Casting an int to a double only to cast it back down again isn't going to net you much performance, so the only thing you can save is memory usage. The whole thing is complicated to solve in the end. >_<

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!