1-) Java - DİNAMİK 2 TANE BUTTON OLUŞTURUP ARTTIR DİYİNCE LABELİ ARTTIRAN UYGULAMA
public class dB extends javax.swing.JFrame {
public dB() {
initComponents();
butonPanel.removeAll();//butonPanel demek attığımız panelin ismi?.
GridLayout grdLayout = new GridLayout(2, 2);
butonPanel.setLayout(grdLayout);
JButton btn = new JButton();
btn.setText("ARTIR");
btn.setName("btn" + "artir");
butonPanel.add(btn);
btn.addActionListener(new dB.artir());
JButton btn1 = new JButton();
btn1.setText("AZALT");
btn1.setName("btn" + "azalt");
butonPanel.add(btn1);
btn1.addActionListener(new dB.azalt());
grdLayout = null;
butonPanel.revalidate(); }
class artir implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton) e.getSource();
int sayi=Integer.parseInt(jLabel1.getText());
sayi++;
jLabel1.setText(String.valueOf(sayi)); } }
class azalt implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton) e.getSource();
int sayi=Integer.parseInt(jLabel1.getText());
sayi--;
jLabel1.setText(String.valueOf(sayi)); } }