/* Panel을 이용하여 화면을 배치하는 프로그램. 화면은 BorderLayout으로 설정된다. 각 영역은 Panel 객체를 이용하여 다시 각각 독립적인 구성으로 배치한다. */
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class ChattingPanel extends Applet {
// 패널을 생성한다.
private Panel northPanel = new Panel();
private Panel southPanel = new Panel();
private Panel eastPanel = new Panel();
private Panel centerPanel = new Panel();
public void init() {
BorderLayout aBorder = new BorderLayout();
setLayout (aBorder);
// 패널을 윈도우에 배치한다.
add (northPanel, BorderLayout.NORTH);
add (southPanel, BorderLayout.SOUTH);
add (eastPanel, BorderLayout.EAST);
add (centerPanel, BorderLayout.CENTER);
// northPanel에 Labele 을 생성
Label titleLabelnorth = new Label ("부산it직업학교 채팅 프로그램");
northPanel.setBackground(Color.ORANGE);
northPanel.setLayout (new FlowLayout());
northPanel.add (titleLabelnorth);
// centerPanel에 TextArea생성하여 배치한다.
centerPanel.setLayout (new BorderLayout());
centerPanel.setBackground(Color.WHITE);
TextArea ta1=new TextArea("////////////// 채팅방에 들어 오신것을 환영합니다 ////////////////");
//Button centerCButton = new Button ("Center Button");
centerPanel.add (ta1, BorderLayout.CENTER);
// southPanel에 Choice 배치한다.
//FlowLayout aFlow = new FlowLayout();
//southPanel.setLayout (aFlow);
Choice aChoice = new Choice();
aChoice.add("귓속말선택");
southPanel.add(aChoice);
//southPanel에 TextField 배치
TextField tf1=new TextField("",50);
southPanel.add(tf1,BorderLayout.SOUTH);
southPanel.setBackground(Color.ORANGE);
GridLayout aGrid = new GridLayout (2,1);
southPanel.setLayout (aGrid );
//southPanel에 버튼 배치
Button[] southButton = new Button[7];
southButton[0] = new Button ("대화방개설");
southButton[0].addActionListener (new southButtonHandler(southButton[0]));
southPanel.add (southButton[0]);
southButton[1] = new Button ("대화방참여");
southButton[1].addActionListener (new southButtonHandler(southButton[1]));
southPanel.add (southButton[1]);
southButton[2] = new Button ("대화명변경");
southButton[2].addActionListener (new southButtonHandler(southButton[2]));
southPanel.add (southButton[2]);
southButton[3] = new Button ("쪽지보내기");
southButton[3].addActionListener (new southButtonHandler(southButton[3]));
southPanel.add (southButton[3]);
southButton[4] = new Button ("화면지우기");
southButton[4].addActionListener (new southButtonHandler(southButton[4]));
southPanel.add (southButton[4]);
southButton[5] = new Button ("도움말");
southButton[5].addActionListener (new southButtonHandler(southButton[5]));
southPanel.add (southButton[5]);
southButton[6] = new Button ("나가기");
southButton[6].addActionListener (new southButtonHandler(southButton[6]));
southPanel.add (southButton[6]);
Label southLabel1 = new Label ("부산it직업학교 채팅 프로그램");
southPanel.add(southLabel1);
// eastPanel 텍스트에리어를 생성하여 배치한다.
eastPanel.setLayout (new GridLayout ());
TextArea ta2=new TextArea("[참가인원]",20,20);
eastPanel.add (ta2,BorderLayout.EAST);
}
class southButtonHandler implements ActionListener {
Button aButton;
public southButtonHandler (Button paraButton) {aButton = paraButton;}
public void actionPerformed (ActionEvent e) {
if(((Button)e.getSource()).getLabel()=="대화방개설"){
aButton.setBackground (Color.yellow);
}
else if(((Button)e.getSource()).getLabel()=="대화방참여"){
aButton.setBackground (Color.blue);
}
else if(((Button)e.getSource()).getLabel()=="대화명변경"){
aButton.setBackground (Color.yellow);
}
else if(((Button)e.getSource()).getLabel()=="쪽지보내기"){
aButton.setBackground (Color.orange);
}
else if(((Button)e.getSource()).getLabel()=="화면지우기"){
aButton.setBackground (Color.green);
}
else if(((Button)e.getSource()).getLabel()=="도움말"){
aButton.setBackground (Color.yellow);
}
else if(((Button)e.getSource()).getLabel()=="나가기"){
aButton.setBackground (Color.red);
System.exit(0);
}
}
}
}
'javabasic' 카테고리의 다른 글
채팅UI 2010.7.29 (0) | 2010.07.30 |
---|---|
chatting-frame ui (0) | 2010.07.23 |
자바강의2 (0) | 2010.07.22 |
자바 강의 (0) | 2010.07.22 |
계산기(자바) (0) | 2010.07.16 |