Nesne Tabanlı Programlama-2 (Bahar-2016) Hafta-3/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 |
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class yerlesim extends JFrame implements ActionListener{ public yerlesim() { // this anahtar kelimesi kullanilmasa da olur this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(330,370); this.setLayout(new FlowLayout()); JPanel jpn0 = new JPanel(); JPanel jpn1 = new JPanel(); JPanel jpn2 = new JPanel(); jpn0.setPreferredSize(new Dimension(100, 370)); jpn1.setPreferredSize(new Dimension(100, 370)); jpn2.setPreferredSize(new Dimension(100, 370)); for(int i=1;i<31;i++) { JButton jbtn = new JButton("Buton-"+i); jbtn.setPreferredSize(new Dimension(100,30)); jbtn.setActionCommand(i+""); jbtn.addActionListener(this); if(i%3==0) jpn2.add(jbtn); if(i%3==1) jpn0.add(jbtn); if(i%3==2) jpn1.add(jbtn); } this.add(jpn0); this.add(jpn1); this.add(jpn2); this.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, e.getActionCommand()); } public static void main(String[] args) { new yerlesim(); } } |