Swing和AWT混合不好,但还是做了,为什么呢? [英] Swing and AWT Mixing is bad, but still done, why?

查看:251
本文介绍了Swing和AWT混合不好,但还是做了,为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,人们建议不要混用Swing和AWT 组件,但是我们看到这个很多:

I have noticed that people recommend not intermixing Swing and AWT Components, however we see this alot:

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
 //AWT imports though only for listeners
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

那么,为什么许多包括Java(因为我得到了了他们的教程<一个href=\"http://docs.oracle.com/javase/tutorial/display$c$c.html?$c$c=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ButtonDemoProject/src/components/ButtonDemo.java\">here)仍然使用AWT进口,虽然我看到它的主要表现为监听器秒。

So why do many including Java (because I got that off their tutorial here) still use AWT imports, though I see its mainly for Listeners.

你如何添加的原始的摆动监听器 S /库的东西,如按钮的JComboBox presses / slections等?

How do you add native Swing Listeners/Libraries for stuff like Key, Button, JComboBox presses/slections etc?

或者,我会使用 firePropertyChangeListeners()? (尽管这涉及到Java Bean)的

Or would I use firePropertyChangeListeners()? (though that relates to Java Beans)

据困惑我现在有一段时间,我的大多数应用程序都Swing和AWT这被认为是坏?

It has been confusing me now for some time, most of my app have Swing and AWT which is said to be bad?

推荐答案

摇摆股相当多的班,AWT,并使用一些相同的执行 - 注意,javax.swing.JComponent中(基Swing组件类)实际上继承从java.awt.Component中(基AWT容器类)

Swing shares quite a few classes with AWT, and uses some of the same implementation - note that javax.swing.JComponent (the base Swing component class) actually inherits from java.awt.Component (the base AWT container class)

这其实不是太大的问题,如果你细心混合Swing和AWT。其主要缺陷是:

It's actually not that much of a problem to mix Swing and AWT if you are careful. The main pitfalls are:


  • 您就有可能得到一个非常不同的外观,如果你混合AWT和Swing感觉UI组件

  • Swing组件是轻量级(被Java渲染),而AWT组件都是重量级(如主机平台组件实现) - 这意味着,如果你把AWT组件Swing组件内(倒过来,你都会有问题是罚款)

这篇关于Swing和AWT混合不好,但还是做了,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