標題:
佈局元件 - BorderLayout 搭配 GridLayout
[打印本頁]
作者:
tonyh
時間:
2016-9-3 16:35
標題:
佈局元件 - BorderLayout 搭配 GridLayout
本帖最後由 tonyh 於 2016-9-3 17:10 編輯
[attach]1751[/attach]
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();
}
}
複製代碼
作者:
李允軒
時間:
2016-9-3 17:12
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch01{
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch01(){
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
JButton 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,5,5));
pn2.add(btn5);
pn2.add(btn6);
JFrame 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());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String args[]){
new Ch01();
}
}
複製代碼
作者:
劉得恩
時間:
2016-9-3 17:12
import javax.swing.*;
import java.awt.*;
public class Ch116 {
private JFrame f;
private JButton btn[]=new JButton[]{new JButton("xxx"),new JButton("xxxxxxx"),new JButton("xxxxxxxxxxx"),new JButton("xxxxxxxxxxx"),new JButton("xxx"),new JButton("x")};
private JPanel p1,p2;
Ch116()
{
p1=new JPanel();
p1.setLayout(new GridLayout(4,1));
for(int i=0;i<4;i++)
p1.add(btn[i]);
p2=new JPanel();
p2.setLayout(new GridLayout(2,1));
for(int i=0;i<2;i++)
p2.add(btn[i+4]);
f=new JFrame("\u30df\udcef");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(true);
f.setVisible(true);
f.setBounds(100,100,300,200);
f.setLayout(new BorderLayout());
f.add(p1,BorderLayout.WEST);
f.add(p2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
作者:
張峻瑋
時間:
2016-9-3 17:13
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch116{
private JFrame fm=new JFrame("BorderLayout 搭配 GridLayout");
private JButton btn1,btn2,btn3,btn4,btn5,btn6;
private 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.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();
}
}
複製代碼
作者:
張彥承
時間:
2016-9-3 17:19
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
public class Ch100 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch100()
{
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");
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();
pn1.setLayout(new GridLayout(2,1));
pn1.add(btn5);
pn1.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.EAST);
fm.add(pn2,BorderLayout.WEST);
}
public static void main(String[] args) {
new Ch100();
}
}
複製代碼
作者:
林宇翔
時間:
2016-9-24 09:36
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import javax.swing.JPanel;
public class ch113 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
ch113()
{
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");
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(" 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 ch113();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2