问题描述
首先,我想让你知道,我在网上搜索过,但没有找到任何东西.我记得我曾经在上面看到一个线程,但再也找不到了;这是很久以前的事了.
First of all, I want you to know that I searched the web for that but couldn't find anything.I remember that I saw a thread on it once but couldn't find it again; it was a long time ago.
我想知道如何在没有 JFrame 或 AWT 的情况下制作我自己的窗口.我搜索的每个地方都只向我展示了库和预制代码,但我无法了解它在内部是如何工作的.我想知道如何在没有 Java 已经给我的情况下构建一个窗口.
I want to know how to make my own window, without JFrame or AWT.Everywhere I am searching just shows me library and pre-made code but I can't learn how it works inside.I want to know how to build a window, without what Java already gave me.
Java 的好处和坏处是 Java 使开发人员的工作变得容易,所以,这就是我尝试 C、搜索汇编代码并试图找到一种方法来做到这一点的原因,但所有方法都使用了库.
The good thing and the bad thing in Java is that Java makes things easy for the developers,so, that's why I tried C, searched for assembly code and tried to find a way to do this, but all of the approaches used libraries.
那为什么,我想知道,这甚至可能吗?不需要所有的窗口,只需要它的基础,甚至屏幕上的像素,但不包括使用更多的库或为此构建的类,每个人都使用只是因为这是他们唯一知道的东西.
That why, I want to know, it is even possible?Don't need all of the windows, just the base of it or even pixels on the screen, but something that will not include using more libraries or made classes that were built for that and everyone using just because this is the only thing they know.
感谢所有帮助我并回答我的问题的人:)
Thanks to everyone that will help me and will answer my question(s) :)
推荐答案
在 Java 中,我们依赖于与本机操作系统的绑定.我们有抽象框架的原因,比如 AWT、Swing、JavaFX、SWT 是因为完成这个过程的过程并不简单,特别是如果你真的想以某种有意义的方式在这些表面上绘画,并且当你考虑不同的可用操作系统的要求.
In Java, we are reliant on bindings into the native OS. The reason we have abstract frameworks, like AWT, Swing, JavaFX, SWT is because the process by which this is done is not trivial, especially if you actually want to paint to these surfaces in some meaningful way and is compounded when you consider the different requirements of the available operating systems.
取决于您实际想要实现的目标,将取决于您将要走的路,例如...
Depending on what you actually want to achieve, will depend on which way you will go, for example...
使用 JWindow
或未修饰的 JFrame
.这为您提供了一个可用的绘画表面和一个与现成的事件队列(消息循环)的连接.
Use a JWindow
or an undecorated JFrame
. This provides you with a available painting surface and a connection into a ready made event queue (message loop).
这两个窗口向您展示了一个空的"窗口.没有装饰的长方形.在处理这些类型的窗户时,您可以直接或通过自定义外观提供自己的装饰.
These two windows present you with an "empty" rectangle with no decorations. When dealing with these types of windows, you can provide your own decorations directly or via a custom look and feel.
直接在操作系统中使用 JNI(本机)绑定,这将允许您要求操作系统创建您自己的窗口.这意味着您需要负责确定如何绘制窗口、如何处理来自操作系统的针对您的窗口的消息(事件)以及所有其他注意事项.
Use a JNI (native) binding directly into the operating system which would allow you to ask the OS to create a window of your own. This means that you become responsible for determining how you are going to paint to the window, how you are going to process messages (events) from the OS that are targeted to your window and all other considerations.
看看JNA Win32WindowDemo.java
或者如果你真的想变得时髦,你也可以看看 ...
Take a look at JNA Win32WindowDemo.java
or if you really want to get funky, you could also have a look at ...
作为一些额外的绑定到原生图形库
as some additional bindings into native graphics library
这篇关于在没有 JFrame 或 AWT 的情况下制作 Java 窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!