# NOT RUN {
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" ) )
# }
# NOT RUN {
# inner class example
<!-- % TODO: find a better example -->
HashMap <- J("java.util.HashMap")
with( HashMap, new( SimpleEntry, "key", "value" ) )
with( HashMap, SimpleEntry )
# }
# NOT RUN {
with( J("java.lang.System"), getProperty("java.home") )
# }
# NOT RUN {
# }
Run the code above in your browser using DataCamp Workspace