Kamis, 23 November 2017

Tugas MultiLayout

Source Code :

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;

public class tugas10 {

public static void addComponentsToPane(Container pane) {
JLabel label;
JLabel label2;
JLabel label3;

pane.setLayout(null);

label = new JLabel("Flow Layout");
pane.add(label);

JButton b1 = new JButton("0");

JButton b2 = new JButton("1");
JButton b3 = new JButton("2");
JButton b4 = new JButton("3");
JButton b5 = new JButton("4");
JButton b6 = new JButton("5");
JButton b7 = new JButton("6");
JButton b8 = new JButton("7");


JButton b9 = new JButton("8");

JButton b10 = new JButton("9");
JButton b11 = new JButton("10");
JButton b12 = new JButton("11");

pane.add(b1);

pane.add(b2);
pane.add(b3);
pane.add(b4);
pane.add(b5);
pane.add(b6);
pane.add(b7);
pane.add(b8);
pane.add(b9);
pane.add(b10);
pane.add(b11);
pane.add(b12);

b9.setBounds(375,35,47,24);

b10.setBounds(422,35,48,24);
b11.setBounds(375,60,48,24);
b12.setBounds(422,60,47,24);

label2 = new JLabel("None Layout");

pane.add(label2);
label3 = new JLabel("Grid Layout");
pane.add(label3);

Insets insets = pane.getInsets();

Dimension size = b1.getPreferredSize();

b1.setBounds(50+insets.left,40+insets.top,size.width,size.height);

size=b2.getPreferredSize();
b2.setBounds(95+insets.left,40+insets.top,size.width,size.height);
size=b3.getPreferredSize();
b3.setBounds(140+insets.left,40+insets.top,size.width,size.height);
size=b4.getPreferredSize();
b4.setBounds(185+insets.left,40+insets.top,size.width,size.height);
size=b5.getPreferredSize();
b5.setBounds(285+insets.left,40+insets.top,size.width,size.height);
size=b6.getPreferredSize();
b6.setBounds(285+insets.left,65+insets.top,size.width,size.height);
size=b7.getPreferredSize();
b7.setBounds(285+insets.left,90+insets.top,size.width,size.height);
size=b8.getPreferredSize();
b8.setBounds(285+insets.left,115+insets.top,size.width,size.height);
size=b9.getPreferredSize();
size=b10.getPreferredSize();
size=b11.getPreferredSize();
b11.setBounds(375+insets.left,60+insets.top,size.width,size.height);
size=b12.getPreferredSize();
b12.setBounds(422+insets.left,60+insets.top,size.width,size.height);
size=label.getPreferredSize();
label.setBounds(50+insets.left,15+insets.top,size.width,size.height);
size=label2.getPreferredSize();
label2.setBounds(270+insets.left,15+insets.top,size.width,size.height);
size=label3.getPreferredSize();
label3.setBounds(385+insets.left,15+insets.top,size.width,size.height);
}

public static void main(String[] args) {

JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame=new JFrame("MULTI LAYOUT");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addComponentsToPane(frame.getContentPane()); 
Insets insets = frame.getInsets();
frame.setSize(550+insets.left+insets.right,200+insets.top+insets.bottom);
frame.setVisible(true);
}
}

Output :





Tidak ada komentar:

Posting Komentar