Problemy a ako na ne
Rozhodol som sa sem vlozit niektore celkom zaujimave prispevky z
jedneho listervera. Mozno sa z nich nieco naucite.
Texty su v povodnom zneni. Myslim, ze nie je vhodne,
ani nutne prekladat ich do slovenskeho jazyka.
Problem s obrazkami
>... If all images are not loaded when you start repainting
>the screen, then you don't get anything on the screen but an error.
Try using the Mediatracker first, and them, after all is loaded, repaint the
screen with the start images and start the applet :
import java.awt.*;
public class dance extends java.applet.Applet implements Runnable
{
// MediaTracker declaration
MediaTracker theTracker;
Image The_Bear;
int Random_Bear;
bear[] dancer= new bear[5];
Thread runner;
String[] The_Dirs={"blue/","green/","orange/","yellow/","pink/"};
int Random_Time;
int x1;
int y1=2;
public void init()
{
// Initialize tracker
MediaTracker theTracker = new MediaTracker(this);
for(int variable=0;variable<5;variable++) // Load up each of the 5 bears
{
dancer[variable] = new bear();
for(int index=0;index<9;index++) // Load 9 images for each bear
{
// use a try to be sure everything is loading ok
try {
dancer[variable].Dance_Step[index]=
getImage(getDocumentBase(),The_Dirs[variable] +
dancer[variable].File[index]);
} catch (Exception e1) {
System.out.println(e1);
}
// Add image to the tracker
theTracker.addImage(dancer[variable].Dance_Step[index], index);
// Wait for loading and check if loaded
try {
theTracker.checkID(index, true);
theTracker.waitForID(index);
} catch (Exception e2) {
System.out.println(e2);
}
}
// Below line calculates top left x value for each bear,
// top left y is the same for all bears
dancer[variable].TopX=variable*55;
}
} //Init done!
import java.awt.*;
public class bear extends dance
{
String File[]
={"bear1.gif","bear2.gif","bear3.gif","bear2.gif",
"bear1.gif","bear4.gif","bear5.gif","bear4.gif","bear1.gif"};
Image[] Dance_Step=new Image[9];
int Current_Step=0;
int TopX;
int BotX;
}
Dakujeme Mark Allen Framness.
trochu ina reakcia na problem s obrazkami
Load the image using getToolkit().getImage(...)
Image fold = getToolkit().getImage("folder.gif");
and then display it.
Dakujeme Kavitha N.
Ako zobrazit obrazky v aplikacii
>Hi,
>
>I'm wondering how I could display an image of type gif/jpeg for stand
>alone applications? (I know how to do it for applets)
>
> Thanks
>
First, you need to create a panel of sometype, and open it on the
desktop. One way to do this would be by createing a new class which
extends Frame. Secondly, use the static method
Toolkit.getDefaultToolkit(), and then you can use the getImage() method
of the Toolkit class you just grabbed.
Dakujeme Craig Strickland za dobry napad.
Udalosti
> Hi,
> Does anyone know what Event gets posted and to which object when the
> user clicks in a window (i.e. Frame) to bring it to the front? I am trying
> to do extra processing anytime the user brings a new window to the front,
> but I can't seem to find which Event type to trap.
You can use MOUSE_ENTER. I put the following lines of code as the first
stmt in my handleEvent method to see what events are being handled:
if (isDebugOn) {
System.out.println("handleEvent(" + event.toString() + ")");
}
The isDebugOn boolean is set in the main method by passing in an
argument
like "-debug". So,
java APPLICATION -debug
would set isDebugOn to true.
Za radu dakujeme Dan Luevano
JDK versus VisualJava++
You have to choose, what you what more:
The complete control of the java-code you write or a good IDE.
If you want a easy to use tool for developing, a IDE like VJ++ is fine.
But there are some drawbacks with them.
The most importend is that tey have problems with using LayoutManagers, which are quite usefull for
platform-independend programming. The new JDK 1.1 isn't supported either!
VJ++ uses some ActiveX parts, that work only on MS Windows. You don't have control of that and on other platform your
program won't work!
So, my advice is:
Learn the complete Java with JDK1.1!
The bit more work you have with the programming of the GUI is worth the better control of the code and the better
platform independence.
Ma pravdu ten Dirk Hennig
Ako spustit aplet v nezavislom okne
>Hello...
>Does an applet Java can make a window independant of browser (not
>display in the browser but, just another window) ? I most capture
>UserID and Passwod like Netscape do when a password is required...So,
>does java allow to do this?
>Thanks
Check out documatation for the Frame class.
Za dobry tip dakujeme David Soroko.
Problem s polom
> Hi,
>
> When I run the following program both many[0].a and many[1].a are set to 2.
> Why isnīt many[0].a set to 1 and many[1].a set to 2 as expected?
> I would appreciate if someone could explain this to me.
>
> Daniel Johansson
>
> public class Test extends java.applet.Applet {
>
> Memory one = new Memory();
> Memory many[] = new Memory[2];
>
> public void init() {
>
> for (int i = 0; i < many.length; i++)
> many[i] = new Memory();
>
> one.a = 1;
> many[0] = one;
>
> one.a = 2;
> many[1] = one;
>
> for (int i = 0; i < many.length; i++)
> System.out.println(many[i].a);
>
> }
>
> }
>
> class Memory {
>
> int a;
>
> Memory() {
> a = 0;
> }
>
> }
It is important to understand that object arrays like many do
no contain objects but references/pointers to objects.
In your example many[0] and many[1] point to the same object, one,
so you get the same value for a.
Ma pravdu David Soroko, dakujeme.
Diskusia o modalnych DialogBox_och
> It's developers like you, who break the rules of the underlying
> window manager, that cause users like me to be mad at the window
> manager, but I guess I now know better. Why not just be happy with
> the machanisms of the window managers style. For instance, say I'm
> looking at your window, and your dialog pops up, then I get a beep
> from another window indicating someone is requesting a 'talk'
> conversation, So I want to click on that window and forget about your
> dialog for the time being. If you accomplish your goal that the
> mouse would be prevented from leaving your dialog (bad bad bad), then
> I would be locked into your egocentric application. I, as a user who
> has the capability to multitask my own brain, would be locked into an
> application which, not only breaks the rules of the underlying window
> manager, annoys me to the extent that I may not want to run your
> application again in the future.
I think a lot of it depends on the reason the dialog box popped up. If
it's in reaction to a caught exception, it may be sometthing that has to
be attended to or serious problems could result. I do agree that some
modal dialogs are irritating (especially in the Win95 environment, when,
say, a dialog is showing me the progress of a running process, and I
can't so anything else until it finishes). But even there, it depends on
the process. If it's a timing critical process, you don't want anything
to interrupt (although I suppose the argument could be made that a decent
OS would be able to properly handle things like that). I will admit
Win95 has been behaving itself a little better with regard to situations
like this, but it's still locked in the world of single users and single
tasking trying to emulate multitasking. :-)
Doug A. Bauman versus Brett W. McCoy
Moj applet blika!
>Hi all!
>
>Would anybody prompt to me why my Java applet shimmers sometime?
>This applet is on my home page also.
>Regards,
The problem with your homepage applet is called: "flicker". If you will
notice, the first few lines of your scrolling text are smooth and as more
lines are added you get more and more of this flicker, i.e. the shimmer you
talk about.
Flicker is a common problem in animations and can be solvedin a variety of
ways. For your applet you are probably going to have to resort to "double
buffering" as each frame redraws more and more of the entire applet (i.e.
you can not just isolate a part of your applet and redraw that part only, my
dancing bear applet, on the homepage below, uses this to eliminate the
flicker). Double buffering is a process where you draw two images at the
same time. The first image drawn off screen to an "off screen buffer" and
the second image to be drawn is the previously drawn buffer image
transferring to the screen. I have not yet used double buffering in any of
my applets so now I hand the thread off to a more capable java hack!!!!!
Dakujeme, Mark Allen Framness
A ako na to reaguje Brett W. McCoy? ...
> flicker). Double buffering is a process where you draw two images at the
> same time. The first image drawn off screen to an "off screen buffer" and
> the second image to be drawn is the previously drawn buffer image
> transferring to the screen. I have not yet used double buffering in any of
> my applets so now I hand the thread off to a more capable java hack!!!!!
Well, while denying any claims of being 'more capable', I have used
double-buffering. I don't have access to my specific code, but I can
upload something within the next day or so some code for
double-buffering, if someone else on the list doesn't do it first.
Basically, you create a Graphics object and an Image object as members of
your object (whether in an applet or a helper object), then create a
method called update(), and pass the Graphics object into your paint()
method, which directly paints onto the image rather than the Applet
window. Then you use drawImage() to draw the image onto the screen.
Liek i said, I have some specific code I wrote to do this which
illustrates this much better than I can describe it.
Moj applet blika - dvojite buffrovanie
Here are some more precise details of how I have used double-buffering:
I first have these as member variables in my applet class (they can be
private also):
protected Image imBuff; //for double buffering
protected Graphics grBuff; //prevents flickering
Then I have an update method for doing the operations offscreen:
public void update(Graphics g)
{
if(imBuff == null)
{
imBuff = createImage(size().width, size().height);
grBuff = imBuff.getGraphics();
}
//the following three lines ensure the foreground and background
//colors are correct
grBuff.setColor(getBackground());
grBuff.fillRect(0, 0, size().width, size().height);
grBuff.setColor(g.getColor());
paint(grBuff);
g.drawImage(imBuff, 0, 0, this);
}//end update()
Your paint() method is unaware of the offscreen image and graphics
buffer. I lifted this code right out of an object that makes text fade
from one to color to another, and I also used it in an object that
scrolls text.
Toto je dobreee, dakujeme ti Brett W. McCoy