Sidewinder


World


FishMusic


LaughingBaby


Monday, July 7, 2008

자바 상속 관련

이상 없이 잘 돌아가요.

------------------------- TitleDialog.java --------------------------
import java.awt.*;
import java.awt.event.*;
public class TitleDialog extends Dialog implements ActionListener
{
private TextField tf = new TextField(15);
private Button b = new Button("설정");
public TitleDialog(Frame dw)
{
super(dw);
this.setLayout(new FlowLayout());
this.add(tf);
this.add(b);
this.tf.addActionListener(this);
this.b.addActionListener(this);
pack();
}
public void actionPerformed(ActionEvent e)
{
Frame f = (Frame)this.getParent();
f.setTitle(tf.getText());
this.tf.selectAll();
this.setVisible(false);
}
}

---------------------- DialogFrame.java ----------------------
import java.awt.*;
import java.awt.event.*;
public class DialogFrame extends Frame implements ActionListener
{
private Button b1 = new Button("Dialog 띄우기");
private TitleDialog td;
public DialogFrame()
{
this.td = new TitleDialog(this);
this.setLayout(new FlowLayout());
this.add(b1);
this.b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
this.td.setTitle("부모 윈도우의 제목을 입력하시오.");
this.td.setModal(false);
this.td.show();
}
}

------------------- DialogFrameMain.java ------------------------
public class DialogFrameMain
{
public static void main(String[] args)
{
DialogFrame f = new DialogFrame();
f.setSize(200,100);
f.setTitle("모달리스 Dialog 테스트");
f.show();
}
}
-------------------------------------------------------------------

No comments:

Post a Comment