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 / First Aid / March 2004

Tip: Looking for answers? Try searching our database.

createImage is not on the screen

Thread view: 
Qu?bec - 17 Mar 2004 14:21 GMT
I wish you are not frustratedhas I am ;-),

In the 1.1.8 docs
createImage
"Creates a graphics context for this component. This method will return null
if this component is currently not on the screen."

Jean  Don Quichotte

=====================================================================
/*<applet codebase="."  code="ReturnNull" width=400   height=200 ></applet>
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class ReturnNull extends java.applet.Applet {

 Image offImage,i;

Dimension dimension = getSize();
   int abswidth = dimension.width;
   int absheight = dimension.height;
Graphics offG;

 public void init () {

   int[] pixels = new int [abswidth * absheight];
   int c;
   double radianConversion = (0.45 * Math.PI / 180.0);
   for (int index = 0, y = 0;y < absheight / 4;y++) {
     c = (int)(Math.abs (Math.sin((y + absheight) * radianConversion)) *
255);
     for (int x = 0;x < abswidth;x++) {
       pixels[index++] = ((c << 24) | (c << 16) | (c << 8) | 255);
     }
   }
   i = createImage (new MemoryImageSource (
         abswidth, absheight / 4, pixels, 0, abswidth));

System.out.println (1);  //prints

   offImage = createImage (abswidth, absheight / 4);
<=================================

System.out.println (2);   // dont prints

   offG = offImage.getGraphics();

   repaint();

 }
 public void paint (Graphics g) {
   g.drawImage(offImage, 0, 3*absheight / 4, this);

 }
}
Qu?bec - 17 Mar 2004 15:12 GMT
                                                   Why is it not on the
screen?
Chris Smith - 17 Mar 2004 16:01 GMT
Québec wrote:
> Why is it not on the
> screen?

When you first create a component, it's not actually displayed on the
screen yet.  You get a certain amount of time to customize its
attributes before it is shown to the user.  That's what's meant by "The
return value may be null if the component is not displayable" in the API
documentation.  I don't know where you got the phrase "not on the
screen"... that's far less clear than what the documentation really
says.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Andrew Thompson - 17 Mar 2004 15:51 GMT
On Wed, 17 Mar 2004 08:21:14 -0500, Québec wrote:

> In the 1.1.8 docs
> createImage
> "Creates a graphics context for this component. This method will return null
> if this component is currently not on the screen."

There are a number of reasons things can fail.
That is _one_ of them.

> import java.awt.*;
> import java.awt.event.*;
[quoted text clipped - 27 lines]
>
>     offImage = createImage (abswidth, absheight / 4);

   offImage = createImage (abswidth, absheight / 4);
// this also prints..
java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
       at
java.awt.image.DirectColorModel.createCompatibleWritableRaster(Direct
ColorModel.java:999)
       at
sun.awt.windows.WComponentPeer.createImage(WComponentPeer.java:483)
       at java.awt.Component.createImage(Component.java:2957)
       at ReturnNull.init(ReturnNull.java:31)
// ***** THis is telling you, at line 31, that
// you are passing illegal arguments, and it is
// even telling what about them is illegal
// either width or height is < 0 ..
// I will leave it as an exercise for the reader to
//  a) discover what values are being passed
//  b) fix the error
//  c) learn how to read the Java Console/CLI where these
//      messages appear!!
     

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Qu?bec - 17 Mar 2004 23:13 GMT
When I was talking about making thing fixed I was thinking about relative to
the applet size.... at least.
I have only one label to put on. I use it because it permits me to create an
emboss text in 1.1.8
So, I need to create a Lyout Manager.

Don Quichotte in progress

========================

The 1.1.8 appletviewer does not gives these informations.
>java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0

I will use it as a debugger from now on.

================
Winhelp doc by Frank Allimant jdk1.1.8 for
Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the
US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
========================
Class java.awt.Component
public Graphics getGraphics()
Creates a graphics context for this component. This method will return null
if this component is currently not on the screen.
Andrew Thompson - 18 Mar 2004 05:42 GMT
On Wed, 17 Mar 2004 17:13:53 -0500, Québec wrote:

> When I was talking about making thing fixed I was thinking about relative to
> the applet size.... at least.
> I have only one label to put on. I use it because it permits me to create an
> emboss text in 1.1.8
> So, I need to create a Lyout Manager.

> The 1.1.8 appletviewer does not gives these informations.
>>java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0

My apologies!  I was using the applet viewer
provided by Sun (albiet from a much later
java version) myself, but it certainly explains
why you did not report those errors if they
did not appear for you.

Is that what you are saying?

> I will use it as a debugger from now on.

'It' 1.1.8?

No, please.  If it is not giving detailed
and useful messages, update to a Java version
from _this_ millennium!  1.1.8 is _way_ old!

> ================
> Winhelp doc by Frank Allimant jdk1.1.8 for

> Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
> Java is a trademark or registered trademark of Sun Microsystems, Inc. in the
[quoted text clipped - 6 lines]
> Creates a graphics context for this component. This method will return null
> if this component is currently not on the screen.

But.. I am still not sure we are on the same wavelength,
that is saying WinHelp..  There is no mention of the
print out of '1' by your applet.

When I run your applet example in TextPad (ctrl 3)
I get the applet viewer and a DOS window in the
background.  The '1' prints in the DOS window,
then the stack trace I mentioned, it is, literally..

"
1
java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
       at
java.awt.image.DirectColorModel.createCompatibleWritableRaster(Direct
ColorModel.java:999)
"

Are you saying you do not see that on your machine?

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Qu?bec - 18 Mar 2004 12:37 GMT
> > I will use it as a debugger from now on.
>
> 'It' 1.1.8?
No.:  I will use 1.4.2 I have the twi of them.

The double buffer works nice and the funny applet too will be on the web
someday.
http://www.jeanpierredaviau.com/Class/Applets.html
The Label too.  I found a RowLayout in my notes that I included in a
BorderLayout using a Panel. Fine.

I found using DirectColorModel as a parameter for
i = createImage (new MemoryImageSource (
         abswidth, absheight / 4, new DirectColorModel((255 << 16) , (255
<< 8), 255, (255 << 24)), pixels, 0, abswidth));
  makes quite a difference in 1.1.8

> > ================
> > Winhelp doc by Frank Allimant jdk1.1.8 for
the winhelp version of the Sun's doc, here:
http://www.allimant.org/javadoc/javadoce.html

> There is no mention of the print out of '1' by your applet.

Yes my  1  is printed by 1.1.8

> java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0

Yes. It is printed by my 1.4.2

> When I run your applet example in TextPad (ctrl 3)
I am using EditPlus 2

>from _this_ millennium!  1.1.8 is _way_ old!

Yes, I would prefer using 1.4.  My problem is the 65 megs of Sun download of
JRE 1.4

I was not believing in fast download web design, and small plugins.  I must
be getting old.  I see myself 'zapping' any slow websites or plugin dowloads
has Real Player, Flash, etc. Canned design in steel or grids.  Canned
thoughts. All the same lookin. Sunsets fullfill my saoul and all the rest
seems uninteresting. What will it be in ten years? If I still can think.
The I (57) and is gang (baby boomers) will be the clients of the next 20
years.... probably....

The download of the JRE only (PLUGINj2re-1_4_2_03-windows-i586-p.exe  ) is
15 Megs. But I needed to log on has a developper using password etc.  Sun
does not care.... of the user I think. There they complain with Microsoft
and tries to force the users at a  65 Megs download. Thats almost windows
2000 size. But the cable, big machines. We dont need all this.  Anyway, I
wont make money out of that, I mean out of controversy.
Putting it on my web sites, I would have to switch to another bracket of
prices with my provider and pay 100$ a year more for the sake of art.

                                                                   Blah,
thats all folks,

Jean

==========================
http://www.jeanpierredaviau.com/feedback.htm


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.