글쓴이 :최종철 1998년 7월 25일 21:13:36
In Reply to: [답변]애플릿에서 프린트하는 법과 CardLayout 예제 posted by 조신제 on 1998년 7월 25일 20:10:52:
조신제님께서 답해주신데 대해서 대단히 감사드립니다.
저는 지금 jdk1.1.3을 쓰고있는데요.
에러메시지가 나거든요..
제가 cardlayout을 시험코자 대충 한 것인데..
한번만 봐주세요...
------------ 카드 레이아웃 --------
import java.awt.* ;
import java.awt.event.* ;
public class CL extends java.applet.Applet
implements ActionListener {
CardLayout cl = new CardLayout() ;
Panel p, p1, p2, cards ;
public void init() {
setLayout(new BorderLayout()) ;
cards = new Panel() ;
p = new Panel();
add("North", p) ;
add("Center", cards) ;
p = new Panel() ;
p.add(new Label("Select Panel !!")) ;
p.add(new Button("Btn1")) ;
p.add(new Button("Btn2")) ;
cards.setLayout(new CardLayout()) ;
p1 = new Panel() ;
p1.setLayout(new GridLayout(2,2,10,10)) ;
p1.add(new Button("Label 1")) ;
p1.add(new Button("Label 2")) ;
p1.add(new Button("Label 3")) ;
p1.add(new Button("Label 4")) ;
cards.add("P1", p1) ;
p2 = new Panel() ;
p2.setLayout(new GridLayout(4,1,10,10)) ;
p2.add(new Button("Label 1")) ;
p2.add(new Button("Label 2")) ;
p2.add(new Button("Label 3")) ;
p2.add(new Button("Label 4")) ;
cards.add("P2", p2) ;
} // init
public void actionPerformed (ActionEvent e) {
if (e.getSource() instanceof Button) {
String label = ((Button)e.getSource()).getLabel() ;
if (label == "Btn1") { cl.show(cards, "P1") ; }
if (label == "Btn2") { cl.show(cards, "P2") ; }
} // instanceof Button
} // actionPerformed
} // top
----------------------- 카드레이아웃 --------
------ 그리고 이것은 프린트 예제입니다 -----
애플릿을 애플릿자체에서 프린트를 할수 있게끔
해야 하기ㄸㅒ문에 이처럼 간단하게 대충 실험하고자
합니다.
이 예제를 한번만 봐주세요.
저는 수리환경 모델링을 해서, 나온 결과를
gif화일로 만든 다음에 이것을 애플릿에서
보이게 할려고 합니다.
그 다음에 프린트를 해야 하는데, 일단 아래 방법이
잘 작동하게 되면, 될텐데...
너무 어렵습니다.
그럼 이것도 봐주시면 대단히 감사하겠습니다.
------------- 프린트 예제 ----------------
import java.awt.*;
import java.awt.event.* ;
public class PP extends java.applet.Applet implements ActionListener {
Label status = new Label("Print ME !!");
Button prbtn = new Button("PRINT APPLET") ;
public void init() {
setLayout(new FlowLayout(FlowLayout.CENTER,10,10)) ;
add(status) ;
add(prbtn) ;
prbtn.addActionListener(this) ;
} // init
public Insets getInsets() { return new Insets(10,10,10,10); }
public void start() { }
public void stop() { }
public void actionPerformed (ActionEvent e) {
if (e.getSource() instanceof Button) {
PrintJob job = getToolkit().getPrintJob(this, "Print Test",
null) ;
//(Properties)null) ;
if (job != null) {
Graphics pg = job.getGraphics() ;
if (pg != null) {
printAll(pg) ;
pg.dispose() ;
}
job.end() ;
}
} // instanceof Button
} // actionPerformed
} // top
------------- 프린트 예제 끝 ---------------
또 한번 부탁드리겠습니다.
감사합니다.
최종철