Visual J++ 6.0 (VJ6) 是微軟在 Java 戰略上的關鍵產物:將 Java 語言塞入 Visual Studio 體系,捆綁 WFC (Windows Foundation Classes) 直通 Win32 API,提供 VB 風格的 RAD 體驗。雖因違反 Java 兼容性規範敗訴 Sun、隨後被 C#/.NET 取代,但其調試器優秀、介面熟悉、智能感知超前的特點,曾讓無數 Windows 開發者輕鬆入門 Java。本文整理 VJ6 完整使用流程,供維護舊專案或考古研究者參考。
加入項目 (類/表單/網頁/現有文件) —— 核心擴充專案入口。工具 → 選項 → 文字編輯器 → Java 格式 客製化。System. 彈出成員列表,輸入 o 定位 out,空格確認;out. 再列出 println 等,帶參數簽名提示 (1 of 10)。啟用:工具 → 選項 → 文字編輯器 → 每種語言 → 自動列出成員。WFC (Windows Foundation Classes) 封裝 Win32 API,提供 com.ms.wfc.* 套件,實現 VB 風格拖放表單開發。
import com.ms.wfc.app.*; 即使用 WFC。// 1. 新建專案:檔案 → 新建專案 → Visual J++ Projects → Console Application
// 2. VJ6 自動生成骨架
public class Class1 {
public static void main(String[] args) {
// TODO: 在此加入初始化代碼
}
}
// 3. 撰寫代碼 (體驗智能感知)
System.out.println("Hello!"); // 輸入 Sys[.]o[ ]p[.]p[.]ln("Hello!")
// 4. 建置/執行
// 工具列「播放」圖示 = 自動建置 + 執行
// 或 偵錯 → 啟動 (F5)
// 彈出 DOS 視窗輸出:Hello!
目標:兩個編輯框 + 一按鈕,點擊按鈕將 Edit1 內容複製到 Edit2 (禁用編輯)。
Form1 設計介面。Edit 控件 (自動命名 edit1, edit2) 與一個 Button (button1)。edit2,屬性視窗將 Enabled 設為 False。button1 進入事件處理器:private void button1_click(Object source, Event e) {
edit2.setText(edit1.getText());
}
完整生成代碼結構 (節選):
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
public class Form1 extends Form {
// 控件宣告
Container components = new Container();
Edit edit1 = new Edit();
Edit edit2 = new Edit();
Button button1 = new Button();
public Form1() { initForm(); } // 設計器生成初始化
private void initForm() {
// 佈局座標、大小、TabIndex、事件綁定
button1.addOnClick(new EventHandler(this.button1_click));
this.setNewControls(new Control[] { button1, edit2, edit1 });
}
private void button1_click(Object source, Event e) {
edit2.setText(edit1.getText());
}
public static void main(String args[]) {
Application.run(new Form1());
}
}
VJ6 無視覺化設計器支援標準 AWT/Swing,需手寫代碼:
Frame/JFrame、Panel/JPanel、佈局管理器、事件監聽器代碼。提示:多文件專案必須掌握「加入項目」流程,否則無法管理依賴。
Applet1.java + Page1.html。Page1.html 進入所見即所得編輯,右鍵 Applet 區域選「Always View as Text」查看/編輯標籤:<applet code=Applet1.class name=movetext width=400 height=100 VIEWASTEXT>
<param name=string value="你好,這是一個例子!">
<param name=font value="新細明體">
<param name=style value=BOLD>
<param name=size value=40>
<param name=speed value=20>
</applet>
Applet1.java,在 init() 讀取參數,paint() 繪製,start()/run()/stop() 管理執行緒滾動 (實現 Runnable)。關鍵片段:public class Applet1 extends Applet implements Runnable {
Font ft; String theString; int size, speed, xSet, Max, Min;
public void init() {
theString = getParameter("string");
// ... 讀取 font, size, speed 參數 ...
ft = new Font(font, vice_style, size);
FontMetrics fm = getFontMetrics(ft);
Min = -fm.stringWidth(theString);
Max = getSize().width;
xSet = Max;
}
public void paint(Graphics g) {
g.setFont(ft); g.setColor(Color.red);
g.drawString(theString, xSet, getSize().height/2);
}
public void run() {
while (true) {
try { repaint(); Thread.sleep(speed); }
catch (InterruptedException e) {}
}
}
// start()/stop() 管理執行緒生命週期...
}
VJ6 以「熟悉的 VS 介面 + 極強調試 + WFC RAD」降低了 Windows 開發者進入 Java 的門檻,但綁定專有類庫、背離標準、缺乏跨平台註定其成為過渡產物。今日回顧:
維護 VJ6 專案時,建議:隔離 WFC 代碼、逐模組遷移至標準 Java/Swing/SWT、引入 Maven/Gradle 建構、切換至 IntelliJ/Eclipse 開發,勿在新專案投入 WFC 技術債。