我可以在Java图形中使用拉链

发布于 2025-02-01 11:34:47 字数 736 浏览 0 评论 0原文

我正在制作爪哇游戏。我可以绘制图像和其他内容,但是拉链给了我一个错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sun.font.SunFontManager
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
its longer...

这是代码:

Font font = new Font("Arial",50,Font.PLAIN);
g2.setFont(font);
g2.drawString("Hello World!", 100, 100);
g2.dispose();

I am making a Java game. I can draw images and other things, but drawString gives me an error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sun.font.SunFontManager
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
its longer...

This is the code:

Font font = new Font("Arial",50,Font.PLAIN);
g2.setFont(font);
g2.drawString("Hello World!", 100, 100);
g2.dispose();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

俏︾媚 2025-02-08 11:34:47

Oracle有一个有用的教程,创建带有swing 的GUI。使用Netbeans IDE部分跳过学习秋千。

您的一小部分代码在两个地方是错误的。

Font font = new Font("Arial", Font.PLAIN, 50);
g2.setFont(font);
g2.drawString("Hello World!", 100, 100);
// g2.dispose();

您的字体构造函数采用字符串,font类型和int点大小。

您不处理PaintComponent 图形对象。

我可以想象您的代码其余部分中还有多少其他错误和误解。

Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section.

Your tiny bit of code is wrong in two places.

Font font = new Font("Arial", Font.PLAIN, 50);
g2.setFont(font);
g2.drawString("Hello World!", 100, 100);
// g2.dispose();

Your Font constructor takes a String, Font type, and int point size.

You don't dispose of a paintComponent Graphics object.

I can just imagine how many other errors and misconceptions there are in the rest of your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文