You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.2 KiB
95 lines
3.2 KiB
package com.langtech.plm.mpart;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.ArrayList;
|
|
|
|
public class MainFrame extends JFrame {
|
|
|
|
private JTextField textField;
|
|
private Object syncObject = new Object();
|
|
public MainFrame() {
|
|
super("Main Window");
|
|
|
|
textField = new JTextField(20);
|
|
JButton button = new JButton("Open Dialog");
|
|
ArrayList<String> childrenList = new ArrayList<String>();
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
// 创建并显示模态对话框
|
|
JComboBox<String> a = new JComboBox<String>();
|
|
a.addItem("1");
|
|
System.out.println("0");
|
|
System.out.println(syncObject);
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
DialogFrame dialog = new DialogFrame(MainFrame.this,a,childrenList);
|
|
dialog.setVisible(true);
|
|
// 等待对话框关闭后执行的操作
|
|
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
@Override
|
|
public void windowClosed(java.awt.event.WindowEvent e) {
|
|
|
|
System.out.println("21121212");
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
System.out.println("2");
|
|
|
|
System.out.println(childrenList.size());
|
|
|
|
|
|
|
|
// DialogFrame dialog = new DialogFrame(MainFrame.this,a,syncObject);
|
|
// dialog.setVisible(true);
|
|
// // 等待对话框关闭后执行的操作
|
|
// dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
// @Override
|
|
// public void windowClosed(java.awt.event.WindowEvent e) {
|
|
//
|
|
// System.out.println("1");
|
|
// }
|
|
// });
|
|
// System.out.println("2");
|
|
// synchronized (syncObject) {
|
|
//
|
|
// try {
|
|
// // Wait until notified
|
|
// System.out.println("4");
|
|
// syncObject.wait();
|
|
//
|
|
// } catch (InterruptedException ex) {
|
|
// Thread.currentThread().interrupt(); // Restore interrupted status
|
|
// System.err.println("Thread was interrupted.");
|
|
// }
|
|
// System.out.println("2");
|
|
//
|
|
// }
|
|
System.out.println("3");
|
|
}
|
|
});
|
|
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new FlowLayout());
|
|
panel.add(textField);
|
|
panel.add(button);
|
|
|
|
this.add(panel);
|
|
this.pack();
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
this.setLocationRelativeTo(null); // 居中显示
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
EventQueue.invokeLater(() -> {
|
|
MainFrame frame = new MainFrame();
|
|
frame.setVisible(true);
|
|
});
|
|
}
|
|
} |