Nesne Tabanlı Programlama-2 (Bahar-2016) Hafta-4/1-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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class checkbox extends JFrame implements ActionListener { JCheckBox jcb1,jcb2,jcb3; public checkbox() { this.setTitle("CheckBox Örneği"); this.setSize(300,150); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new FlowLayout()); JPanel jp_main = new JPanel(); jp_main.setPreferredSize(new Dimension(290, 140)); JPanel jpn1 = new JPanel(); JPanel jpn2 = new JPanel(); jpn1.setPreferredSize(new Dimension(280, 60)); jpn2.setPreferredSize(new Dimension(280, 65)); jp_main.add(jpn1); jp_main.add(jpn2); jpn1.setLayout(new GridLayout(1,3)); jpn2.setLayout(new FlowLayout()); jcb1 = new JCheckBox("Seçim-1"); jcb2 = new JCheckBox("Seçim-2"); jcb3 = new JCheckBox("Seçim-3"); /*jcb1.addActionListener(new ActionListener(){@Override public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "Hello World!"); }});*/ jpn1.add(jcb1); jpn1.add(jcb2); jpn1.add(jcb3); JButton jbtn1= new JButton("Göster"); JButton jbtn2= new JButton("Temizle"); jbtn1.addActionListener(this); jbtn1.setActionCommand("goster"); jbtn2.addActionListener(this); jpn2.add(jbtn1); jpn2.add(jbtn2); this.add(jp_main); this.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0) { if(arg0.getActionCommand().equals("goster")) goster(); else temizle(); } private void goster() { String yaz=""; if(jcb1.isSelected()) yaz+=jcb1.getText(); if(jcb2.isSelected()) { if(yaz.length()>0) yaz+=" ; "; yaz+=jcb2.getText(); } if(jcb3.isSelected()) { if(yaz.length()>0) yaz+=" ; "; yaz+=jcb3.getText(); } if(yaz.length()==0) yaz="Seçili Eleman Yok!"; JOptionPane.showMessageDialog(null, yaz); } private void temizle() { jcb1.setSelected(false); jcb2.setSelected(false); jcb3.setSelected(false); } public static void main(String[] args) { new checkbox(); } } |
Okumaya devam et
Son Yorumlar