標題:
佈局元件 - BorderLayout
[打印本頁]
作者:
tonyh
時間:
2017-9-15 20:39
標題:
佈局元件 - BorderLayout
本帖最後由 tonyh 於 2019-9-7 14:53 編輯
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
//如果沒有設Layout,則預設值就是 BorderLayout
//BorderLayout 預設物件之間的水平及垂直距離為0像素
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
陳思惟
時間:
2017-9-15 21:00
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
//如果沒有設Layout,則預設值就是 BorderLayout
//BorderLayout 預設物件之間的水平及垂直距離為0像素
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
黃璽安
時間:
2017-9-15 21:05
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch114 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch114()
{
JButton btn1=new JButton("xxx");
btn1.setBounds(0, 0, 100, 100);
btn1.setSize(100, 100);
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
JButton btn6=new JButton("x");
fm=new JFrame("GridLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
new BorderLayout();
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch114();
}
}
複製代碼
作者:
洪振庭
時間:
2017-9-15 21:05
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch113 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch113()
{
JButton btn1=new JButton("x 456 x");
JButton btn3=new JButton(" ______/* ____ ");
JButton btn4=new JButton("_____ _______________");
JButton btn5=new JButton(" 1 1 1 ");
JButton btn6=new JButton(" 1 1 4 1 4 ");
JButton btn2=new JButton(" 1 8 7 12 ");
fm=new JFrame("GridLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(4, 0));
fm.add(btn1,BorderLayout.CENTER);
fm.add(btn2,BorderLayout.SOUTH);
fm.add(btn3,BorderLayout.EAST);
fm.add(btn4,BorderLayout.NORTH);
fm.add(btn5,BorderLayout.WEST);
}
public static void main(String[] args) {
new Ch113();
}
}
複製代碼
作者:
曾挺桂
時間:
2017-9-22 20:31
本帖最後由 曾挺桂 於 2017-9-29 21:05 編輯
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
李知易
時間:
2017-9-29 20:11
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch105 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch105()
{
JButton btn1=new JButton("x 456 x");
JButton btn3=new JButton(" ______/* ____ ");
JButton btn4=new JButton("_____ _______________");
JButton btn5=new JButton(" 1 1 1 ");
JButton btn6=new JButton(" 1 1 4 1 4 ");
JButton btn2=new JButton(" 1 8 7 12 ");
fm=new JFrame("GridLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(4, 0));
fm.add(btn1,BorderLayout.CENTER);
fm.add(btn2,BorderLayout.SOUTH);
fm.add(btn3,BorderLayout.EAST);
fm.add(btn4,BorderLayout.NORTH);
fm.add(btn5,BorderLayout.WEST);
}
public static void main(String[] args) {
new Ch105();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2