JButton ButtonClickTest
package com.example.test; import java.awt.EventQueue; import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.FlowLayout;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyBoundsAdapter;
import java.awt.event.InputMethodListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.beans.VetoableChangeListener; public class ButtonClickTest extends JFrame { /**
*
*/
private static final long serialVersionUID = 2643641337669537093L;
private JPanel contentPane; /**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ButtonClickTest frame = new ButtonClickTest();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the frame.
*/
public ButtonClickTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); JButton btnNewButton = new JButton("New button");
btnNewButton.addVetoableChangeListener(new VetoableChangeListener() {
public void vetoableChange(PropertyChangeEvent evt) {
System.out.println("vetoableChange");
}
});
btnNewButton.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("propertyChange");
}
});
btnNewButton.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
System.out.println("mouseWheelMoved");
}
});
btnNewButton.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("mouseDragged");
}
@Override
public void mouseMoved(MouseEvent e) {
System.out.println("mouseMoved");
}
});
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("mouseClicked");
}
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("mouseEntered");
}
@Override
public void mouseExited(MouseEvent e) {
System.out.println("mouseExited");
}
@Override
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
}
@Override
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
}
});
btnNewButton.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed");
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased");
}
@Override
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped");
}
});
btnNewButton.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.out.println("itemStateChanged");
}
});
btnNewButton.addInputMethodListener(new InputMethodListener() {
public void caretPositionChanged(InputMethodEvent event) {
System.out.println("caretPositionChanged");
}
public void inputMethodTextChanged(InputMethodEvent event) {
System.out.println("inputMethodTextChanged");
}
});
btnNewButton.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
@Override
public void ancestorMoved(HierarchyEvent e) {
System.out.println("ancestorMoved");
}
@Override
public void ancestorResized(HierarchyEvent e) {
System.out.println("ancestorResized");
}
});
btnNewButton.addHierarchyListener(new HierarchyListener() {
public void hierarchyChanged(HierarchyEvent e) {
System.out.println("hierarchyChanged");
}
});
btnNewButton.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
System.out.println("focusGained");
}
@Override
public void focusLost(FocusEvent e) {
System.out.println("focusLost");
}
});
btnNewButton.addContainerListener(new ContainerAdapter() {
@Override
public void componentAdded(ContainerEvent e) {
System.out.println("componentAdded");
}
@Override
public void componentRemoved(ContainerEvent e) {
System.out.println("componentRemoved");
}
});
btnNewButton.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
System.out.println("componentHidden");
}
@Override
public void componentMoved(ComponentEvent e) {
System.out.println("componentMoved");
}
@Override
public void componentResized(ComponentEvent e) {
System.out.println("componentResized");
}
@Override
public void componentShown(ComponentEvent e) {
System.out.println("componentShown");
}
});
btnNewButton.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
System.out.println("stateChanged");
}
});
btnNewButton.addAncestorListener(new AncestorListener() {
public void ancestorAdded(AncestorEvent event) {
System.out.println("ancestorAdded");
}
public void ancestorMoved(AncestorEvent event) {
System.out.println("ancestorMoved");
}
public void ancestorRemoved(AncestorEvent event) {
System.out.println("ancestorRemoved");
}
});
contentPane.add(btnNewButton);
} }
JButton ButtonClickTest的更多相关文章
- java中Jbutton常用设置
. 对JButton大小的设置 ——因为JButen是属于小器件类型的,所以一般的setSize不能对其惊醒大小的设置,所以一般我们用 button.setPreferredSize( ...
- Java——按钮组件:JButton
import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; impor ...
- JAVA学习Swing章节按钮组件JButton的简单学习
package com.swing; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; ...
- 关于java中JButton的样式设置(的一些我们应该知道的函数)(转)
1. 对JButton大小的设置 ——因为JButen是属于小器件类型的,所以一般的setSize不能对其惊醒大小的设置,所以一般我们用 button.setPreferredSize(new Dim ...
- JButton计数
1.引言 在Swing窗口中,我们时常会点击按钮进行计数,例如点击按钮A,第一次弹出窗口1,第二次弹出窗口2....以及按钮的快捷键设置. import java.awt.event.ActionEv ...
- JButton按钮
1.方法 void setSize(width,height):设置按钮大小 void setBounds(x,y,width,heigth):设置按钮的左上角顶点位置和大小 void setC ...
- Java 内部类和匿名类 实现JButton动作 ActionListener类
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ControlCircle2 extend ...
- JButton 做图片框
JButton setHorizontalTextPosition(SwingConstants.CENTER);// 在水平方向文字位于图片中央 setVerticalTextPosition(Sw ...
- Swing学习篇 API之JButton组件
按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且还可 ...
随机推荐
- 2018.8.10 programming bat based on python
@echo off REM Current DevProg Version. Match the pip package version (x.y.z)SET currentversion=0.4.0 ...
- php是如何工作的
a:前提条件: apache服务器启动正常工作 b:客户端浏览器在地址栏输入一个程序地栏 按回车发送请求 {请求}http://127.0.0.1/day03/1.php c:apache接收请求,并 ...
- [Unity3D]EZGUI 操作简单介绍
官方的GUI根本无法跟EZGUI比,无论是资源还是易用性还是速度.EZGUI基于Mesh不占DrawCall.EZGUI是自动合并Mesh成为一个物体,并且贴图自动制作Atlas.所以效率高,CPU消 ...
- scrapy入门实践1
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 这就是整个Scrapy的架构图了: 各部件职能: Scrapy ...
- hadoop-pig学习笔记
A1 = LOAD '/luo/lzttxt01.txt' AS (col1:chararray,col2:int,col3:int,col4:int,col5:double,col6:double) ...
- Directx 9 VS2015环境搭建
安装好Directx9 sdk和vs2015后 打开vs,新建项目 --> c++项目 -->win32控制台应用程序-->空项目 创建项目后,右键项目属性, 包含目录 D:\Pr ...
- 神秘常量!用0x077CB531计算末尾0的个数,32位数首位相连
大家或许还记得 Quake III 里面的一段有如天书般的代码,其中用到的神秘常量 0x5F3759DF 究竟是怎么一回事,着实让不少人伤透了脑筋.今天,我见到了一段同样诡异的代码. 下面这个 ...
- [转] AS3地图拼接与战争迷雾的实现
在开发游戏的过程中,特别是地图编辑器中,需要利用最少的资源,实现最丰富的地形地貌.虽然现在众多的RPG开始使用整图,但是我们偶尔还是需要能够让玩家自己编辑地图,或者其他需要自动进行地图构建的功能.另外 ...
- 关于打包后提示无法连接到mongodb的情况
昨天晚上要和前端联调. 打完jar包后发现无法连接到测试环境的数据库. 就很尴尬,最后发现问题在于mongodb的URI写错了: 正确的URI格式:mongodb://url:port/dbName ...
- dwd面试记录与最近面试的一些感想。
因为自己简历有些问题,额,面试官以为我有三年的工作经验. (吐槽一些智联的简历系统,)16年工作,一到18年自动变三年.这也忒坑人了. 工作年限一定要真实,避免出现问题,这会让面试官觉得你很不真诚. ...