2012年10月20日 星期六

Java Swing──傻傻分不清,混亂的概念

Pane?Panel?Component?Layout?Container?
好吧,我終於混亂了

今天趁著有空去大概翻了幾篇入門介紹
總算小有心得。



Frame

所謂的視窗(Frame)
幾乎是所有應用程式都有視窗~~

Container

中文翻譯通常為"容器"

根據Java官網,java.awt.Container的敘述
java.awt.Container繼承自java.awt.Component

A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT components.
Components added to a container are tracked in a list. The order of the list will define the components' front-to-back stacking order within the container. If no index is specified when adding a component to a container, it will be added to the end of the list (and hence to the bottom of the stacking order).
 一個AWT容器物件也是元件(Component)的一種,它能容納其他元件。

 Component

中文翻譯通常為"元件"

 A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. Examples of components are the buttons, checkboxes, and scrollbars of a typical graphical user interface.

根據orcale官方說法,元件是一種能在螢幕上有圖形表現、跟使用者互動的物件。
像是按鈕、畫布、選取盒等等東西就是他的子類別~

Layout

中文翻譯五花八門,我是比較喜歡"佈局"這個

Interface LayoutManager

All Known Subinterfaces:
LayoutManager2
All Known Implementing Classes:
BasicComboBoxUI.ComboBoxLayoutManager, BasicInternalFrameTitlePane.TitlePaneLayout, BasicInternalFrameUI.InternalFrameLayout, BasicOptionPaneUI.ButtonAreaLayout, BasicScrollBarUI, BasicSplitPaneDivider.DividerLayout, BasicSplitPaneUI.BasicHorizontalLayoutManager, BasicSplitPaneUI.BasicVerticalLayoutManager, BasicTabbedPaneUI.TabbedPaneLayout, BorderLayout, BoxLayout, CardLayout, DefaultMenuLayout, FlowLayout, GridBagLayout, GridLayout, GroupLayout, JRootPane.RootLayout, JSpinner.DateEditor, JSpinner.DefaultEditor, JSpinner.ListEditor, JSpinner.NumberEditor, MetalComboBoxUI.MetalComboBoxLayoutManager, MetalScrollBarUI, MetalTabbedPaneUI.TabbedPaneLayout, OverlayLayout, ScrollPaneLayout, ScrollPaneLayout.UIResource, SpringLayout, SynthScrollBarUI, ViewportLayout


佈局管理器(Layout Manager)是一種介面,眼花撩亂,
實作它的人多到很恐怖
可見JAVA提供的佈局種類有多少了~~
還沒完,還有LayoutManager2
LM2裡面放的是Swing複雜格局中比較常用的~~

Defines the interface for classes that know how to lay out Containers.
佈局的功用就是告訴容器們裡面要怎麼擺放元件(Component)。
要是流動式的呢?還是東南西北中麻將式的?還是像切豆腐那樣幾行幾列的?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以上都還簡單。。。
下面就很Confuse 了=     ="
Panel?Pane?困擾我很久的問題了


Panel

中文翻譯通常為"面板"

public class Panel
extends Container
implements Accessible
Panel is the simplest container class. A panel provides space in which an application can attach any other component, including other panels. The default layout manager for a panel is the FlowLayout layout manager.

Panel類別是繼承自容器類別~
它是最簡單的容器
然後可以設定佈局方式(Layout)

A pane is a (usually) independently scrollable subsection of a window. It's what you get, for example, if you drag the splitter bar in a Word window.

A panel is an object that is used to group controls and other objects. It is often but not always dragable, occasionally resizable or
scrollable. Most toolbars, for example, consist of a panel with buttons. Panels may or may not have a visible border.

Pane

中文翻譯為"窗格"

它通常是一個視窗中一個可捲動的獨立次單位。
Panel則是用來整理一些物件的群組

http://simon.blog.51cto.com/80/122148
這裡有些講解

其實也沒有說得很清楚,英文網站上的資料也不是很齊全,可能還是要去翻翻書了
(其實外國人也搞不太懂,我只能確定這一點=   =")













結果根本沒講到甚麼重點嘛。。。。((頂鍋蓋逃走。。。

沒有留言:

張貼留言