顯示具有 B4-A-I-J 標籤的文章。 顯示所有文章
顯示具有 B4-A-I-J 標籤的文章。 顯示所有文章

2015年12月15日 星期二

B4J 8:windows 執行 jar

參考來源:Running JAR file on Windows
---
執行指令 : java -jar MyJavaTool.jar
---
經過 B4J run 過後,實際已轉譯出 .jar 檔 ; 這已是可在windows 有安裝 java 虛擬器下執行了!

利用 windows command 來執行 jar
---



B4J 7:MySQL 連線

須先下載 mysql-connector-java-5.1.38-bin.jar  (for mysql)
---

---
mysql 較麻煩 , 會有亂碼問題!!
再一開始建立資料庫時就必須定義好編碼 (如:big5 或 utf8 )
再UI 建檔部分也須定義確定讀取資料庫時,要採用big5或utf8 ; 必須是一致性

B4J 6:MSSQL 連線

須先下載 jtds-1.3.1.jar (for MSSQL)
---



B4J MSSQL 2008 / JDBC

官網下載 : jTDS JDBC Driver參考範例 : How do I connect to a SQL Server 2008 database using JDBC?
--
java :
Class.forName( "net.sourceforge.jtds.jdbc.Driver" );
Connection con = DriverManager.getConnection( "jdbc:jtds:sqlserver://address>:1433/zacmpf", userName, password );
Statement stmt = con.createStatement();

--
原則在 B4J 一樣套用這樣的參數帶入即可

2015年12月10日 星期四

B4J 使用 UI 工具 JavaFX Scene Builder 下載

官網 :oracle - JavaFX Scene Builder Archive 下載
--
要執行 FXML 一直出現錯誤!! = . = 搞不懂...狂查

實在是  ...
---
原來是缺 : JavaFX Scene Builder    UI 編輯器

到官網也不知道是哪一個,太多資源了!!
官網下載頁面
找 : Java Archive 這一個就對了!!
拉到底 : 就看到了

---
底下是 : B4J 開 FXML 畫面







B4J 一些範例參考

B4J 一些範例參考
--

B4J 5:練習:加法



B4J HowTos 英文版線上教學

B4J HowTos 英文版線上教學
--
不錯喔! 可以練功力!!

B4J 4:將 b4j 編譯成windows 執行檔 exe

還是要參考官網作法 Create Windows native executables (exe files)
---
** 要產 windows exe 主要是透過 Launch4j 這支工具 Download Launch4j
---
底下是設定和編譯 windows exe (重點在 : 必須指定 JRE 的最低版本 )






B4J 3:程式架構分析

一.程式分析:

1.說明目前這個 Form 的寬和高
#Region  Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
#End Region


2.程序的全域定義 (這只限於本Form的定義)
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Button1 As Button
Private TextField1 As TextField
Private Label1 As Label
End Sub

3.這支程式啟動及相關載入設定值
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.RootPane.LoadLayout("Lay01") 'Load the layout file.
MainForm.Show
TextField1.Text =""
End Sub

4.點擊 Button1 的事件處理
Sub Button1_Action
If IsNumber(TextField1.Text ) Then
If TextField1.Text>=0 And TextField1.Text<=100 Then
Label1.Text ="0-100數值!!"
Else If TextField1.Text>=101 And TextField1.Text<=999 Then
Label1.Text ="101-999數值!!"
Else If TextField1.Text>=1000 Then
Label1.Text ="數值大於等於1000"
End If
Else
Label1.Text ="請輸入數值!!"
End If
 
End Sub

二.檔案存放分析:
依本程式共有 2 檔  2 目錄 :
*.b4j   --- 程式碼
*.meta (依官方的說法) 可建立附加的文件(採用META-INF格式)目錄
Files ---存放UI設計檔區
[Objects] 存放核心檔了
1.轉換 java 後的 *.jar
2.scr  表示 B4J 內容程序將 VB 轉譯為java 語法 所存放的位置
3.bin 目錄 -- 這個就不理它了 !


三.分析B4J轉譯 java 的程式碼    (底下看完,就應該知道 B4J 怎運作VB to java 了)
[不過,Layout 就是精華了! 這部分官方就編譯過了,不需研究了]


package b4j.example;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.debug.*;

public class main extends javafx.application.Application{
public static main mostCurrent = new main();

public static BA ba;
static {
ba = new  anywheresoftware.b4j.objects.FxBA("b4j.example", "b4j.example.main", null);
ba.loadHtSubs(main.class);
        if (ba.getClass().getName().endsWith("ShellBA")) {

ba.raiseEvent2(null, true, "SHELL", false);
ba.raiseEvent2(null, true, "CREATE", true, "b4j.example.main", ba);
}
}
    public static Class getObject() {
return main.class;
}


