JAVA/PRIMER
[JAVA] GUI - JTextField, JTextArea
yulrang
2018. 4. 19. 14:19
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(); } }