Dialog自定义内容

阅读 96

2022-04-22

package kl;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DialogDemo {
    public static void main(String[] args) {
        Frame frame = new Frame("这里测试Dialog");

        Dialog d1 = new Dialog(frame, "模式对话框", true);

        Box vBox=Box.createVerticalBox();
        vBox.add(new TextField(20));
        vBox.add(new Button("确认"));

        d1.add(vBox);

        d1.setBounds(20, 30, 500, 200);


        Button b1=new Button("打开模式对话框");


        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d1.setVisible(true);
            }
        });

        frame.add(b1,BorderLayout.NORTH);


        frame.pack();
        frame.setVisible(true);
    }
}

 

精彩评论(0)

0 0 举报