?? chap11-3.txt
字號:
// 程序11-3
import java.awt.*;
import javax.swing.*;
public class testFlowLayout{
JFrame frame;
Container contentPane;
JPanel jp;
FlowLayout layout;
public static void main(String args[ ]){
testFlowLayout obj=new testFlowLayout( );
obj.testFlow( );
obj.changeAlign( );
}
private static void fillComponent(Container c){
for(int i=0;i<3;i++)
c.add(new JButton("Button "+i));
}
public void testFlow ( ){
frame=new subJFrame("testFlowLayout");
contentPane=frame.getContentPane( );
jp=new JPanel( ); // 定義一個面板
layout=new FlowLayout( );
fillComponent(jp); // 向面板中添加組件
contentPane.add(jp);
layout=new FlowLayout(FlowLayout.CENTER,20,50);
contentPane.setLayout(layout);
frame.setSize(400,200);
frame.show( );
}
public void changeAlign( ){
for(int i=0;i<3;i++){
try{
Thread.sleep(1000); // 睡眠1秒
}catch(Exception e){
e.printStackTrace( );
}
switch(i){
case 0:
layout.setAlignment(FlowLayout.LEFT);
break;
case 1:
layout.setAlignment(FlowLayout.CENTER);
break;
case 2:
layout.setAlignment(FlowLayout.RIGHT);
break;
}
layout.layoutContainer(contentPane); // 重新排列有關的組件
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -