PHP字串長度找子字串與取代字串的常用函數

PHP在字串的操作上,有非常多的相關函數可以使用,我們在這裡只介紹經常會使用到的字串操作函數。像是如何取得字串的長度、在某一個字裏面尋找子字串首次出現的位置、以及字串的取代函數...等等。這些都是在編寫程式的時候,頻繁被程式設計師使用到的基礎函數。 取得字串長度 <?...

2017年12月24日 星期日

使用CardLayout(或稱TAB)的方式來編排頁面元件


package test.swing.layout;

import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

public class TestCardLayout extends JFrame {
	
	private JPanel contentPane;

	public static void main(String[] args) {
		TestCardLayout frame = new TestCardLayout();
		frame.setVisible(true);		
	}
	
	public TestCardLayout(){
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);   //(左邊界,上邊界,宽度,長度)
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));   //(上,左,下,右)
		setContentPane(contentPane);
		
		//設置Layout的樣式來呈現component之間在Panel上的位置關係
		contentPane.setLayout(new CardLayout(35, 10));  //左右間距,上下間距
		
		//加入Tab panel到Layout上面
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, "新Tab panel面板");
		
		//加入第一個tab panel
		JPanel tab1 = new JPanel();
		tab1.setBackground(Color.WHITE);
		tab1.setBorder(new EmptyBorder(20, 10, 30, 10));   //(上,左,下,右)
		tabbedPane.addTab("測試tab1", null, tab1, null);  //(名稱,圖示,元件,提示)
		
		JButton submitBtn = new JButton("提交");
		tab1.add(submitBtn);
		
		//加入第二個tab panel
		JPanel tab2 = new JPanel();
		tab2.setBackground(Color.WHITE);
		tab2.setBorder(new EmptyBorder(20, 10, 30, 10));   //(上,左,下,右)
		tabbedPane.addTab("測試tab2", null, tab2, null);  //(名稱,圖示,元件,提示)
		
		JLabel nameLabel = new JLabel("名稱: ");
		tab2.add(nameLabel);				
		
	}

}
執行結果 

沒有留言:

張貼留言