chatting-frame ui

javabasic 2010. 7. 23. 17:17

//chatting....
import java.awt.*;
import java.awt.event.*;

public class ChattFrame extends Frame {
    private Panel northPanel = new Panel();
    private Panel southPanel = new Panel();
    private Panel eastPanel = new Panel();
    private Panel centerPanel = new Panel();

    public static void main (String[] args) {
 ChattFrame chat=new ChattFrame();
 chat.go();
 
    }
    public void go(){
 
 Frame aframe = new Frame();
  
 aframe.add(BorderLayout.CENTER,centerPanel);
 aframe.add(BorderLayout.NORTH,northPanel);
 //
 aframe.add(BorderLayout.SOUTH,southPanel);
 southPanel.setLayout (new BorderLayout());
 Panel southa = new Panel();
 Panel southb = new Panel();
 southPanel.add(southa,BorderLayout.NORTH);
 southPanel.add(southb,BorderLayout.SOUTH);

 aframe.setSize(800,600);
 aframe.setVisible(true);
 
  // centerPanel에  TextArea생성하여 배치한다.
        //centerPanel.setBackground(Color.WHITE);
 TextArea ta1=new TextArea("////////////// 채팅방에 들어 오신것을 환영합니다 ////////////////",30,60);
 centerPanel.add (ta1);

 // eastPanel 텍스트에리어를 생성하여 배치한다.
        TextArea ta2=new TextArea("[참가인원]",20,20);
 aframe.add(BorderLayout.EAST,ta2);
        
 
 //north 배치
 Label titleLabelnorth = new Label ("부산it직업학교 채팅 프로그램");
 northPanel.setBackground(Color.ORANGE);
        northPanel.setLayout (new FlowLayout());
        northPanel.add (titleLabelnorth);
 
 //south 배치
 //Label titleLabelnorth1 = new Label ("Whisper:");
 southa.setBackground(Color.ORANGE);
        southa.setLayout (new FlowLayout());
        //southa.add (titleLabelnorth1);

 Choice aChoice = new Choice();
 aChoice.add("귓속말선택");
 southa.add(aChoice);

 //southPanel에 TextField 배치
 TextField tf1=new TextField("",50);
 southa.add(tf1);
 
 
 southb.setBackground(Color.yellow);
        southb.setLayout (new FlowLayout());
        //southb.add (titleLabelnorth2);

 //southPanel에 버튼 배치
       Button[] southButton = new Button[7];
        southButton[0] = new Button ("대화방개설");
 southButton[0].addActionListener (new southButtonHandler(southButton[0]));
        southb.add (southButton[0]);
 southButton[1] = new Button ("대화방참여");
 southButton[1].addActionListener (new southButtonHandler(southButton[1]));
        southb.add (southButton[1]);
 southButton[2] = new Button ("대화명변경");
 southButton[2].addActionListener (new southButtonHandler(southButton[2]));
        southb.add (southButton[2]);
 southButton[3] = new Button ("쪽지보내기");
 southButton[3].addActionListener (new southButtonHandler(southButton[3]));
        southb.add (southButton[3]);
 southButton[4] = new Button ("화면지우기");
 southButton[4].addActionListener (new southButtonHandler(southButton[4]));
        southa.add (southButton[4]);
 southButton[5] = new Button ("도움말");
 southButton[5].addActionListener (new southButtonHandler(southButton[5]));
        southa.add (southButton[5]);
 southButton[6] = new Button ("나가기");
 southButton[6].addActionListener (new southButtonHandler(southButton[6]));
        southa.add (southButton[6]);
 Label southLabel1 = new Label ("부산it직업학교 채팅 프로그램");
 southb.add(southLabel1);
    }   
    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);
   
   FlowLayout flow1=new FlowLayout();
   setLayout (flow1);
   
   Label titleLabel2 = new Label ("대화명을 변경합니다");
   TextField chtext=new TextField(20);
          setBackground (Color.red);
   addWindowListener (new WindowHandler());
   add(titleLabel2);
   add(chtext);
   
   setVisible (true);
  }
  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);

  }
  
     }
 
   
    } 
    // 윈도우를 닫기위한 이벤트 청취자
    class WindowHandler extends WindowAdapter {
        public void windowClosing (WindowEvent e) {
            if (e.getID() == WindowEvent.WINDOW_CLOSING) {
                setVisible (false);
                System.exit (0);
            }
        }
    }

}

'javabasic' 카테고리의 다른 글

chatting ver1.02  (0) 2010.08.04
채팅UI 2010.7.29  (0) 2010.07.30
채팅 UI  (0) 2010.07.22
자바강의2  (0) 2010.07.22
자바 강의  (0) 2010.07.22
Posted by 지화명이
,