简体   繁体   English

在AWT / Swing中用于处理事件的设计模式的名称是什么?

[英]What is the name of the design pattern used in AWT/Swing that handles events?

I have heard that there are 2 ways that we can set the PLAF in Swing. 我听说有两种方法可以在Swing中设置PLAF。 What is the real meaning of PLAF, and what are those 2 ways? PLAF的真正含义是什么,这两种方式是什么?

Observer Pattern . 观察者模式

Some of the most notable implementations of this pattern: 此模式的一些最著名的实现:

  • The Java Swing library makes extensive use of the observer pattern for event management. 在Java Swing库中大量使用了事件管理的观察者模式。

To answer the question in your title: Observer is the design pattern that Swing employs. 回答标题中的问题: 观察者是Swing所采用的设计模式。

PLAF is a ' P luggable L ook A nd F eel'. PLAF是一个“P luggable 大号 OOK ND˚F鳗鱼”。 Here is a reference for PLAF in Java. 这是 Java中PLAF 的参考

The title, regarding the Event Listeners, and the PLAF are not related. 与事件侦听器有关的标题与PLAF无关。 The former has to do with the processing of events - more closely associated with the C in MVC, while the latter is generally associated with the V iew aspect of MVC. 前者与事件的处理做的事情-在MVC中的C.更密切相关,而后者通常与MVC中的V IEW方面相关。

PLAF = Pluggable Look and Feel. PLAF =可插拔外观。 Basically, the same UI can have different skins with very little work. 基本上,同一UI只需很少的工作就可以具有不同的外观。

Check out this site for a detailed description of L&F. 请访问此站点以获取L&F的详细说明。 In short, there are actually 3 ways to set up your PLAF. 简而言之,实际上有3种方法来设置您的PLAF。

1) Via command line: java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp or java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel MyApp 1)通过命令行:java -Dswing.defaultlaf = com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp或java -Dswing.defaultlaf = com.sun.java.swing.plaf.windows.WindowsLookAndFeel MyApp

2) Via swing.properties file in your java lib. 2)通过Java库中的swing.properties文件。 swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel swing.defaultlaf = com.sun.java.swing.plaf.windows.WindowsLookAndFeel

3) Programatically with either: 3)以下列方式编程:

//At the beginning of your program
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//Another option
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//And another
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

//Or during your program - 
UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(frame);
frame.pack();

The above link also has code examples to demonstrate how to change your look and feel. 上面的链接还提供了代码示例,以演示如何更改外观。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM