Java-2 2016 Hafta-5 Örnek-1

java2_2016_hafta5_ornek1

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class secimkutusu implements ActionListener
{
JLabel jlab;
JComboBox jcb;
public secimkutusu()
{
	String[] str={"abc","xyz","asdasdsa"};
	JFrame jfrm = new JFrame("Seçim Kutusu");
	jfrm.setSize(150,150);
	jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	jfrm.setLayout(new FlowLayout());
	
	JPanel jpn = new JPanel();
	jpn.setPreferredSize(new Dimension(100,100));
	jcb = new JComboBox(str);
	JButton jbtn = new JButton("Getir");
	jbtn.addActionListener(this);
	jlab= new JLabel("--");
	
	jpn.add(jcb);
	jpn.add(jbtn);
	jpn.add(jlab);

	jfrm.add(jpn);	
	jfrm.setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{
	jlab.setText(jcb.getSelectedIndex()+") "+jcb.getSelectedItem());
	
	//int say= jcb.getItemCount();
	
	// son elemani secmek icin
	//jcb.setSelectedIndex(say-1);
	
}

public static void main(String[] asdasd)
{
	new secimkutusu();
}


}

 

Share