No announcement yet.

Java applet within a PowerBASIC app?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Java applet within a PowerBASIC app?

    I was looking at some Java apps, thinking of translating a few into PowerBASIC.

    But then I wondered if there was a way to play a Java applet within a PowerBASIC app?

    My forum search was somewhat fruitless.

    Has anyone made it work?

  • #2
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <TITLE> Java Test </TITLE>
      <APPLET CODE="PocketCalc.class" WIDTH="395" HEIGHT="179">
       Your browser doesn't support Java applets.
    <!-- Java applets can run in a Web browser using a Java Virtual Machine (JVM)
    This example applet available here:
    Display in PB using embedded browser -
    You'll need cwebpage.dll -
    Other examples of embedded browser on the forum from Jose and Semen that don't require third party DLLs
    Here's a version of Lance's code for the applet..
    #Compile Exe
    #Dim All
    #Include "WIN32API.INC"
    %ID_IE = 1000
    ' DLL rqd: [URL][/URL] 
    Declare Function EmbedBrowserObject   Lib "cwebpage.dll" Alias "EmbedBrowserObject"   (ByVal HWND As Dword) As Long
    Declare Sub      UnEmbedBrowserObject Lib "cwebpage.dll" Alias "UnEmbedBrowserObject" (ByVal HWND As Dword)
    Declare Function DisplayHTMLPage      Lib "cwebpage.dll" Alias "DisplayHTMLPage"      (ByVal HWND As Dword, LPCTSTR As Asciiz) As Long
    Declare Sub      ResizeBrowser        Lib "cwebpage.dll" Alias "ResizeBrowser"        (ByVal HWND As Dword, ByVal cx As Dword, ByVal cy As Dword)
    Declare CallBack Function ShowDIALOG1Proc()
    Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
    Function PBMain()As Long
      ShowDIALOG1 %HWND_Desktop
    End Function
    CallBack Function ShowDIALOG1Proc()
     Local x As Long, y As Long, RC As RECT
      Select Case As Long CbMsg
        Case %WM_InitDialog
          EmbedBrowserObject GetDlgItem(CbHndl, %ID_IE)
          Dialog Post CbHndl, %WM_User + 999&, 0, 0
        Case %WM_User + 999&
          MousePtr 0
          DisplayHTMLPage GetDlgItem(CbHndl, %ID_IE), EXE.Path$ + "Java Test.html"
        Case %WM_Size
          Dialog Get Client CbHndl To x,y
          Control Set Size CbHndl, %ID_IE, x - 65, y - 10
          Control Set Loc CbHndl, %IdOk, x - 55, 5
          Control Set Loc CbHndl, %IdCancel, x - 55, 24
          Dialog Units CbHndl, x - 65, y - 10 To Pixels x, y
          Dialog Units CbHndl, x, y To Pixels x, y
          ResizeBrowser GetDlgItem(CbHndl, %ID_IE), x-1, y-1
        Case %WM_Destroy
          MousePtr 1
          UnEmbedBrowserObject GetDlgItem(CbHndl, %ID_IE)
        Case %WM_Command
          If CbCtlMsg = %BN_Clicked Then
            Dialog End CbHndl, 0
          End If
      End Select
    End Function
    Function ShowDIALOG1(ByVal hParent As Dword) As Long
     Local hDlg As Dword
      Dialog New hParent, "Embedded Browser for Java Applet", 70, 70, 350, 230, %WS_Popup Or _
           %WS_Caption Or %WS_SysMenu Or %WS_ClipSiblings Or %DS_Center Or %WS_THICKFRAME To hDlg
        Control Add Label, hDlg, %ID_IE, "", 5, 5, 350-65, 230 - 10, %SS_Sunken
        Control Add Button, hDlg, %IdOk, "OK", 350 - 55, 5, 50, 14
        Control Add Button, hDlg, %IdCancel, "Cancel", 350 - 55, 24, 50, 14
      Dialog Show Modal hDlg, Call ShowDIALOG1Proc
    End Function
    Last edited by Dave Biggs; 27 Apr 2009, 08:59 AM. Reason: Added browser code
    Rgds, Dave


    • #3
      Thanks Dave!

      So the approach is to put a browser object in the PowerBASIC app, and the browser apps displays the applet.

      Whereas a direct embedment of just the Java applet isn't possible?


      • #4
        Apparently a utility, "Appletviewer" is included with Sun's JDK package. That is a standalone utility to run Java applets but I don't know if source code is included.
        Rgds, Dave


        • #5
          See the section named "Web Development" on José Roca's forum,
          it is the best place to learn how to use advanced (web) programming technics with PB.

          For animation purpose see also the "CSS Doc menu" example, or the GDImage carousel demo or the OfTheBay project (also on José's forum).

          Last edited by Patrice Terrier; 29 Apr 2009, 03:53 AM.
          Patrice Terrier

          Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).