Michael Dunn wrote:make a class (a very little class) - just a
frame and panel (for your drawing code).
make sure it demonstrates the same problem
then post that code.
Maneesh Godbole wrote:Check out https://coderanch.com/how-to/java/BackgroundImageOnJPanel
You can use the same approach to have your custom painting instead of the image
Tim Moores wrote:
Firstly,the first line of an output of the program below is The main thread dies here. Why it starting from there
Newly created threads #1 and #2 both sleep at the beginning, so it's natural to run the non-sleeping main thread. But even without that it's up to the JVM to schedule threads. You shouldn't expect thread X to start being executed before thread Y just because it was created earlier; it may work out that way (and probably will), but not necessarily so. You could insert print statements at the beginning of the run method to see when each thread starts to execute.
Second question, there are while(true) loop so, it should never end unless the exception is thrown but the program does not throws an exception. So, why it starts then executing this:new Thread (new SleepyThread(5, "1 ")).start();
I don't understand this question; can you rephrase it? What did you observe happening, and what were you expecting instead?
and the last question why it is doing more 2 thread than first is it because of the program says to or ... smth else?
Is it? It's pretty evenly distributed on my machine. Of course, thread #2 waits for a shorter time than thread #1 at startup, which explains the consecutive 2s at the beginning.
while(true){
try { Thread.sleep(500);; } catch (InterruptedException e){System.out.print("I was interrapted"); }
System.out.print(msg+" ");
}
Bobby Marvikuan wrote:Hello can anyone help with this code why the answer here is 17 but according to my logic it should be 8:( I am not getting that
Darryl Burke wrote:Why do you start the Timer inside a while(...) loop?
Darryl Burke wrote:From your question, I'm assuming that you already know how to zoom, just not how to animate it. Use a javax.swing.Timer and change the zoom level over a period of time, calling repaint() each time.
Darryl Burke wrote:From your question, I'm assuming that you already know how to zoom, just not how to animate it. Use a javax.swing.Timer and change the zoom level over a period of time, calling repaint() each time.