0

What's the better choice? For: Swing and AWT

I am asking this question because I am wondering what would save me more time.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Re. AWT/Swing. See [this answer](http://stackoverflow.com/a/6255978/418556) (& the rest of the Q&A). – Andrew Thompson Dec 15 '12 at 06:11
  • Absent clear criteria for _better_, this question is not constructive. For reference, [JMCAD](http://jmcad.sourceforge.net/index_us.shtml) uses Swing. – trashgod Dec 15 '12 at 13:07

4 Answers4

3

What's the better choice ? For: Swing and .awt

Swing is a more robust and powerful library for most purposes.

I am asking this question because I am wondering what would save me more time.

Save you more time in what way?

What actually is the thrust of this question?

Edit
You state:

I am making a CAD program, that's why I need to know.

I'm not sure that I'd be worried so much about "clearing vs. drawing on top" at this point and would be more worried about overall program design with good separation of logical entities. The graphics details can be tested and changed depending on the results of your testing, but more important is that you have a robust and flexible design, one that will allow you to plug in any type of graphics design.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
3

On-top of all the other comments;

Swing has a clever repaint manager which can be used to only repaint damaged areas of the screen, rather then need to repaint the whole screen.

Swing is also double buffered, which makes it's updates less prone to flickers.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

Generally speaking clearing and redrawing is the preferred approach. There are often visual bugs in programs that try to draw on top.

The typical use case of drawing on top is to eliminate some of the problems related to programs that have difficult to draw widgets (such as CAD programs with very intricate details with lots of features). However, even in these cases there is usually some way of avoiding drawing on top. For instance drawing the CPU intense widget to a buffer and then drawing the buffer whenever something not in that widget is changed.

CrazyCasta
  • 26,917
  • 4
  • 45
  • 72
  • so, you're saying that because programmers suck at their jobs, don't do it the efficient way? :) I agree, programmers cannot seem to make their code draw correctly, but is that enough of a reason to say don't do it at all? – Zagrev Dec 15 '12 at 06:27
  • @Zagrev I think a more accurate way of putting it is that it gets very complicated and is difficult for even the best of programmers to get right and that there are simple efficient alternatives (such as buffering the output). Also, I'm not sure whether it has so much to do with the quality of the individual programmers so much as the quality of the documentation they write. There may be certain cases where you must redraw (like for instance maybe if the window is resized or something) but these cases are generally not well documented. – CrazyCasta Dec 15 '12 at 09:31
  • I'll be glad to agree with that. – Zagrev Dec 16 '12 at 04:13
1

swing will save your more time than awt as all the code of components of swing are purely written in java whereas of awt code of components are written in native language that is other than java thus compilation time of awt is more than swing. Swing is best in case of time saving.

Abhishekkumar
  • 1,102
  • 8
  • 24