2013/05/08 学习笔记
来源:互联网 发布:php后台密码破解工具 编辑:程序博客网 时间:2024/04/29 20:56
1.Cannot refer to a non-final variable inside an innerclass defined in a different method.
2.Inside the inner class, "this" refers to the inner class.To refer to the "this" of the outer class, use"OuterClassName.this". But you can reference outer class's membersdirectly without this clumpysyntax.
3.Anadapter class called WindowAdapter implements the WindowListenerinterface and provides default implementations to all the 7abstract methods. You can then derive a subclass from WindowAdapterand override only methods of interest and leave the rest to theirdefault implementation.
4.the JComponents shall not be added onto the top-levelcontainer (e.g., JFrame, JApplet) directly because they arelightweight components. The JComponents must be added onto theso-called content-pane of the top-level container. Content-pane isin fact a java.awt.Container that can be used to group and layoutcomponents.
Notes: If a component is added directly into a JFrame, itis added into the content-pane of JFrame instead
5.
Running the GUIConstruction Codes on the Event-Dispatching Thread
Inthe previous examples, we invoke the constructor directly in theentry main() method to setup the GUI components. Forexample,
// The entry main method
public static void main(String[] args) {
}
Theconstructor will be executed in the so-called "Main-Program"thread. This may cause multi-threading issues (such as unresponsiveuser-interface and deadlock).
Itis recommended to execute the GUI setup codes in the so-called"Event-Dispatching" thread, instead of "Main-Program" thread, forthread-safe opearations. Event-dispatching thread, which processesevents, should be used when the codes updates the GUI.
Torun the construstor on the event-dispatching thread,invoke
public static void main(String[] args) {
}
Note: javax.swing.SwingUtilities.invokeLater() is a coverfor
Attimes, for example in game programming, the constructor or themain() may contains non-GUI codes. Hence, it is a common practiceto create a dedicated method called initComponents() (used inNetBeans visual GUI builder) or createAndShowGUI() (used in Swingtutorial) to handle all the GUI codes (and another method calldinitGame() to handle initialization of the game's objects). ThisGUI init method shall be run in the event-dispatchingthread.
6.Warning Message "Theserialization class does not declare a static finalserialVersionUID field of type long" (Advanced)
Thiswarning message is triggered because java.awt.Frame (via itssuperclass java.awt.Component) implements the java.io.Serializableinterface. This interface enables the object to be written out toan output stream serially (via method writeObject()); and read backinto the program (via method readObject()). The serializationruntime uses a number (called serialVersionUID) to ensure that theobject read into the program is compatible with the classdefinition, and not belonging to another version.
Youhave these options:
1)
2)
private static final long serialVersionUID =1L;
3)
@SuppressWarnings("serial")
public class MyFrame extends JFrame { ...... }
以上学习笔记摘自:http://www.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html
这里顺便介绍个很好的java学习网站:
http://docs.oracle.com/javase/tutorial/uiswing/index.html
- 2013/05/08 学习笔记
- 学习笔记:Shell脚本-2015-08-05
- 2013/08/15 C# WPF 学习笔记
- 2013/08/16 C# WPF 学习笔记
- 2013/08/17 C# WPF 学习笔记
- 2013/08/18 C# WPF 学习笔记
- 2013/08/19 C# WPF 学习笔记
- 2013/08/20 C# WPF 学习笔记
- 2013/08/21 C# WPF 学习笔记
- 2013/08/22 C# WPF 学习笔记
- 2013/08/23 C# WPF 学习笔记
- 2013/08/24 C# WPF 学习笔记
- C++ 学习笔记 2013-08-25
- 2013/08/25 C# WPF 学习笔记
- 2013/08/26 C# WPF 学习笔记
- 2013/08/27 C# WPF 学习笔记
- 2013/08/28 C# WPF 学习笔记
- 2013/08/29 C# WPF 学习笔记
- java set的使用
- JOGL——java eclipse中opengl的配置
- java中map list set 用法以及区别
- 如何让eclipse 32位和64位同时运行
- java类的一些特殊效果
- 2013/05/08 学习笔记
- java for语句的一个用法
- 利用二级指针删除单向链表
- 单例模式 Singleton
- 适配器模式1
- jcl错误集锦
- 组合模式 Composite
- js控制div弹出层
- JCL实用程序