標題:
JPanel 類別與 setBorder() 方法
[打印本頁]
作者:
tonyh
時間:
2016-9-3 17:20
標題:
JPanel 類別與 setBorder() 方法
本帖最後由 tonyh 於 2016-9-3 17:48 編輯
試使用 setBorder() 方法,為容器加上邊框。
[attach]1752[/attach]
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch117 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch117();
}
}
複製代碼
作者:
劉得恩
時間:
2016-9-3 17:56
import javax.swing.*;
import java.awt.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch116 {
private JFrame f;
private JButton btn[]=new JButton[4];
private JPanel p1,p2,p3;
Ch116()
{
for(int i=0;i<4;i++)
btn[i]=new JButton("按鈕"+(i+1));
p1=new JPanel();
p1.setBorder(new EtchedBorder());
p2=new JPanel();
p2.setBorder(new TitledBorder("第二區"));
p3=new JPanel();
p3.setLayout(new GridLayout(4,1,5,5));
p3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
for(JButton i:btn)
p3.add(i);
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 GridLayout());
f.add(p1);
f.add(p2);
f.add(p3);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
作者:
張彥承
時間:
2016-9-3 18:03
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch100{
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch100();
}
}
複製代碼
作者:
張峻瑋
時間:
2016-9-23 18:52
import javax.swing.*;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch117 {
JFrame fm;
JButton btn[]=new JButton[4];
JPanel pn1,pn2,pn3;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch117();
}
}
複製代碼
作者:
林宇翔
時間:
2016-9-24 09:54
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class ch113 {
JFrame fm;
JButton btn[]=new JButton[4];
JPanel p1,p2,p3;
ch113()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
p1=new JPanel();
p1.setBorder(new EtchedBorder());
p2=new JPanel();
p2.setBorder(new TitledBorder("第二區"));
p3=new JPanel();
p3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
p3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
p3.add(btn[i]);
fm=new JFrame("setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(p1);
fm.add(p2);
fm.add(p3);
}
public static void main(String[] args) {
new ch113();
}
}
複製代碼
作者:
李允軒
時間:
2016-9-24 15:54
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch01 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch01()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch01();
}
}
複製代碼
作者:
張峻瑋
時間:
2016-9-24 17:43
import javax.swing.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
public class Ch119 {
JFrame fm;
Font ft[]=new Font[6];
JLabel lb[]=new JLabel[6];
Ch119()
{
ft[0]=new Font("標楷體",Font.BOLD,50);
ft[1]=new Font("微軟正黑體",Font.BOLD+Font.ITALIC,40);
ft[2]=new Font("新細明體",Font.ITALIC,60);
ft[3]=new Font("Times New Roman",Font.PLAIN,60);
ft[4]=new Font("Arial",Font.ITALIC,40);
ft[5]=new Font("Manorly",Font.PLAIN,80);
for(int i=0;i<6;i++)
{
if(i<3)
lb[i]=new JLabel("你好",JLabel.CENTER);
else
lb[i]=new JLabel("Hello",JLabel.CENTER);
lb[i].setBorder(new EtchedBorder());
lb[i].setFont(ft[i]);
}
lb[0].setForeground(Color.BLUE);
lb[2].setForeground(Color.RED);
lb[4].setForeground(Color.GRAY);
fm=new JFrame("Font 類別");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout(2,3));
for(int i=0;i<6;i++)
{
fm.add(lb[i]);
}
}
public static void main(String[] args) {
new Ch119();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2