将 AWT 图形代码移植到 Android

发布于 2024-11-03 10:28:38 字数 222 浏览 3 评论 0原文

我们希望在 Android 平台上使用一些现有的 Java AWT 图形代码。据我所知,Android 不包含任何 AWT 类——没有 Graphics2DPath2DFontMetrics

。将绘图代码移植到 Android 的最佳方法是什么?理想情况下,我们希望修改我们的代码库以同时针对 Android 和通用 Java。

We would like to use some of our existing Java AWT graphics code on the Android platform. As far as I can tell, Android does not include any of the AWT classes -- no Graphics2D, Path2D, FontMetrics, etc.

What is the best approach to port our drawing code to Android? Ideally, we would like to modify our code base to target both Android and generic Java.

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

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

发布评论

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

评论(3

茶底世界 2024-11-10 10:28:38

android 平台支持 awt 的一小部分。我的意思是它支持 awt 字体。从 java swing(您真的只是使用 awt 作为独立 UI 吗?)到 Android 将会对系统造成冲击。在 XML 资源文件中定义 Android 的 UI,这些资源被加载到代表应用程序逻辑单元的 Activity 类中。 Canvas 取代了 Graphics2D 对象,并且它们具有一些不同的功能。Android UI 系统力求避免绝对定位,这在 java UI 中很常见。 Android 还有很多需要考虑的因素,比如不同的屏幕尺寸和分辨率差异。对于 Java SE 来说,这两者都不是什么大问题。回答你的问题:你的工作已经完成,你必须从头开始大部分编码。

我不确定“绘图代码”是什么意思,但就我而言,我有大量通过 awt 形状显示的动画代码。这在 Android 上是可以重现的,因为有 Graphics.drawable.shapes 对象,并且可以通过执行诸如 canvas.drawCircle(x,y,z,h) 之类的操作来显示原始形状(提醒您一件事?)。但当我移植它时,它很困难,感觉就像我在欺骗 Android 去做一些它真正不想做的事情,并且无意做的事情。鉴于你的问题含糊不清,很难准确回答。

The android platform supports a small subset of awt. By small, I mean it supports awt fonts. Going from java swing (are you really just using awt as a standalone UI?) to Android is going to be a shock to the system. One defines Android's UI in XML resource files, and those resources are loaded into Activity classes which represents a logical unit of the application. Canvas' replace Graphics2D objects, and they have somewhat different functionality.The Android UI system seeks to avoid absolute positioning, which is common in java UI's. And there is so much more to consider for Android, like varying screen sizes and differences in resolution. Neither of which were much of a issue for Java SE. To answer your question: you have your work cut out for you and you will have to start much of your coding from scratch.

I'm not sure what 'drawing code' means, but in my case, I have a large amount of animation code that is displayed via awt shapes. This is reproducable on android as there are graphics.drawable.shapes objects, and one can display primitive shapes by doing something like canvas.drawCircle(x,y,z,h) (remind you of something?). But when I ported it, it was difficulty and felt like I was cortorting the android to do something it really didn't want to, and wasn't intended to do. It's hard to answer your question exactly given the vagueness of it.

南城追梦 2024-11-10 10:28:38

我不认为你可以将 AWT 移植到 Android。我的意思是,它是 Java SE 与它的一个子集(或者是带有类固醇的更新版 Java ME,如您所愿)。

不过,有些 Java ME 的 UI 类可以在 Android 上完美运行。我个人喜欢 LWUIT,但它不是唯一的。

I don't think you can port AWT to Android. I mean, it's Java SE vs a subset of it (or an updated Java ME with steroids, as you prefer).

There are though, some UI classes for Java ME that work perfectly on Android. Personally I like LWUIT but it's not the only one.

神妖 2024-11-10 10:28:38

appengine-awt 是 java.awt 和 javax.imageio 包的纯 java 实现,用于 Google AppEngine 环境。

https://github.com/witwall/appengine-awt

SwingWT 是 100% 纯 Java该库旨在成为 Swing 和 AWT 的免费实现。与 Swing 不同,它从 SWT 为您的平台驱动本机对等小部件。

https://github.com/witwall/SwingWT

appengine-awt is a pure java implementation of the java.awt and javax.imageio packages for use in the Google AppEngine environment.

https://github.com/witwall/appengine-awt

SwingWT is a 100% pure Java library which aims to be a free implementation of Swing and AWT. Unlike Swing, it drives native peer widgets for your platform from SWT.

https://github.com/witwall/SwingWT

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