標籤:tle 對象 重寫 next component clip file 程式 設定
工具:myeclipse
1.建立一個Frame類
右鍵項目--->new--->class--->填寫包名,類名(視窗名),選擇父類JFrame--->finish.
右鍵項目--->new--->other--->JFrame--->填寫類名(視窗名)--->finish.
2.布局管理器
我常用布局為absolute layout(絕對布局),flowlayout(流式布局),borderlayout(邊界布局),gridlayout(網格布局)cardlayout(卡片布局)
具體看http://zhangjunhd.blog.51cto.com/113473/128174/
寫寫我最愛的cardlayout
CardLayout cl=new CardLayout ();
JPanel jp=new JPanel();
jp.setLayout(sl);
添加卡片
jp.add(JPanel1,"JPanel1");
jpadd(JPanel2,"JPanel2");
*****
跳轉
cl.first(jp);
cl.next(jp);
cl.last(jp);
cl.show(jp,"JPanel");這就任意跳轉了。
3.按鈕事件----彈窗
類JFileChooser
JFileChooser.setFileSelectionMode(arg)--------參數arg可以使JFileChooser.File_ONLY、JFileChooser.Directories_ONLY和JFileChooser.File_and_Directories.以此控制視窗的選擇對象。
提示小視窗(dialog)
JOptionpane.showMessageDialog(null,"內容","title",JOptionpane.error_message) 注意:此視窗點擊後不中斷程式,繼續向下運行。
其他http://blog.csdn.net/penjie0418/article/details/9257917
4.背景設定
JPanel背景
new JPanel(){
protected void paintComponent(Graphics g){
此處省略
}
}
組件背景
ImageIcon icon=new ImageIcon("BufferImage");
組件名.setIcon(icon);
利用border設定背景
自訂myborder重寫paintBorder()
new Border(){
public void paintBorder(Component c,Graphics g,int x,int y,int width,int height){
此處省略。。。
}
}
在為contentPane設定border
contentPane.setBorder(myborder);如此可以直接在畫板上添加組件。
5.自訂frame視窗
setUndecorated(true);去掉原來的邊框,自己在contentPane上添加一些功能組件(最小化、最大化、exit等),在邊框範圍添加滑鼠事件,時期可拖動視窗。這樣就比較炫了
JAVA的swing編程筆記