TesFlowLayout.java (Pemrograman Berorientasi Objek)

TesFlowLayout.java


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


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

public TesFlowLayout() {
super("Tes FlowLayout");
setSize(300,200);

Panel p1 = new Panel ();
p1.setLayout(new FlowLayout());
p1.add(new Button("Tombol A"));
p1.add(new Button("Tombol B"));
p1.add(new Button("Tombol C"));

Panel p2 = new Panel();
p2.setLayout(new FlowLayout ());
p2.add(new Button("Tombol X"));
p2.add(new Button("Tombol Y"));
p2.add(new Button("Tombol Z"));

Panel p3 = new Panel();
Button exit = new Button ("Exit");
p3.setLayout(new FlowLayout (FlowLayout.CENTER, 35, 35));
p3.add (exit);

exit.addActionListener(new TesFlowLayout.PenangananTombol());

add("North", p1);
add("South", p2);
add("Center",p3);

addWindowListener(
                new TesFlowLayout.PenangananKejadian());
show();
}
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