解决java菜单界面 中文 乱码问题

在用Java做数据库实验时遇到了这个问题,查找csdn后获得了这类解答:https://blog.csdn.net/SICAUliuy/article/details/82559459?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164130440216780269866045%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164130440216780269866045&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-82559459.pc_search_result_cache&utm_term=Java+%E8%8F%9C%E5%8D%95%E4%B9%B1%E7%A0%81&spm=1018.2226.3001.4187https://blog.csdn.net/SICAUliuy/article/details/82559459?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164130440216780269866045%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164130440216780269866045&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-82559459.pc_search_result_cache&utm_term=Java+%E8%8F%9C%E5%8D%95%E4%B9%B1%E7%A0%81&spm=1018.2226.3001.4187

不知道大家好不好用,但是对我来说不太好用,因为这是java.awt.Frame自身的问题,修改编译器的话反而会让其他的没有问题的类出现问题。

最终查找源码可以发现,现在,awt下面有了一个扩展版本java.awt.JFrame,他已经解决了中文乱码问题。只要将原来Frame里所有的变量名(如Panel,MenuBar,Menu等)前面加 ‘J’ 就能在大部分情况下完美适配。注意:相关函数中间若含变量名也同理(如setMenuBar 应该改为 setJMenuBar)。

以下是JFrame 源码前的解释:

 An extended version of java.awt.Frame that adds support for the JFC/Swing component architecture. You can find task-oriented documentation about using JFrame in The Java Tutorial, in the section How to Make Frames .
The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case. As a convenience, the add, remove, and setLayout methods of this class are overridden, so that they delegate calls to the corresponding methods of the ContentPane. For example, you can add a child component to a frame as follows:
         frame.add(child);
   
And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a JFrame.
Unlike a Frame, a JFrame has some notion of how to respond when the user attempts to close the window. The default behavior is to simply hide the JFrame when the user closes the window. To change the default behavior, you invoke the method setDefaultCloseOperation. To make the JFrame behave the same as a Frame instance, use setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE).
For more information on content panes and other features that root panes provide, see Using Top-Level Containers  in The Java Tutorial.
In a multi-screen environment, you can create a JFrame on a different screen device. See Frame for more information.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值