Swing Mandelbrot Set - Threaded Painting

I'm trying to create a swing app that generates the mandelbrot set using an adjustable amount of threads. To update the image, I tried to create a javax swing timer, which apparently isn't working. If someone wants to look my code over and point out any mistakes (or possible optimizations) I'd appreciate it. (And for optimizing, I am aware I should short circuit my escape iteration testing for some cases per the wiki page on the subject).
Note: If you substitute my escape me method from the thread into the main class where the threads are generated, it produces the correct representation of the set.
Main class:
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Mandel {
     public static BufferedImage bnew;
     public static int tnum;
     public static void main(String[] args) {
          int width = 500;
          int height = 500;
          tnum = 5;
          JFrame mf = new MandelbrotFrame();
          mf.setSize(width, height);
          mf.setTitle("Mandel");
          mf.setLocationRelativeTo(null);
          mf.setVisible(true);
          mf.setDefaultCloseOperation(3);
class MandelbrotFrame extends JFrame {
     public MandelbrotFrame() {
          Container contentPane = getContentPane();
          MandelbrotPanel mp = new MandelbrotPanel();
          contentPane.add(mp, "Center");
class MandelbrotPanel extends JPanel implements ActionListener {
     public void paintComponent(Graphics g) {
          super.paintComponent(g);
          Mandel.bnew = new BufferedImage(getWidth(), getHeight(),
                    BufferedImage.TYPE_INT_ARGB);
          generate(Mandel.bnew);
          g.drawImage(Mandel.bnew, 0, 0, null);
          javax.swing.Timer t = new javax.swing.Timer(1000, new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                   repaint();
                   System.out.println("Works");
     public void generate(BufferedImage image) {
          int width = image.getWidth();
          int height = image.getHeight();
          int tnumber = (int) (height / Mandel.tnum);
          int n = 0;
          for (n = 0; n < Mandel.tnum - 1; n++) {
               new MandelPix(tnumber * (n), tnumber * (n + 1), width).start();
          new MandelPix(tnumber * n, height, width).start();
     private static final double XMIN = -1.5;
     private static final double XMAX = .5;
     private static final double YMIN = -1;
     private static final double YMAX = 1;
     @Override
     public void actionPerformed(ActionEvent arg0) {
          System.out.println("painted");
          repaint();
}Thread:
import java.awt.Color;
public class MandelPix extends Thread {
     public int start;
     public int limit;
     public int width;
     private int max_iteration = 1000;
     private static final double XMIN = -1.5;
     private static final double XMAX = .5;
     private static final double YMIN = -1;
     private static final double YMAX = 1;
     public MandelPix(int start, int limit, int width) {
          this.start = start;
          this.limit = limit;
          this.width = width;
     public boolean escapeMe(double x0, double y0) {
          double x = 0.0;
          double y = 0.0;
          int iteration = 0;
          while (x <= 2 && y <= 2 && iteration < max_iteration) {
               double xtemp = x * x - y * y + x0;
               y = 2 * x * y + y0;
               x = xtemp;
          if (iteration == max_iteration) {
               return true;
          return false;
     public void run() {
          for (int n = start; n < limit; n++) {
               for (int i = 0; i < width; i++) {
                    double x = (XMIN + i * (XMAX - XMIN) / width);
                    double y = (YMIN + n * (YMAX - YMIN) / 500);
                    if (escapeMe(x, y)) {
                         Mandel.bnew.setRGB(i, n, Color.black.getRGB());
                    } else {
                         Mandel.bnew.setRGB(i, n, Color.white.getRGB());
}

Changes Made.
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Mandel {
     public static BufferedImage bnew;
     public static int tnum;
     public static int width;
     public static int height;
     public static void main(String[] args) {
           width = 500;
           height = 500;
          tnum = 5;
          JFrame mf = new MandelbrotFrame();
          mf.setSize(width, height);
          mf.setTitle("Mandel");
          mf.setLocationRelativeTo(null);
          mf.setVisible(true);
          mf.setDefaultCloseOperation(3);
class MandelbrotFrame extends JFrame {
     public MandelbrotFrame() {
          Container contentPane = getContentPane();
          MandelbrotPanel mp = new MandelbrotPanel();
          contentPane.add(mp, "Center");
          Mandel.bnew = new BufferedImage(Mandel.width, Mandel.height,
                    BufferedImage.TYPE_INT_ARGB);
          mp.generate(Mandel.bnew);
class MandelbrotPanel extends JPanel implements ActionListener {
     public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.drawImage(Mandel.bnew, 0, 0, null);
     public void generate(BufferedImage image) {
          int width = image.getWidth();
          int height = image.getHeight();
          int tnumber = (int) (height / Mandel.tnum);
          int n = 0;
          for (n = 0; n < Mandel.tnum - 1; n++) {
               new MandelPix(tnumber * (n), tnumber * (n + 1), width).start();
          new MandelPix(tnumber * n, height, width).start();
          javax.swing.Timer t = new javax.swing.Timer(1000, new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    repaint();
                   System.out.println("Works");
     @Override
     public void actionPerformed(ActionEvent arg0) {
          System.out.println("painted");
          repaint();
}

Similar Messages

  • Speeding up an program to create a mandelbrot set

    Hi,
    For fun I decided to create code to paint the mandelbrot set onto a canvas using the Java2D API.
    Unfortunately, if I try making the canvas large (e.g. 800x600 pixels) refreshing is really slow.
    Is there any way to speed this up? Every time I move / resize / do anything, the screen repaints, taking all that time to render the graphic.
    Is there any way to paint to a file, and then when the image is done reloading, just load the image? Seems like it could be a little quicker once the image renders.
    Also, my code is basically:
    if (escapein == 0) {
      // the value never escapes orbit
      g2.setPaint(Color.BLACK);
      g2.drawLine(x,y,x,y);
    } else {
      // set the color to paint the pixel based on how many iterations it takes to escape
      g2.setPaint(new Color(0,0,(int) (((double) escapein / (double) 50) * 200) + 55));                   
      g2.drawLine(x,y,x,y);
    } Is there a quicker way to render the image than using the drawline method to draw each pixel?
    I know my question seems kind of open ended, but really I'm just looking for suggestions on what I can do next. It's taken a lot of work to figure out how to create this, but now that I have it, what can I do to improve it / speed it up?

    Use BufferedImage; see the javadoc.

  • What does, "swing is not thread safe." mean?

    can anyone explain what that means in detail?

    [Google can|http://letmegooglethatforyou.com/?q=swing+is+not+thread+safe+tutorial]
    For better response, you may wish to ask a specific question that's answerable without having to write a book chapter.

  • Setting Thread pool size

              Hi,
              I want to know if I set a system property "-Dweblogic.ThreadPoolSize", how will the
              WLS get to know that the pool size has been changed, at run time?
              E.g. I pass -Dweblogic.ThreadPoolSize=30 from the command-line. Then if I change
              the pool size to 40 at runtime, is there any event that I can fire for the change
              in property through APIs?
              Thnx in advance.
              Best Regards
              Ali
              

    Disregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.

  • Mandelbrot sets, 3D Mandelbox Zooms and Fractals

    I've recently been researcing complex fractals and happened to come accross this video
    and thought it would be an awesome addition to the iTunes visualizer.
    From what I can see on the current visualizer, Julia Sets are being used to render most of the visualizations.
    Would it be possible to make this happen with the right graphics card and computing power?
    And how do I get this suggestion presented to the wizards behind the iTunes Program?

    The video was not generated in real time. Deep iteration of the Mandelbrot and Julia sets involes a lot of calculations, but colour cycling of existing images can be quite pleasing in small doses. I'm not sure there is an easy translation into a visualiser that responds to the music, but you can drop a line to Tunes Feedback with your suggestion.
    tt2

  • Swing's Single Threading Rule - recipe please?

    Hi there,
    Some dust has been kicked up with JSR-296 being worked on, and we're seeing lots SwingUtilities.invokeLater advocates piping up on their blogs.
    Being from the very 'old school', and not so often delving into intense Swing-isms, I'd like to learn the "right way" of doing things, and also to which granularity these should be applied.
    For reference, take a look at this blog: http://weblogs.java.net/blog/cayhorstmann/archive/2007/06/the_single_thre.html
    Sadly enough, the "StillBad" example is precisely how we were taught in University long ago. Some clarification is required:
    --> Which methods do we need to wrap into invokeLater blocks precisely?
    from what I can gather, it seems that any function that affects GUI state needs to be wrapped as such? It sure seems a ginormous PITA to have to wrap every last "setText" in an invokeLater Runnable.... doesn't this incur a pretty considerable object instantiation overhead?
    What's the "right way"?
    Thanks!
    Alex

    You're referring to the setVisible call in the component's constructor? The Java STR page would seem to exact that no harm is done in doing so, since nothing takes place post-realization. This doesn't stand?
    Like I say, it depends on when your constructor is called. If it's called directly from main() then the setVisible() (but not the subsequent setText()) is ok.
    My point is that doing this sort of thing in a constructur is A Bad Idea; because, (a) in a constructor you've no idea if you're being called at the start of the main() method or if you're being called way downstream by another bit of UI or whatever, and (b) it pre-empts what the caller is planning to do with the object - imagine creating a JPanel which went and found a component in the hierarchy and added itself - hey, I wasn't going to put it there - and whilst it's a reasonable argument that you're not likely to do much else with a frame other than display it, there may well be things you want to do before displaying it.
    So, if we lose the line that realizes the component, we not only get a more usable and predictable constructor (remember polymorphism: a JFrame doesn't make itself visible when it's constructed; yours shouldn't diverge dramatically from that behaviour - it looks like a duck but it doesn't quack like a duck) but we also lose the line that causes everything downstream to be thread critical.
    In a main method, I've never once put my initial UI constructing code, from the frame constructor to the pack()/setVisible() calls on the EDT via SwingUtilities.invokeXxx(). And I've never encountered a problem.
    Yup, that's what the documentation is saying: that's not going to cause issues. The confusing bit here is that the OP's written a constructor that looks like a 'typical'* main() method :)
    Like I say, seeing as there's only a very short and transient period where working off the EDT is valid, it's generally best to make it wholly unconfusing and do 100% of the Swing stuff on the EDT.
    * in tutorials at least

  • Swing isn't thread safe, what about AWT?

    Since Swing isn't really thread safe what does that mean for AWT? Is AWT thread safe? Also if it is doesn't that mean one should use AWT over Swing since AWT is thread safe?

    Trizi wrote:
    jverd wrote:
    Trizi wrote:
    [http://forum.java.sun.com/thread.jspa?threadID=5282846&tstart=0|http://forum.java.sun.com/thread.jspa?threadID=5282846&tstart=0]
    There ya go duffy the hom^oYou say that is if being gay were a bad thing. So, besides being an obnoxious fuckhead, you're also a homophobic troglodyte? Man your fiancee must be a real winner to have picked you. My guess is that she's either a sheep, a blow-up doll, or someone you've got bound and gagged in your basement.Now from what everyone is saying that I don't have anything original...
    You don't either, too much "Silence of the Lambs" maybe?Dude, try speaking English.
    By the way, I am sure if I was a troglodyte I would be in a museum, also I have homosexual friends, sorry not homophobic, I just found a good ting to his name and figured I'd exploit it.. Just like I'm exploiting your pathetic intelligence.You really need help if you think the above makes any sense or any point.

  • Swing adf set db credential from java

    Hi!
    I wrote a program on Swing adf using standart JDeveloper jdbc connection.
    Now I whant install my programm to client. But jdbc url with credential store in standart adf xml configuration files.
    I whant that than user start programm first them input connection attributes ( host,sid,user,password), and then programm initilize all View and Control.
    I I was searching answer in google,forums.oracle.com, jdeveloper books and not found answer.
    But problem often is repeated, I think answer must be included into JDeveloper help book.
    My main method with init context
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception exemp) {
    exemp.printStackTrace();
    try {
    JUMetaObjectManager.setErrorHandler(new JUErrorHandlerDlg());
    JUMetaObjectManager mgr = JUMetaObjectManager.getJUMom();
    mgr.setJClientDefFactory(null);
    BindingContext ctx = new BindingContext();
    HashMap map = new HashMap(4);
    mgr.loadCpx("view.DataBindings.cpx", map);
    final FormMain frame = new FormMain();
    frame.setBindingContext(ctx);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
    frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width) {
    frameSize.width = screenSize.width;
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);
    } catch (Exception ex) {
    JUMetaObjectManager.reportException(null, ex, true);
    System.exit(1);
    }

    May be anybody know how to create configuration on java for swinf ADF, without xml files?

  • Setting Thread's priority

    What is the best way to use thread's setPriority method? from it's run method using this or when i create its instance or in its constructor (or other)?
    Thanks,
    snayit

    Unless, of course, you are implementing my proposed extension to the Runnable interface ... TheSameThingWeDoEveryNightPinkyTakeOverTheWorldRunnable.
    � {�                                                                                                                                                                                                                                                                                                                                   

  • Setting Thread Local Area (TLA)

    i am getting this error "OutOfMemoryError: getNewTla". so i want to set TLA size. As explained in this url : https://blogs.oracle.com/pa/entry/error_java_lang_outofmemoryerror_getnewtla .
    But i dont know where do i have to add " -XXtlasize:min=8k,preferred=128k " . Please help me with this in detail.
    PS: I want to do these changes in our planning server.
    Thanks,
    Abhishek

    Windows? running as a service? if so then go to regedit
    HKEY_LOCAL_MACHINE\SOFTWARE\Hyperion Solutions\Planning0\HyS9Planning
    Add a new JVMOption with a number one after the last
    so say the last one is JVMOption43
    Add JVMOption44
    with a value of -XXtlasize:min=8k,preferred=128k
    Edit JVMOptionCount and increment by decimal 1.
    Restart planning.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • My Xorg looks like the Mandelbrot Set. What does yours look like?

    Seriously.  ATI needs to stop sucking at life and make drivers that don't do this shit.  I've been wrestling with this on and off for weeks and this is the fruit of my efforts.
    edit: before someone asks, I am using an HD 4870 with the proprietary drivers.
    Last edited by tehfishman (2009-10-22 21:15:17)

    eldragon wrote:suddenly, the 500ish fps in glxgears i get with the intel graphics arent as bad
    Yep, at least you get to RUN glxgears .
    *looks fondly on his laptop's nVidia Geforce 9300M*

  • In this case, can I modify swing GUI out of swing thread?

    I know the Swing single thread rule and design (Swing is not thread safe).
    For time-consuming task, we are using other thread to do the task and
    we use SwingUtilities.invokeAndWait() or SwingUtilities.invokeLater (or SwingWorker) to update Swing GUI.
    My problem is, my time-consuming task is related to Swing GUI stuff
    (like set expanded state of a huge tree, walk through entire tree... etc), not the classic DB task.
    So my time-consuming Swing task must executed on Swing thread, but it will block the GUI responsivity.
    I solve this problem by show up a modal waiting dialog to ask user to wait and
    also allow user to cancel the task.
    Then I create an other thread (no event-dispatch thread) to do my Swing time-consuming tasks.
    Since the modal dialog (do nothing just allow user to cancel) is a thread spawn by
    Swing event-dispatch thread and block the Swing dispatch-thread until dialog close.
    So my thread can modify Swing GUI stuff safely since there are no any concurrent access problem.
    In this case, I broke the Swing's suggestion, modify Swing stuff out of Swing event-dispatch thread.
    But as I said, there are no concurrent access, so I am safe.
    Am I right? Are you agree? Do you have other better idea?
    Thanks for your help.

    If you drag your modal dialog around in front of the background UI, then there is concurrent access: paint requests in your main window as the foreground window moves around.

  • Trying to understand "thread-safe" w/ swing components

    The other day there was a big hullabaloo about some code I posted because I was calling JLabel.setText from a thread that wasn't the ui thread. On the other hand, this thread was the only thread making changes to the JLabel. My understanding is that in any kind of multi-threaded system, if you just have 1 writer / changer, then no matter how many readers there are, this is thread-safe. So why what I was doing not thread safe?
    Second question - JLabel.setText() is essentially setting data in the model for JLabel, which then gets picked up and displayed the next time the GUI thread paints it. So if it's not safe to update a JLabel's model, I assume its never safe to update any data that also is being displayed visually. So for instance, if I was showing some database table data in a JTable, I should do the update in the UI thread - probably not. But what is the distinction?
    Third question - what swing components and what operations need to be run on the UI thread to call your program "thread-safe". Validate? setSize()? setLocation()? add? remove? Is there anything that can be called on swing components from a non-ui thread?
    Edited by: tjacobs01 on Nov 2, 2008 8:29 PM

    tjacobs01 wrote:
    My understanding is that in any kind of multi-threaded system, if you just have 1 writer / changer, then no matter how many readers there are, this is thread-safe. So why what I was doing not thread safe?This is not true. As I mentioned in that hullabaloo thread, the Java Memory Model allows threads to cache values of variables they use. This means that values written by one thread are not guaranteed to ever be visible to other threads, unless you use proper synchronization.
    Take the following example:
    import java.util.concurrent.TimeUnit;
    public class ThreadExample {
        static class Foo {
            private String value = "A";
            public String getValue() {
                return value;
            public void setValue(String value) {
                this.value = value;
        public static void main(String[] args) {
            final Foo foo = new Foo();
            Thread writer = new Thread() {
                @Override
                public void run() {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                        foo.setValue("B");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
            Thread reader = new Thread() {
                @Override
                public void run() {
                    try {
                        TimeUnit.MINUTES.sleep(1);
                        System.out.println(foo.getValue());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
            writer.start();
            reader.start();
    }Here two different threads both access the same Foo instance, which is initialized with a value of "A". One thread, the writer, sleeps one second, and then sets foo's value to "B". The other thread, the reader, sleeps one minute (to avoid race conditions) and then prints foo's value to System.out. It may seem obvious that the reader thread will read the value "B", but this is in fact not guaranteed to be true. The reader thread may never see the value that was written by the writer thread, so it may very well read the old value "A".
    (If you run the code you will probably see "B" printed out, but again, this is not guaranteed behavior.)
    A simple way to fix this is to synchronize access to the mutable state that the two threads share. For example, change the class Foo to
        static class Foo {
            private String value = "A";
            public synchronized String getValue() {
                return value;
            public synchronized void setValue(String value) {
                this.value = value;
        }It's for this same reason that you often see the use of a volatile boolean as a control flag for stopping threads, rather than a plain old boolean. The use of volatile guarantees that the thread you want to stop actually sees the new value of the flag once it has been set by another thread.
    Here is an article that touches some of this stuff:
    [http://www.ibm.com/developerworks/java/library/j-jtp02244.html]
    I also highly recommend the book "Java Concurrency in Practice" (one of the authors of which, David Holmes, sometime hangs out on the Concurrency forum here, I believe).
    Edited by: Torgil on Nov 2, 2008 9:01 PM

  • NullPointerException in BasicTableUI - Table updated in Swing worker thread

    I am getting following exception while updating a table :-
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1141)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1051)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
    at javax.swing.JComponent.paintComponent(JComponent.java:541)
    at javax.swing.JComponent.paint(JComponent.java:808)
    at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4771)
    at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4724)
    at javax.swing.JComponent._paintImmediately(JComponent.java:4668)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4477)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run (SystemEventQueueUtilities.java:117)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy (EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy
    (EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    Since swing is not thread safe the table is updated in a swing worker thread. This should ensure that all gui updates are scheduled in the main event dispatching thread. Following is that code :-
    SwingWorker sw = new SwingWorker() {
    public Object construct()
    try{
    _myTable.updateUI();
    return null;
    }catch(Exception e){
    return null;
    public void finished(){
    sw.start();
    Inspite of doing these i am getting these exceptions.

    try using javax.swing.SwingUtilities.invokeLater(Runnable doRun)

  • The Single Threaded Nature of Swing

    I am designing a program that uses the basic <i>Model View Controller</i> design pattern. The controller allows you to manipulate the <i>Model</i> and the <i>Views</i> then display a graphical representation of the <i>Model</i>.
    Any way I want to have several different, independent <i>Views</i> of my <i>Model</i>. So I thought; well since the <i>Views</i> are only dependent on the <i>Model</i> I should be able to have the <i>Model</i> raise an event to alert the <i>Views</i> to update their drawing appropriately. Naturally since all the <i>Views</i> are independent I would like them to draw in their own threads, but since Swing is not thread safe it seams that i wont be able to do that.
    As a potential solution I am considered having each <i>Views</i> first create a graphics object that has all the new drawing information, then make a call to repaint through Swings Event Dispatch Thread and and have the component paint method simply BLIT from the pre-rendered graphics object into the graphics Object passed in the paint method. This has the advantage of allowing all the <i>Views</i> to do their drawing code concurrent;y and keep the <i>Controller</i> portion responsive since the even dispatch thread will only have to perform a very simple operation for repaints, however since i have no guarantee as to when the Event Dispatch Thread will actually get around to drawing them I winder if latency will be an issue.
    Non the less I can't help but think that in such a situation it would be safe to multi-thread the drawing. I would like to know if any body else has had to do something similar and what kind of approach they took.
    Flaws in my logic or comments regarding my current solution are also greatly appreciated.

    PCP wrote:
    Any way I want to have several different, independent <i>Views</i> of my <i>Model</i>. So I thought; well since the <i>Views</i> are only dependent on the <i>Model</i> I should be able to have the <i>Model</i> raise an event to alert the <i>Views</i> to update their drawing appropriately. Which is how Swing components work internally, so it all sounds good here.
    Naturally since all the <i>Views</i> are independent I would like them to draw in their own threads, but since Swing is not thread safe it seams that i wont be able to do that.It almost sounds as if you are confusing thread safety with not having the ability to interact with different threads. I'm no Graphics expert, but I think that Swing can handle all this as long as you handle Swing right: Do what you need to do in your separate threads, but just remember to only update Swing components on the EDT.
    As a potential solution I am considered having each <i>Views</i> first create a graphics object that has all the new drawing information, Or perhaps a graphics object derived from a BufferedImage object?
    then make a call to repaint through Swings Event Dispatch Thread and and have the component paint method simply BLIT from the pre-rendered graphics object into the graphics Object passed in the paint method. This has the advantage of allowing all the <i>Views</i> to do their drawing code concurrent;y and keep the <i>Controller</i> portion responsive since the even dispatch thread will only have to perform a very simple operation for repaints, however since i have no guarantee as to when the Event Dispatch Thread will actually get around to drawing them I winder if latency will be an issue.What is the frequency with which you are calling repaints? Have you tried this and found that Swing degrades your program's responsiveness? Again, I'm no graphics expert (where's Darryl, Hiwa, Morgalr when you need them?), but have you considered using active rendering instead of the typical passive rendering?
    Non the less I can't help but think that in such a situation it would be safe to multi-thread the drawing. I would like to know if any body else has had to do something similar and what kind of approach they took. Flaws in my logic or comments regarding my current solution are also greatly appreciated.Whatever happens, please let us know the outcome. Good luck!

Maybe you are looking for

  • How to add "Team leader" field in standard BPC security report

    BPC Expert, We are using BPC MS 5.0 version. There is a checkbox in the security setup to make someone a "Team Leader" when you add him/her to a team and this checkbox determines who can post data and who cannot.  When we run the user report we see w

  • How to remove all transitions?

    I used the automate to sequence with default transition. A few dozens of transitions were added to the sequence. How to remove all the transitions without deleting the sequence and starting from scratch please? Thanks in advance.

  • Time Stretch in Premier Elements 10 prevents moving of clips in Timeline

    Time Stretch in Premier Elements 10: after using it the Icon will not go away and I cannot now click-on and slide clips in the timeline. How can this be resolved?.

  • Importing existing libraries

    Hi All, I used to have a huge library already imported into lightroom while all the files stored on Drobo (external HD). At some point my main computer died (HD failure). After a full reinstall of the whole system from scratch, including LR I tried t

  • Streaming videos to PS3?

    I'm trying to figure out how to stream dvdmedia videos to a PS3. I downloaded and installed MediaLink and EyeConnect, but neither application recognizes the dvdmedia files. Any help would be greatly appreciated.