티스토리 뷰
JTextField : 한 줄 입력
JTextArea : 여러 줄 입력
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
class MyFrame14 extends JFrame implements ActionListener{
JTextField tf = new JTextField(25); // JTextArea(행, 열)
JTextArea ta = new JTextArea(18,25);
String s = "";
public MyFrame14(){
setLayout(new FlowLayout());
ta.setEditable(false);
tf.addActionListener(this);
add(tf);
add(ta);
setSize(300,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
s += tf.getText()+"\n";
if( e.getSource() == tf ){
ta.setText(s);
tf.setText("");
}
}
}
public class 텍스트영역예제1 {
public static void main(String[] args) {
new MyFrame14();
}
}
'JAVA > PRIMER' 카테고리의 다른 글
| [JAVA] GUI - 마우스 이벤트 (0) | 2018.04.19 |
|---|---|
| [JAVA] GUI - 키 이벤트 (0) | 2018.04.19 |
| [JAVA] GUI - 이벤트 (0) | 2018.04.19 |
| [JAVA] GUI - 배치관리자 (0) | 2018.04.19 |
| [JAVA] GUI - JPanel, JLabel, JButton (0) | 2018.04.19 |
댓글