Avatar billede nickbuus Nybegynder
18. august 2000 - 17:17 Der er 5 kommentarer og
1 løsning

Call by reference problem (in english!)

I want to call a method in my main class from another class.
The problem is that I cannot create an instance of the main class because this will cause an
endless loop.
My code looks like this

I have a main class called \"Frame1\" which makes the connections to a synthesizer using the jdk1.3 midi class
playing notes from here is not a problem(I did this just to test that the connection did work)
Then another class called \"Piano\" draws the keyboard and controls the mouseactions then If
the keyboard is played by pressing the mouse button on the keyboard - the method \"On\" is
called in a new class called \"Key\". This method should somehow make a connection back
to the \"Frame1\" class which takes care of the midi connection.

Please help? I have a feeling that its some sort of call by reference that is needed??

Thanks

Nick

----- Original Message -----
From: Allen Wallis <allen@rrsg.ee.uct.ac.za>
Newsgroups: comp.lang.java.gui
Sent: Thursday, August 17, 2000 7:59 AM
Subject: Re: TRANSPARENT IMAGE


> Brendan DJ Murphy wrote:
> >
> > PLEASE PLEASE HELP.
> >
> > I am trying to print a solid white ring with a transparent \"hole\" in an
> > offscreen image.  I then wish to draw this offscreen image to a Canvas
> > so that I can still see through the hole and see the original canvas :
> >
> > // first, draw the full Disc in the offscreen image:
> >
> > g.setColor(Color.white)
> > g.fillArc(0,0,100,100,0,360)
> >
> > // then, draw a \"hole\" in the middle...
> >
> > g.setColor(Color.transparent)  // ....  if only !!! :-(
> > g.fillArc(25,25,50,50,0,360)
> >
> > and then copy this graphics object to the canvas so that you can still
> > see \"through\" the middle of the ring to the original contents of the
> > screen.
> >
> > OK,  this doesn\'t compile.  But there must be an easy way of doing it.
> > Are there any examples of source code where something similar has been
> > achieved.
> >
> > I\'ve tried playing with alpha values but if i set the alpha value of the
> > hole to transparent, it quite simply leaves the disc a full solid disc.
> >
> > I believe the tactic is to draw the hole in a unique colour, (eg
> > magenta) and then use an imagefilter to change magenta to transparent
> > before the final copy to the canvas.
> >
> > Does anybody have any working examples of how this is done?
> >
> > PLEASE PLEASE PLEASE help.
> >
> > regards
> > Brendan
> >
> > --
> > Brendan DJ Murphy
>
> Hi,
> I\'ve been having the exact trouble that you have in trying to use
> transparent colours to offscreen images. I think one of the problems in
> your example (that I had as well) is that when drawing in the
> transparent colour, if the colour is completely transparent, nothing
> will change - you will always see the white that you painted first. I
> then thought of using XORMode: by filling the area that you want
> transparent with a known colour (lets say pink), and then using
> g.setColor(Color.pink);
> g.setXORMode(transparent);
> g.fillOval...
> This should then replace the pink pixels with the colour specified by
> \"transparent\". I tried this, however the transparency did not work - the
> pixels were replaced by the colour specified by transparent - but minus
> the alpha value. I eventually gave up on trying. If you find out how to
> achieve this, please mail me the answer!
>
> But here\'s something that might help if you can use the BufferedImage:
>
> BufferedImage im = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_ARGB);
>
> This image should now be completely transparent to start with. Of course
> - I still don\'t know how to actually draw in a transparent colour, at
> least you have a transparent image to start with. This didn\'t really
> help me as I found that drawing a BufferedImage to screen took far
> longer than drawing a normal Image to screen.
>
> hope you come right
> cheers
> Allen
Avatar billede zaknafein Praktikant
18. august 2000 - 20:07 #1
Make the method \"final\", so that you don\'t have to instantiate the class to use the method:

Like the math.random object- u don\'t create an instance of the math onject, to use the random method;
Avatar billede zaknafein Praktikant
18. august 2000 - 20:08 #2
You always use call by reference in java!
Avatar billede lynggaard Nybegynder
19. august 2000 - 00:15 #3
Thats called making it \"static\" not \"final\" !
Avatar billede zaknafein Praktikant
19. august 2000 - 00:28 #4
Yes offcourse, i just let myself confuse with the term \"static\" in C++!!
Avatar billede nickbuus Nybegynder
03. september 2000 - 15:43 #5
Well zaknafeins answer was ok but you didn\'t reply with a \"svar\" - sorry then I cant give you the points - or can I? somebody please answer If theres something I\'m doing wrong here?

Nick
Avatar billede zaknafein Praktikant
03. september 2000 - 23:17 #6
You could just have asked me to post an empty asnwer, which you then can accept ;)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester