java基礎知識(二)

來源:互聯網
上載者:User

標籤:

  • java的布局管理:
    • borderLayout:則將板塊分為東西南北中五個方向,每添加一個組件就要指定組件擺放的方位,放置在東西南北四個方向的組件將貼邊放置.當拉大Frame的時候,處在center(中間)的組件就不斷積壓東西南北四個方向的組件(邊界布局)
    • flowLayout:是將組件流水似的擺放在Frame或其它構件上,從左至右,依次排放,遇到邊界就重新另起行,順序排放,整體置放在中央的位置(流式布局)
    • GridLayout:就是分幾行幾列將組件擺放到Frame上去,幾個組件也是貼邊放置的(網格布局)
  • JoptionPane:
    1. showConfirmDialog()
    2. showInputDialog()
    3. showMessageDialog()
    4. showOptionDialog()
    5. 學習網站
  • ActionLister的三種實現方法
    • 定義一個監聽類實現ActionLister介面
    • 用匿名內部類來實現監聽事件
    • 用命名內部類來實現監聽事件
    • 常用的方法:
      1. getActionCommand()//擷取按鈕名稱
      2. getSource()//擷取資源類型
    • 事件監聽學習網站
  • Runtime類和Process類
    • Runtime.getRuntime()//擷取當前應用程式的Runtime對象
    • exec()//執行外部程式或任務,返回為process類型‘
    • 執行個體
      1. 通過exec()執行外部的程式,作為當前進程的一個子進程。
      2. 代碼public class RuntimeTest {    public static void main(String[] args) throws Exception{        Runtime runtime = Runtime.getRuntime();//Runtime.getRuntime()用來擷取Runtime類的一個執行個體。        runtime.exec("notepad");// 開啟一個記事本程式    }}
      3. 通過exec()方法還可以去編譯和運行java的源檔案。 
      4. 代碼public class RuntimeTest {    public static void main(String[] args) {        Runtime rt = Runtime.getRuntime();// 擷取Runtime 類的執行個體        // System.out.println(rt.freeMemory());        // System.out.println(rt.totalMemory());        try {            // Process java.lang.Runtime.exec(String command)            // 執行一個外部程式來作為當前程式的一個子進程            // rt.exec("notepad");            // 也可以使用exec來編譯JAVA的源檔案。            rt.exec("javac Hello.java");            Process p = rt.exec("java Hello");            InputStream is = p.getInputStream();// 擷取輸入資料流            int data;            while ((data = is.read()) != -1) {                System.out.print((char) data);            }        } catch (IOException e) {            e.printStackTrace();        }    }}class Hello {    public static void main(String[] args) {        System.out.println("Hello World");    }}

          

          

       

java基礎知識(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.