Cari Blog Ini
Kamis, 03 November 2016
TextField ke ComboBox dengan java visual
berikut codingan nya :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class TextfieldToComboBox extends JFrame
{
JLabel judul = new JLabel ("Masukkan Data Jurusan : ");
JTextField txdata = new JTextField ();
JComboBox cbdata = new JComboBox();
JButton insert = new JButton ("INSERT");
TextfieldToComboBox()
{
setTitle("Aplikasi TextField to ComboBox");
setLocation(0,0);
setSize(250,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void KomponenVisual()
{
getContentPane().setLayout(null);
getContentPane().setBackground(Color.magenta);
getContentPane().add(judul);
judul.setBounds(50,10,150,20);
getContentPane().add(txdata);
txdata.setBounds(10,30,200,20);
txdata.setHorizontalAlignment(SwingConstants.CENTER); //untuk text rata tengah
getContentPane().add(insert);
insert.setBounds(40,55,150,60);
insert.setIcon(new ImageIcon("simpan.png"));
getContentPane().add(cbdata);
cbdata.setBounds(10,120,200,20);
show();
}
void aksireaksi()
{
insert.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
cbdata.addItem(txdata.getText());
}
});
}
public static void main (String[] args)
{
TextfieldToComboBox ttc = new TextfieldToComboBox();
ttc.KomponenVisual();
ttc.aksireaksi();
}
}