IMPLEMENTASI LAYOUT MANAGER PAKET ABSTRACT WINDOW TOOLKIT A. FLOWLAYOUT class MyFlowLayout extends Frame{ public MyFlowLayout(){ super("contoh FlowLayout"); ); setlayout(new FlowLayout(FlowLayout.CENTER,50,30)); Button btn[]=new Button[10]; btn[i]=new Button(String.valueOf(i)); add(btn[i]); class TestFlowLayout{ new MyFlowLayout();
B. BORDERLAYOUT class MyBorderLayout extends Frame{ public MyBorderLayout(){ super("contoh BorderLayout"); ); setlayout(new BorderLayout(20,20)); Button btn[]=new Button[5]; btn[i]=new Button(); btn[0].setlabel("north"); btn[1].setlabel("west"); btn[2].setlabel("center"); btn[3].setlabel("east"); btn[4].setlabel("south"); add(btn[0],borderlayout.north); add(btn[1],borderlayout.west); add(btn[2],borderlayout.center); add(btn[3],borderlayout.east); add(btn[4],borderlayout.south);
class TestBorderLayout{ new MyBorderLayout(); C. GRIDLAYOUT class MyGridLayout extends Frame{ public MyGridLayout(){ super("contoh GridLayout"); ); setlayout(new GridLayout(4,3,5,5)); Button btn[]=new Button[10]; btn[i]=new Button(String.valueOf(i)); add(btn[i]); class TestGridLayout{ new MyGridLayout();
D. GRIDBAGLAYOUT class MyGridBagLayout extends Frame{ public MyGridBagLayout(){ super("contoh GridBagLayout"); ); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setlayout(gbl); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 0; this.add(new Button("Satu"), gbc); gbc.gridx = 1; gbc.gridy = 0; this.add(new Button("Dua"), gbc); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth=2; this.add(new Button("Tiga"), gbc); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 2;
gbc.gridwidth=2; gbc.ipady=20; this.add(new Button("Empat"), gbc); gbc.gridx = 2; gbc.gridy = 3; gbc.ipady = 50; gbc.fill = GridBagConstraints.VERTICAL; this.add(new Button("Lima"), gbc); class TestGridBagLayout{ new MyGridBagLayout(); E. CARDLAYOUT class MyCardLayout extends Frame implements ActionListener{ private Panel pnl; private CardLayout card; private String teks[]={"satu","dua","tiga","empat","lima"; private Button btn[]=new Button[5]; private String []pengenal={"a","b","c","d","e"; public MyCardLayout(){ super("contoh CardLayout"); setlayout(new BorderLayout()); pnl= new Panel();
card=new CardLayout(40,30); pnl.setlayout(card); for(int i=0; i<btn.length;++i){ btn[i]=new Button(teks[i]); btn[i].addactionlistener(this); pnl.add(pengenal[i],btn[i]); card=(cardlayout) pnl.getlayout(); card.first(pnl); //card.show(pnl,pengenal[0]); add(pnl,borderlayout.center); public void actionperformed(actionevent e) { card.next(pnl); class TestCardLayout{ new MyCardLayout(); IMPLEMENTASI LAYOUT MANAGER PAKET SWING F. BOXLAYOUT import javax.swing.*; class MyBoxLayout extends Frame{ public MyBoxLayout(){ super("contoh BoxLayout");
); setlayout(new BoxLayout(this, BoxLayout.X_AXIS)); Button btn[]=new Button[10]; btn[i]=new Button(String.valueOf(i)); add(btn[i]); class TestBoxLayout{ new MyBoxLayout();