[Re]JFrame에서 component 추가, 삭제는 어떻게...


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :이성훈 1999년 11월 19일 12:18:46

In Reply to: JFrame에서 component 추가, 삭제는 어떻게... posted by 임준모 on 1999년 11월 19일 10:14:26:

제가 주로 쓰는 방법인데요.
아래 코드를 참고하세요.
------------------------------------------------------------
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class CompTest extends JFrame implements ActionListener {
JButton b1;
JButton b2;
JButton b3;

public CompTest() { this("Anonymous"); }
public CompTest (String s) {
super(s);
b1 = new JButton("Button1");
b2 = new JButton("Button2");
b3 = new JButton("Button3");
b3.addActionListener(this);

this.getContentPane().setLayout( new BorderLayout());
this.getContentPane().add("Center", b1);
this.getContentPane().add("South", b3);

this.setSize(400,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
this.remove(b1);
this.getContentPane().add("Center", b2);
this.validate();
}
public static void main(String args[]) {
new CompTest("Hi all");
}
}


다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]