JAVA 私塾第十、十一章笔记整理
JAVA 私塾第十、十一章笔记整理第十章 AWT
AWT(Abstract Window Toolkit)用于Java Application 的GUI(Graphical User Interface图形用户界面)编程。
AWT所涉及的类一般在java.awt包及其子包中。
【此处有图片,可以到JAVA 私塾官网下载完整笔记:w ww.javass.cn】
布局管理器
FlowLayout(Panel和Applets的缺省布局管理器)
对组件逐行定位,行内从左到右,一行排满后换行。默认的对齐方式是居中。
BorderLayout (Window, Dialog和Frame的缺省布局管理器)
将整个容器的布局划分成东西南北中五部分,组件只能被添加到指定区域。每个区域只能加入一个组件,如加入多个,则先前的会被覆盖。
GridLayout
将空间划分成规则的矩形网格,每个单元区域大小相等,组件被添加到每个单元各种,先从左到右满一行后换行,再从上到下。
CardLayout
GridBagLayout
第十一章Swing和GUI事件处理
GUI事件∵接口:
事件类型 相应∵接口∵接口中的方法
ActionActionListeneractionPerformed(ActionEvent)
ItemItemListeneritemStateChanged(ItemEvent)
MouseMouseListenermousePressed(MouseEvent)
mouseReleased(MouseEvent)
mouseEntered(MouseEvent)
mouseExited(MouseEvent)
mouseClicked(MouseEvent)
Mouse MotionMouseMotionListenermouseDragged(MouseEvent)
mouseMoved(MouseEvent)
KeyKeyListenerkeyPressed(KeyEvent)
keyReleased(KeyEvent)
keyTyped(KeyEvent)
FocusFocusListenerfocusGained(FocusEvent)
focusLost(FocusEvent)
AdjustmentAdjustmentListeneradjustmentValueChanged(AdjustmentEvent)
ComponentComponentListenercomponentMoved(ComponentEvent)
componentHidden (ComponentEvent)
componentResized(ComponentEvent)
componentShown(ComponentEvent)
WindowWindowListenerwindowClosing(WindowEvent)
windowOpened(WindowEvent)
windowIconified(WindowEvent)
windowDeiconified(WindowEvent)
windowClosed(WindowEvent)
windowActivated(WindowEvent)
windowDeactivated(WindowEvent)
ContainerContainerListenercomponentAdded(ContainerEvent)
componentRemoved(ContainerEvent)
TextTextListenertextValueChanged(TextEvent)
事件适配器:
public abstract class WindowAdapter implements WindowListener {
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}内部类
import java.awt.*;
import java.awt.event.*;
public class Test1{
Frame f = new Frame("Java Gui");
public Test1(){
MyInner m = new MyInner();
f.addWindowListener(m);
f.setSize(150,150);
f.setVisible(true);
}
public static void main(String args[]){
new Test1();
}
class MyInner extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(1);
}
}
}匿名内部类
import java.awt.*;
import java.awt.event.*;
public class Test2{
Frame f = new Frame("Java Gui");
public Test2(){
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(1);
}
});
f.setSize(150,150);
f.setVisible(true);
}
public static void main(String args[]){
new Test2();
}
}什么是双缓冲?
在后台进行界面的更新,然后在前台进行界面交换
功能:双缓冲可以改善一个被频繁改变的组件的外观
*Swing和AWT的区别?
Swing提供了更完整的组件,引入了许多新的特性和能力。Swing API是围绕着实现
AWT 各个部分的API 构筑的。
AWT 采用了与特定平台相关的实现,而绝大多数Swing 组件却不是这样做的,因此Swing 的外观和感觉是可客户化和可插的。
页:
[1]