package com.xyzx.swing;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
* @description 我的记事本主程序
*/
public class NotePad {
/**
* 构造函数
*/
public NotePad(){
// 1、 初始化窗体
JFrame notePadFrame = new JFrame("我的记事本");
// 设置边框
notePadFrame.setBounds(200, 200, 300, 500);
notePadFrame.setVisible(true);
// 2、获得窗体容器,添加按钮
JButton btnConfig = new JButton("配置信息");//按钮控件
Container container = notePadFrame.getContentPane();//获得窗体的容器
container.add(btnConfig);// 窗体容器中添加按钮对象
// 3、给按钮增加事件监听器(ActionListener:单击事件)
btnConfig.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 按钮的单击事件
DialogDemo dialogDemo = new DialogDemo(notePadFrame);
dialogDemo.setVisible(true);
}
});
}
public static void main(String[] args) {
new NotePad();
}
}
结果:

单击我的记事本中的内容,显示:

1298

被折叠的 条评论
为什么被折叠?



