-
Code to place a Jlabel on a Jpanel, at given coordinates...
Hello people,
This is definately the place for me, I've very new to programming!
I have some code that draws a circle on a drawingPanel, then a timer that will move the circle down a few pixels every second. That works fine but instead of drawing a circle at x = 150 y = 30 (or whatever) coordinates, I would like to place a Jlabel at those coordinates, that would then move down the screen like the circle did.
Basically, I just want to know what code to put on my "start" button to get the Jlabel on there!
I've read through these forums and have come up with nothing that can help me, probably because I need my hand holding! I don't understand much of this yet!
Any help would be very very much appreciated!
Here's what I have so far, just so you know:
Code:
private void cmdStartActionPerformed(java.awt.event.ActionEvent evt) {
x = 150;
y = 20;
int w = 30;
int h = 30;
panDraw.draw(cboShape.getSelectedIndex(), x, y, w, h);
txtRemaining.setText("until landing");
timer = new Timer();
timer.schedule(new LowerShip(),
0, //initial delay
1*1000); //subsequent rate
}
class LowerShip extends TimerTask {
int Height = 10;
public void run() {
for ( int Height=0; Height<10; Height++ ) {
x = 150;
y = y + 30;
int w = 30;
int h = 30;
panDraw.draw(cboShape.getSelectedIndex(), x, y, w, h);
txtTimeLeft.setText(" ");
txtTimeLeft.setText(9 - Height + " seconds");
txtHeightLeft.setText(" ");
txtHeightLeft.setText(67.5 - Height * 7.5 + " metres");
try {
Thread.sleep(1000);
} catch (InterruptedException e){
}
timer.cancel();
}
}
}
-
Do this:
Set your drawing panel's layoutmanager to null, create your label, add it to the panel with a null constraint.
For every tick invoke its setbounds(x,y,width,height) method and do a plain repaint() for the panel.
Set the button's visible property as appropriate.
Last edited by sjalle; 01-18-2006 at 07:31 AM.
eschew obfuscation
Similar Threads
-
By Chaitanya Marvici in forum ASP.NET
Replies: 6
Last Post: 07-21-2003, 09:15 AM
-
By Nelson in forum VB Classic
Replies: 0
Last Post: 08-02-2002, 09:33 AM
-
By Al Guten in forum .NET
Replies: 0
Last Post: 04-11-2002, 06:48 PM
-
Replies: 150
Last Post: 03-04-2002, 05:40 PM
-
By Robert G in forum .NET
Replies: 84
Last Post: 02-08-2001, 02:38 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks