我将Java中空白的JFrame应用程序基本转换为JavaScript

好的,这是我的自我挑战,我想问你们:“这看起来像是一次准确的转换”。 这是Java,然后是JavaScript:

爪哇

import java.awt.*;
import javax.swing.*;

public class Program {
    public static void main(String[] args) {
        // Initialize the window
        JFrame win = new JFrame("Window");

        // Set it's size
        win.setPreferredSize(new Dimension(100,100));

        // Set the background color to black
        win.contentPane().background(Color.BLACK);

        // Make the window visible
        win.setVisible(true);
    }
}

JAVASCRIPT

const statictype = function(type,value) {
    if((typeof type !== " undefined" && type !== undefined) && value !== undefined) {
        if(type.constructor.name === value.constructor.name) { return value }
    }
    throw TypeError("Static types did not match")
}

const Program = function() {
    return new Program()
}
Program.main = Object.freeze(
    function main(...args) {
        // Initialize the window
        let win = document.createElement("div")

        // Set it's size
        win.style = "min-width:1px; min-height:26px; width:100px;\
 height:125px; position:absolute; top:"+(screen.availHeight-125)+"px;\
 left:"+(screen.availWidth-100)+"px; border-color:black; border-width:1px;\
 border-style:solid; resize:both; overflow:hidden;"
        let win_titlebar = document.createElement("div")
        win_titlebar.innerText = "Window"
        win_titlebar.style = "min-height:25px; min-width:100px;\
 max-height:25px; max-width:100px; height:25px; width:100px;\
 background-color:white; position:absolute; top:0px; left:0px;"
        win.appendChild(win_titlebar)
        delete win_titlebar

        // Make the background color black
        let win_screen = document.createElement("canvas")
        win_screen.style = "background-color:black;\
 position:absolute; top:26px; left:0px;"
        win.appendChild(win_screen)
        delete win_screen

        // Make the window visible
        document.head.parentNode.appendChild(win)
        return undefined
    }
)

Program.main()

因此,正如我所问,这是否准确?

from: https://dev.to//calin92540842/my-basic-conversion-of-a-blank-jframe-application-in-java-to-javascript-jaf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值