標題:
佈局元件 - BorderLayout 搭配 GridLayout
[打印本頁]
作者:
tonyh
時間:
2019-9-21 13:42
標題:
佈局元件 - BorderLayout 搭配 GridLayout
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();
}
}
複製代碼
作者:
蕭澧邦
時間:
2019-9-21 14:16
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();
}
}
複製代碼
作者:
蔡幸融
時間:
2019-9-21 14:37
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.sql.DriverPropertyInfo;
import java.util.concurrent.BrokenBarrierException;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1, pn2;
Ch115()
{
JButton btn1=new JButton("左1");
JButton btn2=new JButton("左2");
JButton btn3=new JButton("左3");
JButton btn4=new JButton("左4");
JButton btn5=new JButton("右1");
JButton btn6=new JButton("右1");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1));
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("練習");
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(pn1, BorderLayout.WEST);
fm.add(pn2, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
譚暐霖
時間:
2019-9-21 14:42
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();
}
}
複製代碼
作者:
高睿辰
時間:
2019-9-21 14:59
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();
}
}
複製代碼
作者:
黃宥鈞
時間:
2019-9-28 14:21
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