🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / Java / IZGARA ŞEKLİNDE BÖLER MİSAL 4 SATIR 3 SUTUN VE BUTTONLARI YERLESTIRIR

 

1-) Java - IZGARA ŞEKLİNDE BÖLER MİSAL 4 SATIR 3 SUTUN VE BUTTONLARI YERLESTIRIR

 

public class gridlayout extends JFrame implements ActionListener {

 

JPanel panel;

 

public int sayi = 0;

 

public gridlayout() {

 

//super("Add component on JFrame at runtime");

 

//setLayout(new FlowLayout());

 

//setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

 

panel=new JPanel();

 

GridLayout experimentLayout = new GridLayout(5,2);

 

//experimentLayout.setAlignment(FlowLayout.TRAILING);

 

panel.setLayout(experimentLayout);

 

//panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

 

add(panel);

 

for(int i=0;i<10;i++) {

 

JButton button=new JButton("CLICK HERE");

 

button.setText(String.valueOf(sayi)+" nolu button");

 

//button.setBounds(0, sayi * 20, 10, 10);

 

panel.add(button);

 

button.addActionListener(new aListener());

 

sayi++; }

 

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

setSize(500,500);

 

setVisible(true); }

 

public void actionPerformed(ActionEvent evt) {

 

panel.add(new JButton("Button"));

 

panel.revalidate();

 

validate(); }

 

class aListener implements ActionListener {

 

public void actionPerformed(ActionEvent e) {

 

JButton b = (JButton) e.getSource();

 

System.out.println(b.getText()); } }

 

public static void main(String[] args) {

 

gridlayout acojfar=new gridlayout();

 

//for (Component c : jPanel1.getComponents())

 

//{

 

// if (c instanceof JLabel)

 

// {

 

// System.out.println("label var");

 

// JLabel ll = (JLabel) c;

 

// ll.setText("deneme");

 

// }

 

}}

 2021 Ocak 18 Pazartesi
 386