728x90
반응형
package Ex01;
import javax.print.DocFlavor.STRING;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JComponentEx1 extends JFrame {
private JTextField td = new JTextField(10);
private JComboBox<String> combo = new JComboBox<String>();
public JComponentEx1() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("JTextField and JComboBox");
Container c = getContentPane();
c.setLayout(new FlowLayout());
JTextField jtf = new JTextField(10);
JComboBox combo = new JComboBox();
jtf.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JTextField t = (JTextField) e.getSource();
combo.addItem(t.getText());
}
});
c.add(jtf);
c.add(combo);
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new JComponentEx1();
}
}
728x90
반응형
'JAVA > 예제' 카테고리의 다른 글
[JAVA] ArrayList를 사용하여 학점 구하기 (0) | 2022.10.26 |
---|---|
[JAVA] Vector를 사용하여 입력한 수 중 가장 큰 수 구하기 (0) | 2022.10.26 |
[JAVA] JSlider를 이용하여 JLabel 글자 크기 변경 (0) | 2022.10.25 |
[JAVA] JSlider 변동시 JLabel text값 변경 (0) | 2022.10.25 |
[JAVA] swing과 이벤트를 사용하여 슬라이더 만들기 (0) | 2022.10.25 |
댓글