.jinit()
if (!nzchar(Sys.getenv("NOAWT"))) {
p <- .jnew( "java/awt/Point", 0L, 0L )
with( p, {
# x and y and now 0
move( 10L, 10L )
# x and y are now 10
x <- x + y
} )
f <- within( .jnew( "javax/swing/JFrame" ) , {
layout <- .jnew( "java/awt/BorderLayout" )
setLayout( layout )
add( .jnew( "javax/swing/JLabel", "north" ), layout$NORTH )
add( .jnew( "javax/swing/JLabel", "south" ), layout$SOUTH )
add( .jnew( "javax/swing/JLabel", "west" ), layout$WEST )
add( .jnew( "javax/swing/JLabel", "east" ), layout$EAST )
setSize( .jnew( "java/awt/Dimension", 400L, 400L ) )
setVisible( TRUE )
} )
}
Double <- J("java.lang.Double")
with( Double, MIN_VALUE )
with( Double, parseDouble( "10.2" ) )
if (FALSE) {
# inner class example
HashMap <- J("java.util.HashMap")
with( HashMap, new( SimpleEntry, "key", "value" ) )
with( HashMap, SimpleEntry )
}
with( J("java.lang.System"), getProperty("java.home") )
# \dontshow{
stopifnot( with( Double, parseDouble("10.0") ) == 10.0 )
d <- new( Double, "10.0")
stopifnot( with( d, doubleValue() ) == 10.0 )
# }
Run the code above in your browser using DataLab