표준 Java GUI 구성 요소를 사용하지 않고 자체 렌더링을 구현할 때 AWT 프레임과 Swing JFrame을 사용하는 것의 주된 차이점은 무엇입니까?EDT 외부 렌더링을위한 Swing/JFrame 대 AWT/Frame
이것은 이전 질문에서에 따라 수 있습니다 : AWT 대 스윙에
AWT custom rendering - capture smooth resizes and eliminate resize flicker
전형적인 논점 우리는 프레임을 사용하고 있기 때문에 적용하지 않는 것. 예를 들어 Heavyweight와 Lightweight가 창 밖으로 나옵니다 (JFrame은 Frame을 확장합니다).
따라서 가장 좋은 점은 의 경우 인 JFrame 또는 프레임입니까? 의미있는 차이가 있습니까?
참고 :이 시나리오는 EDT에서 렌더링이 바람직하지 않은 경우입니다.. EDT와 연결되지 않은 응용 프로그램 워크 플로가 있으며 EDT 외부의 필요에 따라 렌더링이 수행됩니다. 렌더링을 EDT와 동기화하려면 렌더링에 대기 시간이 추가됩니다. Frame 또는 JFrame 이외의 Swing 또는 AWT 컴퍼넌트는 렌더링하지 않습니다 (JPanel/Component/등).
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;
import java.awt.Frame;
public class SmoothResize extends Frame {
public static void main(String[] args) {
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
SmoothResize srtest = new SmoothResize();
//srtest.setIgnoreRepaint(true);
srtest.setSize(100, 100);
srtest.setVisible(true);
}
public SmoothResize() {
render();
}
private Dimension old_size = new Dimension(0, 0);
private Dimension new_size = new Dimension(0, 0);
public void validate() {
super.validate();
new_size.width = getWidth();
new_size.height = getHeight();
if (old_size.equals(new_size)) {
return;
} else {
render();
}
}
public void paint(Graphics g) {
validate();
}
public void update(Graphics g) {
paint(g);
}
public void addNotify() {
super.addNotify();
createBufferStrategy(2);
}
protected synchronized void render() {
BufferStrategy strategy = getBufferStrategy();
if (strategy == null) {
return;
}
// Render single frame
do {
// The following loop ensures that the contents of the drawing buffer
// are consistent in case the underlying surface was recreated
do {
Graphics draw = strategy.getDrawGraphics();
Insets i = getInsets();
int w = (int)(((double)(getWidth() - i.left - i.right))/2+0.5);
int h = (int)(((double)(getHeight() - i.top - i.bottom))/2+0.5);
draw.setColor(Color.YELLOW);
draw.fillRect(i.left, i.top + h, w,h);
draw.fillRect(i.left + w, i.top, w,h);
draw.setColor(Color.BLACK);
draw.fillRect(i.left, i.top, w, h);
draw.fillRect(i.left + w, i.top + h, w,h);
draw.dispose();
// Repeat the rendering if the drawing buffer contents
// were restored
} while (strategy.contentsRestored());
// Display the buffer
strategy.show();
// Repeat the rendering if the drawing buffer was lost
} while (strategy.contentsLost());
}
}
'Frame'의 일부 Nested 및 Inherit 메소드는 JFrame API에서 직접 구현됩니다. http://download.oracle.com/javase/6/docs/api/javax/swing/JFrame.html, – mKorbel
'Frame'과'JFrame'과'MsExcell'과'MozillaFirefox' 사이에 차이점을 볼 수 없으며 완료되면'notify'를 제거합니다 (i3/530/3,43Gb RAM, WinXP, onBoard GPU/no sharedMemory/compiled JDK1.6.22) – mKorbel
@mKorbel : MsExcel과 MozillaFirefox는 무엇을해야합니까? –