1

I'm making a generic, simple process scheduling simulator for demonstration/teaching purposes. It is an assignment for school. I am not asking for any code or anything, I have my process scheduling algorithm/s down and implemented but I am simply asking for a good method to demonstrate what's actually going on.

My first thought is to use javax.swing. I know it a little bit, enough for functionality but I do not think this will provide me with the most informative method of demonstrating process scheduling.

The deadline for my project is soon approaching and I've only been reading up on java.awt (GraphicsEnvironment) and javax.swing. If there is something perhaps easier (or more effective) you could recommend, please do so. I am open to basically anything.

Tutorial video/s or guides would be really helpful as well.

Thanks,

chickeneaterguy

EDIT: I guess I wasn't completely clear. I am basically just looking for a way to clearly demonstrate the way processes are handled in their simplest form - with I/O time slices and CPU time slices along with priorities. I want to demonstrate it graphically rather than the users just looking at a bunch of different processes getting their allotted time.

@mKorbel - there's nothing hidden there. Just looking for a way to visually represent process scheduling.

@r0ast3d - thanks, I'll take a look.

**EDIT2: This is more along the lines what I'm looking to do (in Java) - http://www.youtube.com/watch?v=bta48Ix3t_Q (start watching at about 2 minutes in). I am going to want the data to correspond with what's happening in the code, so it won't be hard-coded images. Would my best bet be doing something like an applet?**

snotyak
  • 3,709
  • 6
  • 35
  • 52
  • please can you translate what's hidden `in the simple process scheduling simulator for demonstration` – mKorbel Nov 18 '11 at 06:25
  • When you say graphics do you mean charts ? have a look at jfreecharts or other open source charting platforms to integrate in your app. – r0ast3d Nov 18 '11 at 06:34
  • I edited the original post. Thanks for the quick feedback. – snotyak Nov 18 '11 at 06:43

2 Answers2

2

If you have a working model, adding a suitable view using the Model–View–Controller pattern is a good approach, as discussed here. JFreeChart works well with MVC, and here's a related example.

Do you think using applets would be a good approach to doing this?

Rather than an applet, I would create a regular application and distribute it using . This related simulation contrasts the two approaches in a hybrid. It also demonstrates using javax.swing.Timer for simple animation such as shown in the video.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks, something dynamic would certainly be beneficial here! :) – snotyak Nov 18 '11 at 17:32
  • I've looked into this. Maybe not in enough depth, but I'm looking for something more similar to what I added in the OP (youtube video). Actually, something like that Youtube video would be perfect. Do you think using applets would be a good approach to doing this? – snotyak Nov 19 '11 at 12:53
  • This looks very helpful! I am liking this method. I'm relatively new to Java and I haven't made any applets yet. I just kind of assumed if I took the applet route, I'd need to make it web-based. Thanks for this! :D I won't certainly use this method (though it is highly likely that I will) so I won't set your answer as the accepted one, just because I'm still seeking options. – snotyak Nov 19 '11 at 19:40
1

Given your side condition of not having much time, I would go a different way. You won't need real-time data as thread-scheduling is typically something in the millisecond area. Even if you slow down the singular threads by Thread.sleep() you will still get countless taskswitches within one second.

If you can agree on that assumption, you will be much better off (at least given the effort required) to dump all your data to a comma seperated file, opening that with excel and visualize it using an excel chart.

If you can't live with the assumption (because your simulator slows down everything a lot and real time info matters to your presenation) the least-cost solution will be Textareas in a JFrame this looks (somewhat similar) like this:

// create a JFrame
JFrame frame = new JFrame();
// A Textarea allows you to store multiple lines
JTextArea area = new JTextArea();
// put the area onto the Frame
frame.add(area);
// set initial size in width, height
frame.setSize(800, 600);
// make frame initially visible
frame.setVisible(true);
do {
  // actualize the frame every second
  Thread.sleep(TimeUnit.SECONDS.toMillis(1));
  // getYour text provides the displayed text, something like:
  // "Thread1 sleeps \n Tread2 is active" 
  // where \n leads to a new line in the area
  String text = getYourText();
// put your termination condition in here
} while (simulation.isRunning());
// this stops the GUI and removes the JFrame afterwards
frame.dispose();
Jonathan
  • 2,698
  • 24
  • 37
  • Like you said, this is probably the easiest method but I think I can pull off more than this. Thanks. – snotyak Nov 18 '11 at 17:32
  • Although what's above is a GUI, I'm looking for something more along the lines of animation related. Pretty much exactly what the youtube video in the OP has. Do you think Applets would be a good alternative? – snotyak Nov 19 '11 at 12:55