我有两层(= AnchorPanes)堆叠其中一个与StackPane.所以这两个层都填满整个场景.问题是,只有顶层接收鼠标事件.
多数民众赞成如何建立场景:
只有按钮B接收点击事件,但按钮A没有.
如果我将图层B设置为鼠标透明(layerB.setMouseTransparent(true)
),则按钮A会接收鼠标事件.但鼠标透明效果也是所有孩子,因此Button B不再接收鼠标事件.
如何让按钮A和按钮B接收鼠标事件?
以下是完整的工作来源:
public class LayerTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final Node layerA = createLayerA();
final Node layerB = createLayerB();
final Parent root = new StackPane(layerA, layerB);
final Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setWidth(250);
primaryStage.setHeight(200);
primaryStage.show();
}
private Node createLayerA() {
final AnchorPane layerA = new AnchorPane();
final Button buttonA = new Button("Button A");
AnchorPane.setLeftAnchor(buttonA, 10d);
AnchorPane.setTopAnchor(buttonA, 10d);
buttonA.setOnMouseClicked(e -> System.out.println("Button A clicked"));
layerA.getChildren().setAll(buttonA); …
Run Code Online (Sandbox Code Playgroud) 我是ANTLR4的新手,似乎没有针对v4的Eclipse-Plug-In.因此,从.g4语法自动构建Java源代码会很好.我有一个简单的空Maven项目,带有src/main/java,src/test/java.在哪里放置.g4文件?如何使用Maven自动构建语法?
我自己的POM测试失败了:
<repository>
<id>mvn-public</id>
<name>MVNRepository</name>
<url>http://mvnrepository.com</url>
</repository>
...
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
Eclipse说:
Failure to find org.antlr:antlr4-maven-plugin:pom:4.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of
central has elapsed or updates are forced
Run Code Online (Sandbox Code Playgroud) 有一个Pane
根和一个GridPane
孩子.根调整阶段大小.我怎样才能做到这一点的GridPane
被自动与根填补宽度调整?应该有任何宽度.没有财产绑定可能吗?
情况就是这样:
Pane
根(黄色)是的根Scene
,使其充满的宽度和高度Stage
.GridPane
(绿色)有一行和三个列作为root的子.GridPane
应填写其父的宽度码:
@Override
public void start(Stage primaryStage) throws Exception {
// Resizes with the stage
final Pane root = new Pane();
root.setStyle("-fx-background-color: yellow");
// grid: 1 row, 3 colums
// should have a constant height and should grow in width to fill parent pane
final GridPane gridPane …
Run Code Online (Sandbox Code Playgroud) Media
-class 只有一个构造函数:public Media(java.lang.String source)
参见http://docs.oracle.com/javafx/2/api/javafx/scene/media/Media.html#Media%28java.lang.String%29
此构造函数获取URI作为字符串.我有一个JavaFX项目,并在此项目中放置了一个WAV文件.当我将项目部署为JAR时,我可以看到(例如7-Zip)WAV文件也被导出.获取内容没有问题
MyApplicationClass.class.getResourceAsStream("/resources/test.wav").
Run Code Online (Sandbox Code Playgroud)
但是,在部署的JAR中为Media
构造函数引用此WAV文件的正确URI是什么?URI
new Media("jar:.!/resources/test.wav")
Run Code Online (Sandbox Code Playgroud)
不起作用.URI也"jar:resources/test.wav"
失败了(因为没有对JAR文件的引用).
有没有人知道正确的URI?
我正在使用org.eclipse.jdt.annotation.NonNull为静态空值分析添加额外信息.我不知道如何正确地注释数组:
我测试过:
public static void test(@NonNull String[] a) {
assert a != null;
}
public static void main(String[] args) {
test(null);
}
Run Code Online (Sandbox Code Playgroud)
但是,Eclipse没有标记test(null);
为错误.
它是Eclipse中的错误还是为什么我不能用完全限定类型名称(FQN)注释参数@NonNull
?
import org.eclipse.jdt.annotation.NonNull;
public class Foo {
// No problem
public void bar(@NonNull String x) {
}
// Error: Type annotations are not allowed on type names used to access
// static members
public void baz(@NonNull java.lang.String x) {
}
}
Run Code Online (Sandbox Code Playgroud) 我是Maxima的新手,并希望将它用于Denavit-Hartenberg矩阵(由许多cos和sin术语组成).问题是,maxima不会简化以下表达式:
ex: x*cos(pi);
Run Code Online (Sandbox Code Playgroud)
我希望,Maxima简化ex
为-x
.怎么做到这一点?(ratsimp(ex)
并且trigsimp(ex)
没有效果)
如何获取带星号的群组的内容?
例如,我想删除一个逗号分隔的列表,例如1,2,3,4,5
。
private static final String LIST_REGEX = "^(\\d+)(,\\d+)*$";
private static final Pattern LIST_PATTERN = Pattern.compile(LIST_REGEX);
public static void main(String[] args) {
final String list = "1,2,3,4,5";
final Matcher matcher = LIST_PATTERN.matcher(list);
System.out.println(matcher.matches());
for (int i = 0, n = matcher.groupCount(); i < n; i++) {
System.out.println(i + "\t" + matcher.group(i));
}
}
Run Code Online (Sandbox Code Playgroud)
输出是
true
0 1,2,3,4,5
1 1
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得每一个条目,即,,,,1
... ?2
3
我正在寻找一个共同的解决方案。这只是一个说明性示例。
请想象一个更复杂的正则表达式,^\\[(\\d+)(,\\d+)*\\]$
例如匹配列表[1,2,3,4,5]
我试图找出为什么它无法使用 GMail 从我的服务器发送邮件。为此,我使用 SwiftMailer,但我可以将问题附在以下隔离代码中:
<?php
$sock = stream_socket_client('tcp://smtp.gmail.com:587', $errno, $errstr);
if (false == $sock) {
die('error');
}
$server_response = fread($sock, 4096);
echo $server_response . PHP_EOL;
fclose($sock);
Run Code Online (Sandbox Code Playgroud)
当我在本地计算机(Windows 10、XAMPP、PHP 5.6.24)上运行此代码时,输出为:
220 smtp.gmail.com ESMTP qp16sm1358626ejb.89 - gsmtp
所以220意味着一切都很好。
但是当我在我的服务器(Debian Jessie,PHP 5.6.38)上运行完全相同的代码时,输出是:
421 4.7.0 稍后重试,关闭连接。
GMail 的错误参考https://support.google.com/a/answer/3726730没有针对此错误消息提供任何建议。
我也在没有 PHP 的服务器控制台上尝试过这个,它也能正常工作:
> nc smtp.gmail.com 587 $ 220 smtp.gmail.com ESMTP n11sm3188821wmi.15 - gsmtp
所以我可以界定问题
nc
命令工作正常)php.ini 的任何设置是否会导致此错误?
更新
只是为了好玩,我在另一台机器上的端口 587 上设置了一个简单的 TCP 服务器,并显示任何已连接客户端的 IP 地址。如果我使用上面的 PHP …
我首选的方法io_service
是在应用程序启动时创建一个执行io_service
run方法的线程.问题是,如果没有任务io_service
,其run方法立即返回并且线程终止.
正如您在chat_client.cpp中看到的那样
...
boost::asio::io_service io_service;
...
chat_client c(io_service, iterator);
boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));
Run Code Online (Sandbox Code Playgroud)
添加一些异步任务后启动该线程io_service
.这是在chat_clients
构造函数中完成的.
我的问题是:有没有办法在添加某个任务之前创建线程io_service
,即
// create io_service and thread on application start
boost::asio::io_service io_service;
boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));
// add some task to io_service
chat_client c(io_service, iterator);
Run Code Online (Sandbox Code Playgroud) 由于子命令支持(和基于注释的声明),我从 Apache Commons CLI 切换到 Picocli。
考虑一个像 这样的命令行工具git
,带有像 这样的子命令push
。Git 有一个主开关--verbose
或-v
用于在所有子命令中启用详细模式。如何实现在任何子命令之前执行的主开关?
这是我的测试
@CommandLine.Command(name = "push",
description = "Update remote refs along with associated objects")
class PushCommand implements Callable<Void> {
@Override
public Void call() throws Exception {
System.out.println("#PushCommand.call");
return null;
}
}
@CommandLine.Command(description = "Version control", subcommands = {PushCommand.class})
public class GitApp implements Callable<Void> {
@CommandLine.Option(names = {"-h", "--help"}, usageHelp = true, description = "Display this help message.")
private boolean usageHelpRequested; …
Run Code Online (Sandbox Code Playgroud) 我想在水平布局中放置一个标签和一个按钮(和一个文本字段)。这有效,但基线未对齐。如何解决?
预期的结果是红线(每个控件的基线)处于相同的高度。
这是 FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<HBox prefHeight="100.0" prefWidth="400.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="Label" />
<Button mnemonicParsing="false" text="Button" />
<TextField text="Lorem Ipsum" />
</children>
</HBox>
Run Code Online (Sandbox Code Playgroud) 这是一个简单的测试方法:
public static boolean isPowerOfTwo(final int i) {
return (i > 0) && (i & (i - 1)) == 0;
}
Run Code Online (Sandbox Code Playgroud)
要获取我javap -c
在 .class 文件上运行的字节码:
public static boolean isPowerOfTwo(int);
Code:
0: iload_0
1: ifle 14
4: iload_0
5: iload_0
6: iconst_1
7: isub
8: iand
9: ifne 14
12: iconst_1
13: ireturn
14: iconst_0
15: ireturn
Run Code Online (Sandbox Code Playgroud)
如您所见,有16个字节代码指令。
现在我运行一个简单的单元测试
@Test
public void testPowerOfTwoInt() {
assertFalse(Util.isPowerOfTwo(Integer.MAX_VALUE));
assertFalse(Util.isPowerOfTwo(0));
assertTrue(Util.isPowerOfTwo(64));
assertTrue(Util.isPowerOfTwo(128));
assertFalse(Util.isPowerOfTwo(-128));
}
Run Code Online (Sandbox Code Playgroud)
但是 JaCoCo 告诉我,isPowerOfTwo
它只包含12字节代码指令: …