    public static void main(String[] args) {
    launch(args);
    }
    public void start (javafx.stage.Stage stage) {
        try {
            anywheresoftware.b4j.objects.FxBA.application = this;
   anywheresoftware.b4a.keywords.Common.setDensity(javafx.stage.Screen.getPrimary().getDpi());
            BA.Log("Program started.");
            initializeProcessGlobals();
            anywheresoftware.b4j.objects.Form frm = new anywheresoftware.b4j.objects.Form();
            frm.initWithStage(ba, stage, 600, 400);
            ba.raiseEvent(null, "appstart", frm, (String[])getParameters().getRaw().toArray(new String[0]));
        } catch (Throwable t) {
            BA.printException(t, true);
            System.exit(1);
        }
    }
public static anywheresoftware.b4a.keywords.Common __c = null;
public static anywheresoftware.b4j.objects.JFX _fx = null;
public static anywheresoftware.b4j.objects.Form _mainform = null;
public static anywheresoftware.b4j.objects.ButtonWrapper _button1 = null;
public static anywheresoftware.b4j.objects.TextInputControlWrapper.TextFieldWrapper _textfield1 = null;
public static anywheresoftware.b4j.objects.LabelWrapper _label1 = null;
public static String  _appstart(anywheresoftware.b4j.objects.Form _form1,String[] _args) throws Exception{
 //BA.debugLineNum = 14;BA.debugLine="Sub AppStart (Form1 As Form, Args() As String)";
 //BA.debugLineNum = 15;BA.debugLine="MainForm = Form1";
_mainform = _form1;
 //BA.debugLineNum = 16;BA.debugLine="MainForm.SetFormStyle(\"UNIFIED\")";
_mainform.SetFormStyle("UNIFIED");
 //BA.debugLineNum = 17;BA.debugLine="MainForm.RootPane.LoadLayout(\"Lay01\") 'Load the l";
_mainform.getRootPane().LoadLayout(ba,"Lay01");
 //BA.debugLineNum = 18;BA.debugLine="MainForm.Show";
_mainform.Show();
 //BA.debugLineNum = 19;BA.debugLine="TextField1.Text =\"\"";
_textfield1.setText("");
 //BA.debugLineNum = 20;BA.debugLine="End Sub";
return "";
}
public static String  _button1_action() throws Exception{
 //BA.debugLineNum = 22;BA.debugLine="Sub Button1_Action";
 //BA.debugLineNum = 23;BA.debugLine="If IsNumber(TextField1.Text ) Then";
if (anywheresoftware.b4a.keywords.Common.IsNumber(_textfield1.getText())) {
 //BA.debugLineNum = 24;BA.debugLine="If TextField1.Text>=0 And TextField1.Text<=100 T";
if ((double)(Double.parseDouble(_textfield1.getText()))>=0 && (double)(Double.parseDouble(_textfield1.getText()))<=100) {
 //BA.debugLineNum = 25;BA.debugLine="Label1.Text =\"0-100數值!!\"";
_label1.setText("0-100數值!!");
 }else if((double)(Double.parseDouble(_textfield1.getText()))>=101 && (double)(Double.parseDouble(_textfield1.getText()))<=999) {
 //BA.debugLineNum = 27;BA.debugLine="Label1.Text =\"101-999數值!!\"";
_label1.setText("101-999數值!!");
 }else if((double)(Double.parseDouble(_textfield1.getText()))>=1000) {
 //BA.debugLineNum = 29;BA.debugLine="Label1.Text =\"數值大於等於1000\"";
_label1.setText("數值大於等於1000");
 };
 }else {
 //BA.debugLineNum = 32;BA.debugLine="Label1.Text =\"請輸入數值!!\"";
_label1.setText("請輸入數值!!");
 };
 //BA.debugLineNum = 35;BA.debugLine="End Sub";
return "";
}

private static boolean processGlobalsRun;
public static void initializeProcessGlobals() {
 
    if (main.processGlobalsRun == false) {
   main.processGlobalsRun = true;
try {
       main._process_globals();

        } catch (Exception e) {
throw new RuntimeException(e);
}
    }
}public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 6;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 7;BA.debugLine="Private fx As JFX";
_fx = new anywheresoftware.b4j.objects.JFX();
 //BA.debugLineNum = 8;BA.debugLine="Private MainForm As Form";
_mainform = new anywheresoftware.b4j.objects.Form();
 //BA.debugLineNum = 9;BA.debugLine="Private Button1 As Button";
_button1 = new anywheresoftware.b4j.objects.ButtonWrapper();
 //BA.debugLineNum = 10;BA.debugLine="Private TextField1 As TextField";
_textfield1 = new anywheresoftware.b4j.objects.TextInputControlWrapper.TextFieldWrapper();
 //BA.debugLineNum = 11;BA.debugLine="Private Label1 As Label";
_label1 = new anywheresoftware.b4j.objects.LabelWrapper();
 //BA.debugLineNum = 12;BA.debugLine="End Sub";
return "";
}
}

B4J 2:第一支程式

本篇仿照官方的教學影片 官網 Documentation :(video) UI App / Designer  來作的!
當然不一定要完全一樣 (稍看了設計和作法,自己動手作1支來玩看看)
---
程式和UI 的設定:


執行結果:

B4J 1:安裝篇

官網:B4X - The simple way to develop native Android, iOS & IoT apps
--
1.先到官網下載 B4J  (free) 完全免費,可開發 windows / linux / mac / ARM 等平台
2.下載 B4J 開發工具
3.下載並安裝 Java JDK v8
Java 8 JDK 下載
可參考官網的 b4j 安裝和需求說明

4.安裝順序
01.安裝 java JDK 8.xx (或更高)
02.安裝 framework 4.0 (必須4.0 或更高)
03.安裝 B4J

5.設定 B4J 的路徑設定值
java . lib .modules 等路徑



以上就完成 B4J 的安裝了

2015年12月9日 星期三

B4A,B4I,B4J

B4X - The simple way to develop native Android, iOS & IoT apps
---
新的開發工具 ...
B4J 是完全免費的, 可以練練功力 !! 採用 VB 語言 , 內部又包了 java lib 來跑 !!
值得試試看