Java-2 2016 Hafta-5 Örnek-1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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(); } } |