zoukankan      html  css  js  c++  java
  • 对话框

    package com.company;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class Main extends JDialog {
             public Main(JFrame frame){
                 /*
                 *第一个参数:父窗体对象
                 * 第二个参数:对话框标题
                 * 第三个参数:是否阻塞父窗体
                  */
                 super(frame,"对话框标题",true);
                 Container c=getContentPane();//获取窗体容器
                 c.add(new JLabel("这是一个对话框"));
                 setBounds(100,100,100,100);//设置窗体坐标和大小
             }
        public static void main(String[] args) {
    	// write your code here
          JFrame f=new JFrame("父窗体");
          f.setBounds(50,50,300,300);
          Container c=f.getContentPane();
          JButton btn=new JButton("弹出对话框");
          c.setLayout(new FlowLayout());//设置布局,使用流布局
          c.add(btn);
          f.setVisible(true);
          f.setDefaultCloseOperation(EXIT_ON_CLOSE);
    
          btn.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                     new Main(f);
                     Main d=new Main(f);
                     d.setVisible(true);
              }
          });//添加动作监听
        }
    }
    

     

  • 相关阅读:
    python 解释器交互模块 -- sys
    python 操作系统模块 -- OS
    python 随机数模块 -- random
    python 时间模块 -- time
    Python 面向对象
    python 模块
    python -- 面向对象进阶
    github连接提示
    linux day4
    git基本使用
  • 原文地址:https://www.cnblogs.com/llhhcc/p/10073330.html
Copyright © 2011-2022 走看看