TesGridLayout.java (Pemrograman Berorientasi Objek)

TesGridLayout.java


import java.awt.*;
import java.awt.event.*;

public class TesGridLayout extends Frame {
public static void main (String[]args) {
TesGridLayout apl = new TesGridLayout();
}

public TesGridLayout() {
super("Tes FlowLayout");
setSize(400,250);

Panel p1 = new Panel();
p1.setLayout(new GridLayout(2,3));
p1.add(new Button("Tombol A"));
p1.add(new Button("Tombol B"));
p1.add(new Button("Tombol C"));
p1.add(new Button("Tombol D"));
p1.add(new Button("Tombol B"));
add("North", p1);

Panel p2 = new Panel();
p2.setLayout(new GridLayout(3,2 ,10, 5));
p2.add(new Button("Tombol A"));
p2.add(new Button("Tombol B"));
p2.add(new Button("Tombol C"));
p2.add(new Button("Tombol D"));
p2.add(new Button("Tombol E"));
add("South", p2);

Panel p3 = new Panel();
Button exit = new Button ("Exit");
p3.setLayout(new GridLayout(2,2));
p3.add(exit);
add("East",p3);
exit.addActionListener(new TesGridLayout.PenangananTombol());

addWindowListener(
                new TesGridLayout.PenangananKejadian());
this.setVisible(true);
}
    class PenangananKejadian extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
            }
    }

class PenangananTombol implements ActionListener {
             public void actionPerformed(ActionEvent e) {
                String status = e.getActionCommand();
                if (status.equals("Exit")) {
                    System.exit(0);
                }
            }
    }
}

Jika di run maka hasilnya:



0 komentar:

Posting Komentar

Diberdayakan oleh Blogger.

Followers

Back to top