好的,这是我的自我挑战,我想问你们:“这看起来像是一次准确的转换”。 这是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()
因此,正如我所问,这是否准确?