Move jLabel without pressing keys [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1
















This question is an exact duplicate of:




  • Swing Timers and Animations in JPanel

    2 answers




To skip reading, view my summary, otherwise here is my problem:



I would like to create an object (using a jLabel) move by itself without key inputs, and I do not know how to do this. For example I want to make a person walk left, turn around at a certain point and walk back and repeat the process forever.



Needed:



I just need to know how to make a thread change the position of a jLabel and make it move around until I want it to stop. A link to any simple examples or questions on how to make a moving jLabel would also be suitable.



Summary:




  • I want to make a jLabel move in the background automatically "forever"

  • I think it needs to be a thread and timer, but I do not know how
    to make a simple coded example.



  • Code or links to good examples will be suitable


Thanks for looking at my question.










share|improve this question













marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 10:09


This question was marked as an exact duplicate of an existing question.














  • 1





    It is complicated without showing us what have you tried. I recomand you to write some code, where you try to move a jlabel. After that, try to make it to move random. And so on until you reach the final product. We are here to help you to find the problem in code, not to write code for you.

    – KunLun
    Nov 22 '18 at 9:53











  • Use a Swing Timer to drive the animation.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 9:58











  • Thanks, I will attempt it and post my solution.

    – Nicholas
    Nov 22 '18 at 10:09











  • But your question is too broad suggesting that you may be asking it at too early a stage. You should break your problem into smaller steps and then search, experiment and solve each individual step. If still stuck, come back with Minimal, Complete, and Verifiable example code and a much more specific question

    – Hovercraft Full Of Eels
    Nov 22 '18 at 10:11


















-1
















This question is an exact duplicate of:




  • Swing Timers and Animations in JPanel

    2 answers




To skip reading, view my summary, otherwise here is my problem:



I would like to create an object (using a jLabel) move by itself without key inputs, and I do not know how to do this. For example I want to make a person walk left, turn around at a certain point and walk back and repeat the process forever.



Needed:



I just need to know how to make a thread change the position of a jLabel and make it move around until I want it to stop. A link to any simple examples or questions on how to make a moving jLabel would also be suitable.



Summary:




  • I want to make a jLabel move in the background automatically "forever"

  • I think it needs to be a thread and timer, but I do not know how
    to make a simple coded example.



  • Code or links to good examples will be suitable


Thanks for looking at my question.










share|improve this question













marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 10:09


This question was marked as an exact duplicate of an existing question.














  • 1





    It is complicated without showing us what have you tried. I recomand you to write some code, where you try to move a jlabel. After that, try to make it to move random. And so on until you reach the final product. We are here to help you to find the problem in code, not to write code for you.

    – KunLun
    Nov 22 '18 at 9:53











  • Use a Swing Timer to drive the animation.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 9:58











  • Thanks, I will attempt it and post my solution.

    – Nicholas
    Nov 22 '18 at 10:09











  • But your question is too broad suggesting that you may be asking it at too early a stage. You should break your problem into smaller steps and then search, experiment and solve each individual step. If still stuck, come back with Minimal, Complete, and Verifiable example code and a much more specific question

    – Hovercraft Full Of Eels
    Nov 22 '18 at 10:11














-1












-1








-1


1







This question is an exact duplicate of:




  • Swing Timers and Animations in JPanel

    2 answers




To skip reading, view my summary, otherwise here is my problem:



I would like to create an object (using a jLabel) move by itself without key inputs, and I do not know how to do this. For example I want to make a person walk left, turn around at a certain point and walk back and repeat the process forever.



Needed:



I just need to know how to make a thread change the position of a jLabel and make it move around until I want it to stop. A link to any simple examples or questions on how to make a moving jLabel would also be suitable.



Summary:




  • I want to make a jLabel move in the background automatically "forever"

  • I think it needs to be a thread and timer, but I do not know how
    to make a simple coded example.



  • Code or links to good examples will be suitable


Thanks for looking at my question.










share|improve this question















This question is an exact duplicate of:




  • Swing Timers and Animations in JPanel

    2 answers




To skip reading, view my summary, otherwise here is my problem:



I would like to create an object (using a jLabel) move by itself without key inputs, and I do not know how to do this. For example I want to make a person walk left, turn around at a certain point and walk back and repeat the process forever.



Needed:



I just need to know how to make a thread change the position of a jLabel and make it move around until I want it to stop. A link to any simple examples or questions on how to make a moving jLabel would also be suitable.



Summary:




  • I want to make a jLabel move in the background automatically "forever"

  • I think it needs to be a thread and timer, but I do not know how
    to make a simple coded example.



  • Code or links to good examples will be suitable


Thanks for looking at my question.





This question is an exact duplicate of:




  • Swing Timers and Animations in JPanel

    2 answers








java multithreading timer jlabel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 9:44









NicholasNicholas

123




123




marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 10:09


This question was marked as an exact duplicate of an existing question.









marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 10:09


This question was marked as an exact duplicate of an existing question.










  • 1





    It is complicated without showing us what have you tried. I recomand you to write some code, where you try to move a jlabel. After that, try to make it to move random. And so on until you reach the final product. We are here to help you to find the problem in code, not to write code for you.

    – KunLun
    Nov 22 '18 at 9:53











  • Use a Swing Timer to drive the animation.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 9:58











  • Thanks, I will attempt it and post my solution.

    – Nicholas
    Nov 22 '18 at 10:09











  • But your question is too broad suggesting that you may be asking it at too early a stage. You should break your problem into smaller steps and then search, experiment and solve each individual step. If still stuck, come back with Minimal, Complete, and Verifiable example code and a much more specific question

    – Hovercraft Full Of Eels
    Nov 22 '18 at 10:11














  • 1





    It is complicated without showing us what have you tried. I recomand you to write some code, where you try to move a jlabel. After that, try to make it to move random. And so on until you reach the final product. We are here to help you to find the problem in code, not to write code for you.

    – KunLun
    Nov 22 '18 at 9:53











  • Use a Swing Timer to drive the animation.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 9:58











  • Thanks, I will attempt it and post my solution.

    – Nicholas
    Nov 22 '18 at 10:09











  • But your question is too broad suggesting that you may be asking it at too early a stage. You should break your problem into smaller steps and then search, experiment and solve each individual step. If still stuck, come back with Minimal, Complete, and Verifiable example code and a much more specific question

    – Hovercraft Full Of Eels
    Nov 22 '18 at 10:11








1




1





It is complicated without showing us what have you tried. I recomand you to write some code, where you try to move a jlabel. After that, try to make it to move random. And so on until you reach the final product. We are here to help you to find the problem in code, not to write code for you.

– KunLun
Nov 22 '18 at 9:53





It is complicated without showing us what have you tried. I recomand you to write some code, where you try to move a jlabel. After that, try to make it to move random. And so on until you reach the final product. We are here to help you to find the problem in code, not to write code for you.

– KunLun
Nov 22 '18 at 9:53













Use a Swing Timer to drive the animation.

– Hovercraft Full Of Eels
Nov 22 '18 at 9:58





Use a Swing Timer to drive the animation.

– Hovercraft Full Of Eels
Nov 22 '18 at 9:58













Thanks, I will attempt it and post my solution.

– Nicholas
Nov 22 '18 at 10:09





Thanks, I will attempt it and post my solution.

– Nicholas
Nov 22 '18 at 10:09













But your question is too broad suggesting that you may be asking it at too early a stage. You should break your problem into smaller steps and then search, experiment and solve each individual step. If still stuck, come back with Minimal, Complete, and Verifiable example code and a much more specific question

– Hovercraft Full Of Eels
Nov 22 '18 at 10:11





But your question is too broad suggesting that you may be asking it at too early a stage. You should break your problem into smaller steps and then search, experiment and solve each individual step. If still stuck, come back with Minimal, Complete, and Verifiable example code and a much more specific question

– Hovercraft Full Of Eels
Nov 22 '18 at 10:11












1 Answer
1






active

oldest

votes


















-2














Here is the solution



import java.util.concurrent.TimeUnit;
//Simple example of how to count to infinity. Same logic applies just the 'to do
//code' is different
public class moveObject extends Thread{
public void run() {
int count = 0;
while (true) {
TimeUnit.SECONDS.sleep(1);
//Make object walk or other to
//do code here for example:
System.out.print(count++);
}
}
}


The reason why it works, I am not to sure about. But it works :D






share|improve this answer



















  • 1





    (1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

    – camickr
    Nov 22 '18 at 16:34




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-2














Here is the solution



import java.util.concurrent.TimeUnit;
//Simple example of how to count to infinity. Same logic applies just the 'to do
//code' is different
public class moveObject extends Thread{
public void run() {
int count = 0;
while (true) {
TimeUnit.SECONDS.sleep(1);
//Make object walk or other to
//do code here for example:
System.out.print(count++);
}
}
}


The reason why it works, I am not to sure about. But it works :D






share|improve this answer



















  • 1





    (1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

    – camickr
    Nov 22 '18 at 16:34


















-2














Here is the solution



import java.util.concurrent.TimeUnit;
//Simple example of how to count to infinity. Same logic applies just the 'to do
//code' is different
public class moveObject extends Thread{
public void run() {
int count = 0;
while (true) {
TimeUnit.SECONDS.sleep(1);
//Make object walk or other to
//do code here for example:
System.out.print(count++);
}
}
}


The reason why it works, I am not to sure about. But it works :D






share|improve this answer



















  • 1





    (1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

    – camickr
    Nov 22 '18 at 16:34
















-2












-2








-2







Here is the solution



import java.util.concurrent.TimeUnit;
//Simple example of how to count to infinity. Same logic applies just the 'to do
//code' is different
public class moveObject extends Thread{
public void run() {
int count = 0;
while (true) {
TimeUnit.SECONDS.sleep(1);
//Make object walk or other to
//do code here for example:
System.out.print(count++);
}
}
}


The reason why it works, I am not to sure about. But it works :D






share|improve this answer













Here is the solution



import java.util.concurrent.TimeUnit;
//Simple example of how to count to infinity. Same logic applies just the 'to do
//code' is different
public class moveObject extends Thread{
public void run() {
int count = 0;
while (true) {
TimeUnit.SECONDS.sleep(1);
//Make object walk or other to
//do code here for example:
System.out.print(count++);
}
}
}


The reason why it works, I am not to sure about. But it works :D







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 12:36









NicholasNicholas

123




123








  • 1





    (1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

    – camickr
    Nov 22 '18 at 16:34
















  • 1





    (1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

    – camickr
    Nov 22 '18 at 16:34










1




1





(1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

– camickr
Nov 22 '18 at 16:34







(1-) You should not be using a Thread. Swing components should be updated on the Event Dispatch Thread (EDT). Read the Swing tutorial on Concurrency, As has already been suggestions you should be using a Swing Timer. The tutorial also has a suggestion on how to use the Swing Timer.

– camickr
Nov 22 '18 at 16:34







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents