| 1 | import java.awt.*;
|
|---|
| 2 | import java.awt.event.*;
|
|---|
| 3 | import javax.swing.*;
|
|---|
| 4 |
|
|---|
| 5 | public class GeometryUnity {
|
|---|
| 6 | public static void main(String[] args){
|
|---|
| 7 | JFrame frame = new JFrame("Geometry Test");
|
|---|
| 8 | frame.getContentPane().setLayout(new BorderLayout());
|
|---|
| 9 | JPanel p = new JPanel();
|
|---|
| 10 | JButton btn = new JButton(new AbstractAction("click") {
|
|---|
| 11 | @Override
|
|---|
| 12 | public void actionPerformed(ActionEvent e) {
|
|---|
| 13 | makeDlg();
|
|---|
| 14 | }
|
|---|
| 15 | });
|
|---|
| 16 | p.add(btn);
|
|---|
| 17 | frame.getContentPane().add(p, BorderLayout.CENTER);
|
|---|
| 18 |
|
|---|
| 19 | frame.setSize(400, 300);
|
|---|
| 20 | frame.setLocation(100,100);
|
|---|
| 21 | frame.show();
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | public static void makeDlg() {
|
|---|
| 25 | final JDialog dlg = new JDialog();
|
|---|
| 26 | dlg.setLayout(new BorderLayout());
|
|---|
| 27 | dlg.setSize(200, 200);
|
|---|
| 28 | dlg.setLocation(300,400);
|
|---|
| 29 | JButton btn2 = new JButton(new AbstractAction("click2") {
|
|---|
| 30 | @Override
|
|---|
| 31 | public void actionPerformed(ActionEvent e) {
|
|---|
| 32 | System.out.println("dlg.getLocationOnScreen()="+dlg.getLocationOnScreen());
|
|---|
| 33 | }
|
|---|
| 34 | });
|
|---|
| 35 | dlg.add(btn2, BorderLayout.CENTER);
|
|---|
| 36 | dlg.setVisible(true);
|
|---|
| 37 | System.out.println("dlg.getLocationOnScreen()="+dlg.getLocationOnScreen());
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|