DrJava 的 Interactions Pane 很好玩

DrJava – http://drjava.sourceforge.net/

一個小型的 Java IDE,有個很棒的功能 – Interactions Pane

例如依序輸入下面三行

import javax.swing.*;
JFrame frame = new JFrame("My JFrame");
frame.setVisible(true);

在第三行輸入完按 Enter 後就會有個 JFrame 出現 Figure 1

然後加入一個 JLabel

frame.getContentPane().add(new JLabel("DrJava Test"));
frame.pack();

Figure 2

把 JLabel 拿掉

frame.getContentPane().removeAll();
frame.pack();

Figure 3

如果沒有加分號,會把那行的東西印出來,像是接著只打 frame 按 Enter,會印出前面宣告的 JFrame 的資料

Figure 4

它還有提供一個 Eclipse Plugin,功能是可以在 Eclipse 裡使用 Interactions Pane

目前的 0.9.5 版有點小問題,解開壓縮檔之後要先編輯它的 plugin.xml 檔案

把這幾行

<requires>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.debug.ui"/>
<import plugin="org.eclipse.jdt.ui"/>
<import plugin="org.eclipse.jdt.core"/>
<import plugin="org.eclipse.console.ui"/>
</requires>

改成

<requires>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.debug.ui"/>
<import plugin="org.eclipse.jdt.ui"/>
<import plugin="org.eclipse.jdt.core"/>
<import plugin="org.eclipse.ui.console"/>
<import plugin="org.eclipse.core.runtime.compatibility"/>
<import plugin="org.eclipse.search"/>
</requires>

才不會開 DrJava 的 perspective 時出錯

(如果改完還看不到可以開的 perspective 裡有 DrJava,用 -clean 參數重新啟動 Eclipse)


  • 留言者: Duncan
  • Email:
  • 網址:
  • 日期: 2004-10-20 11:36:29

請問妳知道要怎麼在 interactive pane 裡面 list 已定義(assigned)的變數嗎?我看 help 也沒提到這點。

在 rebind 變數的時候,似乎不能 re-assign 不同 type 的 reference/value 給以定義過的變數,在無法列出已定義的變數環境下還得記憶變數的 type 實在有點累人。

另外在 interactive 環境裡直接 assign reference 給莫名的變數,也違反了 Java 的 OO model,會讓新手誤以為有 global variable 的存在,雖可以想像成有個 InetractiveConsole class 存在,而在 interactive pane 輸入的碼當作 class initializer 的內容,變數則是 static field,但是這也會造成新手感覺到 static field 可以動態增加的錯覺。


  • 留言者: JiaYun
  • Email:
  • 網址:
  • 日期: 2004-10-20 22:14:33

好像沒辦法列出已定義的變數,文件裡也沒寫….

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *