標題:
佈局元件 - BorderLayout 搭配 GridLayout
[打印本頁]
作者:
tonyh
時間:
2017-9-15 21:09
標題:
佈局元件 - BorderLayout 搭配 GridLayout
本帖最後由 tonyh 於 2019-9-7 14:53 編輯
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch116 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch116()
{
btn1=new JButton("xxx");
btn2=new JButton("xxxxxxx");
btn3=new JButton("xxxxxxxxxxx");
btn4=new JButton("xxxxxxxxx xxxxxxx");
btn5=new JButton("xxx");
btn6=new JButton("x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
作者:
黃璽安
時間:
2017-9-15 21:24
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch116 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch116()
{
btn1=new JButton("xxx");
btn2=new JButton("xxxxxxx");
btn3=new JButton("xxxxxxxxxxx");
btn4=new JButton("xxxxxxxxx xxxxxxx");
btn5=new JButton("xxx");
btn6=new JButton("x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
作者:
李知易
時間:
2017-9-15 21:27
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt. BorderLayout;
import javax.swing.JPanel;
import java.awt. GridLayout;
public class Ch105 {
JFrame fm;
JButton b1,b2,b3,b4,b5,b6;
JPanel pn1,pn2;
Ch105()
{
JButton b1=new JButton("我換換");
b1.setBounds(0,0,100,100);
b1.setSize(100,100);
JButton b2=new JButton("我換換換");
JButton b3=new JButton("我換換換換");
JButton b4=new JButton("我換換換換換");
JButton b5=new JButton("我換換換換換換");
JButton b6=new JButton("我換換換換換換換");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(b1);
pn1.add(b2);
pn1.add(b3);
pn1.add(b4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(b5);
pn2.add(b6);
JFrame fm=new JFrame("FlowLayout");
fm.setBounds(100,100,300,200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1, BorderLayout.WEST);
fm.add(pn2, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch105();
}
}
複製代碼
作者:
洪振庭
時間:
2017-9-15 22:31
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
public class Ch114 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch114()
{
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 ");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("FlowLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.add(pn1,BorderLayout.EAST);
fm.add(pn2,BorderLayout.WEST);
}
public static void main(String[] args) {
new Ch114();
}
}
複製代碼
作者:
陳思惟
時間:
2017-9-22 19:51
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch116 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch116()
{
btn1=new JButton("xxx");
btn2=new JButton("xxxxxxx");
btn3=new JButton("xxxxxxxxxxx");
btn4=new JButton("xxxxxxxxx xxxxxxx");
btn5=new JButton("xxx");
btn6=new JButton("x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
作者:
曾挺桂
時間:
2017-9-22 20:24
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch116 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch116()
{
btn1=new JButton("xxx");
btn2=new JButton("xxxxxxx");
btn3=new JButton("xxxxxxxxxxx");
btn4=new JButton("xxxxxxxxx xxxxxxx");
btn5=new JButton("xxx");
btn6=new JButton("x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2