here onclick of any button iam validating accordingly and showing messagdialogue box with some text.
onload of application the background color is showing gray, after clicking OK button in dialog box only that part of message box area showing white.
if i given showMessageDialog(null, text); the alert box is showing in the center of window to avoid that one i had given "this" as first argument in showMessageDialog();
Ah yes. My mistake. The rectangles are wrong; they should be as follows:
Also, I noticed you're calling super.paintComponents from paintComponent. Surely that s is wrong.
Joined: Oct 12, 2007
It is extremely working well, thank you alot I have small problem while drawing lines, iam trying to draw slowly by using Threads, can you please let me know how i can proceed ,
I tried with Runnable interface but iam not successed, can you please give some code snippet to how i can follow.
When working with threads and Swing, use SwingWorker. In short:
One warning: the SwingWorker may gather objects sent by multiple calls to publish. For instance, when you called publish(b1) and publish(b2, b3), the List in process may contain only b1, only b2 or b3, or all three.
In your case you could try this as follows:
- use Rectangle as B
- in doInBackground, you loop for the length of your line
- for each loop iteration, you create a new Rectangle that represents the part that will already be drawn
- you then publish that Rectangle
- in process, you take the last element which represents the last line piece (the other ones will be discarded)
- you replace the last element of lines with that element
- you repaint
In (semi-pseudo) code, for right only:
How it's called:
Note that you will need to disable and re-enable your buttons, or you will have race conditions.
You can make one SwingWorker class for each direction, or maybe make this one work for all directions.
As a final exercise, you can make it a bit more efficient: instead of creating new Rectangles each time, only publish the changed width / height, then update the Rectangle in lines instead of replacing it. Your SwingWorker class would extend SwingWorker<Void,Integer>.