본문 바로가기

JAVA/기본다지기

JAVA 20일차 필기

AWT로 모의 채팅포맷 만들어보기


package com.javalesson.ch20awt;


import java.awt.Frame;

import java.awt.TextArea;

import java.awt.TextField;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.text.SimpleDateFormat;

import java.util.Date;//현재 시간


public class L02TextComponent extends Frame{

TextArea ta;

TextField tf;

Date date;

SimpleDateFormat sdf;

public L02TextComponent(String title){

super(title);

ta = new TextArea();

tf new TextField();

sdf new SimpleDateFormat("HH:mm:ss");

super.add(ta,"Center");

super.add(tf,"South");

ta.setEnabled(false);

tf.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

ta.append(tf.getText()+" ["+sdf.format(new Date())+"]\r\n");

tf.setText("");

}

});

this.setSize(500, 300);

this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

tf.requestFocus();

}//생성자 end

public static void main(String[] args){

new L02TextComponent("카톡창"); 

}

}//class end




'JAVA > 기본다지기' 카테고리의 다른 글

JAVA 22일차 필기  (1) 2016.09.07
JAVA 21일차 필기  (1) 2016.09.06
JAVA 19일차 필기  (1) 2016.09.01
JAVA 18일차 필기  (1) 2016.08.31
JAVA 17일차 필기  (1) 2016.08.30