我正在学习JavaScript,最近我一直在试验鼠标事件,试图了解它们是如何工作的.
<html>
<head>
<title>Mouse Events Example</title>
<script type="text/javascript">
function handleEvent(oEvent) {
var oTextbox = document.getElementById("txt1");
oTextbox.value += "\n" + oEvent.type;
if(oEvent.type=="click")
{
var iScreenX = oEvent.screenX;
var iScreenY = oEvent.screenY;
var b = "Clicked at "+iScreenX+" , "+iScreenY;
alert(b);
}
}
function handleEvent1(oEvent) {
// alert("Left Window");
}
</script>
</head>
<body>
<p>Use your mouse to click and double click the red square</p>
<div style="width: 100px; height: 100px; background-color: red"
onmouseover="handleEvent(event)"
onmouseout="handleEvent1(event)"
onmousedown="handleEvent(event)"
onmouseup="handleEvent(event)"
onclick="handleEvent(event)"
ondblclick="handleEvent(event)" id="div1"></div>
<p><textarea id="txt1" rows="15" cols="50"></textarea></p> …Run Code Online (Sandbox Code Playgroud) 最近我决定通过重构简单的代码片段来研究Java 8.我有以下示例,我试图转换为Java 8表示.
public static void halfTriangle(){
for(int i=1; i<=4; i++){
for(int j=1; j<=i; j++){
System.out.print("* ");
}
System.out.println(" ");
}
}
Run Code Online (Sandbox Code Playgroud)
我设法想出这样的东西:
public static void halfTriangleJava8(){
IntStream.range(1, 5)
.forEach(i -> IntStream.range(1, 5)
.forEach(j -> System.out.println("* "))
);
}
Run Code Online (Sandbox Code Playgroud)
但我不知道我可以留在哪里:
System.out.println(" ");
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的东西:
public static void halfTriangleJava8(){
IntStream.range(1, 5)
.forEach(i -> {
IntStream.range(1, 5);
System.out.println(" ");
}
.forEach(j -> System.out.println("* "))
);
}
Run Code Online (Sandbox Code Playgroud)
但它给了我一个我不完全理解的错误."此表达式的目标类型必须是功能接口".
我相信这是一个非常简单的错误,但我今天才开始研究Java 8,所以任何帮助都会非常感激.