我正在运行 Python 3.6,想知道是否有办法获取 Tkinter 使用的默认字体,更具体地说是调用Canvas对象时使用的默认字体。canvas.create_text
所以我使用 JaCoco maven 插件自动生成代码覆盖率报告,以便我可以将它们发送到 codecov 以显示在 GitHub 上。突然间,我从 JaCoco 那里得到了一个构建失败,说“未知块类型”。这不是昨天发生的,所以我不知道为什么现在会发生。这是我的 pom.xml 的相关部分
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如何解决此问题以正确生成覆盖率报告?
-X 跟踪
[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.8.5:report from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.8.5, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@55054057]
[DEBUG] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[DEBUG] Setting property: site.resource.loader.class => 'org.codehaus.plexus.velocity.SiteResourceLoader'.
[DEBUG] Setting property: velocimacro.messages.on => 'false'.
[DEBUG] Setting property: runtime.log.invalid.references => 'false'.
[DEBUG] Setting property: resource.loader => 'classpath,site'.
[DEBUG] Setting property: velocimacro.permissions.allow.inline.to.replace.global => 'true'. …Run Code Online (Sandbox Code Playgroud) 好的,所以我在使用自定义字体时遇到了问题。基本上我得到一个我从互联网上下载的自定义字体并在我的程序中使用它。当我在 Eclipse(我使用的编辑器)中运行程序时,一切正常,没有问题。但是,每当我从 eclipse 将它导出到 jar 时,或者尝试从命令提示符运行它时,我都会遇到这个非常烦人的错误:
java.io.IOException: Can't read REVOLUTION.ttf
at java.awt.Font.createFont(Unknown Source)
at TowerDefense.<init>(TowerDefense.java:55)
at TowerDefense.main(TowerDefense.java:302)
Run Code Online (Sandbox Code Playgroud)
由于我在哪里使用字体,我得到了一堆空指针异常。但我不知道为什么它说它无法读取。这是创建字体的代码:
try {
revolution = Font.createFont(Font.TRUETYPE_FONT, new File("REVOLUTION.ttf"));
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(revolution);
}
catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
文件夹布局
塔防
src
default package
TowerDefense.java
Game.java
DragTest.java
JRE System Library
REVOLUTION.ttf
neuropol.ttf
Run Code Online (Sandbox Code Playgroud) 只是一个简单的问题,我想知道是否有任何方法可以将鼠标监听器添加到绘画组件中?例如,假设您画了一个矩形,您可以做到当您单击该矩形时,它就会执行某些操作吗?
public void paintComponent(Graphics g) {
g.drawRect(50, 50, 20, 20);
//Do something when this rectangle is clicked on
}
Run Code Online (Sandbox Code Playgroud) 我是Python的新手,我现在才开始看到它的用途,self并想知道我是否正确使用它.我在下面有一些示例代码,并想知道是否有人可以浏览并查看它是否正确使用.我不确定它是否正确,因为我似乎需要使用self很多,但也许这只是语言的风格.谢谢
码
from tkinter import Canvas
class BouncyBall:
def __init__(self):
self.x = 0
self.y = 0
self.d = 15
self.color = 'blue'
self.speed = 2
self.move_left = False
self.move_right = False
def __init__(self, x, y, d, color):
self.x = x
self.y = y
self.d = d
self.color = color
self.speed = 2
self.move_left = False
self.move_right = False
#Accessor Methods
def get_x(self):
return self.x
def get_y(self):
return self.y
def get_diameter(self):
return self.d
def get_color(self):
return self.color …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用该Movie对象播放一个gif ,它需要我调用该invalidate()方法.但是每当我调用此方法时,我都会收到以下错误:
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题以及为什么会这样