0

I'll start by saying that i'm kinda new to Java, so if i'm doing something obviously wrong don't insult me please...

I am having trouble finding a way to display different images in different positions in the same JFrame/Canvas, I've tried using Graphics, but if I write it as public void run(Graphics g) then thread.start() will not recognize it as its run method and nothing will happen.

In summary I can't find a way to use thread's run method to diplay multiple different images in the same Frame, hope I've been clear enough (if not just ask me what I meant).

  • 1
    Welcome to Stackoverflow. Please show us your code or at least provide a minimal reproducible example (https://stackoverflow.com/help/minimal-reproducible-example) – D. Lawrence Feb 03 '20 at 14:43
  • 1
    How did you display one image in one position in the same JFrame/Canvas? – user253751 Feb 03 '20 at 15:09
  • Why do you want to use threads at all instead of main application thread? – hal Feb 03 '20 at 15:32
  • Because I've been requested to do so – Gaelik607 Feb 03 '20 at 15:51
  • *I am having trouble finding a way to display different images in different positions* - define "different positions". The basic approach would be to create an ImageIcon and then create a JLabel using this Icon and then add the label to the frame. You choose the appropriate layout manager to display each of the labels. – camickr Feb 03 '20 at 17:26
  • 1
    If you want to use Threads, then use a `Swing Worker`. The SwingWorker will make it easy to create the Thread and "publish" each image as you read it. Read the section frmo the Swing tutorial on [Tasks That Have Interim Results](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/interim.html) – camickr Feb 03 '20 at 17:26
  • Consider a thread safe `Model` that hold all the information that `View` needs. Have a thread or threads that modifies the `Model` and have `View` listen to changes in `Model`. See an example [here](https://stackoverflow.com/a/58528000/3992939) – c0der Feb 04 '20 at 07:57

0 Answers0