如题,请高手帮帮忙!!!!!!!!!!!

解决方案 »

  1.   

    Frame2.javapackage test;import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JDesktopPane;public class Frame2 extends JFrame {
        BorderLayout borderLayout1 = new BorderLayout();
        JDesktopPane desktop=new JDesktopPane();
        JButton btn=new JButton("点");
        public Frame2() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    /**
         * Component initialization.
         *
         * @throws java.lang.Exception
         */
        private void jbInit() throws Exception {
            this.setContentPane(desktop);
            setSize(new Dimension(400, 300));
            setTitle("Frame Title");
            desktop.setLayout(borderLayout1);
            this.add(btn,borderLayout1.NORTH);
            
            btn.addActionListener(new ActionListener()
                    {
                        public void actionPerformed(ActionEvent e)
                        {
                            method();
                        }
                    });
            
          
        }
        
        public  void method()
        {
            inner inner=new inner();
            this.add(inner);
        }
        
        public static void main(String[] args)
        {
            new Frame2().setVisible(true);
        }
    }
    ===========================================================inner.javapackage test;import java.awt.BorderLayout;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JInternalFrame;public class inner extends JInternalFrame {
        BorderLayout borderLayout1 = new BorderLayout();
        JButton btn=new JButton("dialog");
        public inner() {
            try {
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    private void jbInit() throws Exception {
            getContentPane().setLayout(borderLayout1);
            this.setSize(100,100);
            btn.addActionListener(new ActionListener()
                    {
                        public void actionPerformed(ActionEvent e)
                        {
                            new Dialog1();
                        }
                    });
            this.add(btn,borderLayout1.CENTER);
            this.setClosable(true);
            this.setResizable(true);
            this.setVisible(true);
        }    public static void main(String[] args) {
            inner inner = new inner();
        }
    }========================================================
    Dialog1.javapackage test;import java.awt.BorderLayout;
    import java.awt.Frame;import javax.swing.JDialog;
    import javax.swing.JPanel;public class Dialog1 extends JDialog {
        JPanel panel1 = new JPanel();
        BorderLayout borderLayout1 = new BorderLayout();    public Dialog1(Frame owner, String title, boolean modal) {
            super(owner, title, modal);
            try {
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    public Dialog1() {
            this(new Frame(), "Dialog1", true);
        }    private void jbInit() throws Exception {
            panel1.setLayout(borderLayout1);
            getContentPane().add(panel1);
            this.setSize(100,100);
            this.setVisible(true);
        }
    }
      

  2.   

    你用JBuilder做的吧!呵呵
    this(new Frame(), "Dialog1", true);上面这句才是我要的啊!不过,我怎么理解,为什么 new Frame() 一下,dialog 就显示在原来的Frame上面????这个 dialog 不是应该在在刚刚 建立的 new Frame() 上面的吗?
      

  3.   

    哦,我知道为什么了啊!主要是模态的关系但是,dialog 用模态,还达不到我要做的东西的要求啊!
      

  4.   

    我这个主要是用在JInternalFrame里的JTable里,我想要做的是,当鼠标双击,JTable的某行,系统就会跟该行相关的信息对话框dialog如果,用以上方法“this(new Frame(), "Dialog1", true);”那么我的双击事件就变成了单击事件了啊我把我的代码粘出来,希望高手再来!!!!!!//这是我做双击事件专门写了的一个内类
    class doubleClick extends MouseAdapter{

    private boolean click=false;
         private  long firstClick=0;
       private long secondClick=0;
       private int rowI=-1;
        private JInternalFrame inframe;
        
        public doubleClick(JInternalFrame inframe){
         this.inframe=inframe;
        }
        
    public void mouseClicked(MouseEvent e){
    if(click==false){
    firstClick=new Date().getTime();
                   click=true;
                }else if(click==true){
             secondClick=new Date().getTime();
             click=false;
                }
                if (Math.abs((secondClick-firstClick)) < 300 && (secondClick-firstClick) > 30){ 
                   exe(e);
                }
            }
            public void mousePressed(MouseEvent e) { 
    if(click==false){
                   firstClick=new Date().getTime();
                   click=true;
                }else if(click==true){
                   secondClick=new Date().getTime();
                   click=false;
                }
                if (Math.abs((secondClick-firstClick)) < 300 && (secondClick-firstClick) > 30){ 
                   exe(e);
                }
            }

    private void exe(MouseEvent e){
    rowI  = table.rowAtPoint(e.getPoint());// 得到table的行号
    if (rowI > -1){
    String id=table.getValueAt(rowI, 0).toString();
    dialog(id);
    }
    }

    private void dialog(String id){//这个就是我要显示相关信息的dialog
                      //本来在这个函数里,没有下面的3句号,双击事件是可以的,
                      //但是有了这三句话,双击就变单击了,
    JDialog dialog=new JDialog(new Frame(),"hello",true);
    dialog.setSize(400,300);
    dialog.setVisible(true);
    System.out.println(id);
    }
    }
      

  5.   

    是这样?要记的给分啊package test;import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JDesktopPane;public class Frame2 extends JFrame {
        BorderLayout borderLayout1 = new BorderLayout();
        JDesktopPane desktop=new JDesktopPane();
        JButton btn=new JButton("点");
        public Frame2() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    /**
         * Component initialization.
         *
         * @throws java.lang.Exception
         */
        private void jbInit() throws Exception {
            this.setContentPane(desktop);
            setSize(new Dimension(400, 300));
            setTitle("Frame Title");
            desktop.setLayout(borderLayout1);
            this.add(btn,borderLayout1.NORTH);
            
            btn.addActionListener(new ActionListener()
                    {
                        public void actionPerformed(ActionEvent e)
                        {
                            method();
                        }
                    });
            
          
        }
        
        public  void method()
        {
            inner inner=new inner();
            this.add(inner);
        }
        
        public static void main(String[] args)
        {
            new Frame2().setVisible(true);
        }
    }
    =======================================================package test;import java.awt.BorderLayout;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    import javax.swing.table.JTableHeader;
    import java.awt.event.ActionListener;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.JInternalFrame;
    import javax.swing.JTable;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseAdapter;public class inner extends JInternalFrame {
        BorderLayout borderLayout1 = new BorderLayout();
        Object[][] object=new Object[][]{{"1","2","3"},{"4","5","6"},{"7","8","9"}};
        String[] cols=new String[]{"A","B","C"};
        JTableHeader header;
        JTable table = new JTable(new DefaultTableModel(object,cols){
            public boolean isCellEditable(int row, int column)
            {
                return false;
            }
        });
        
        public inner() {
            try {
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    private void jbInit() throws Exception {
            getContentPane().setLayout(borderLayout1);
            this.setSize(100,100);
            this.setClosable(true);
            this.setResizable(true);
            table.addMouseListener(new inner_table_mouseAdapter(this));
            this.getContentPane().add(table, java.awt.BorderLayout.CENTER);
            header=table.getTableHeader();
            this.add(header,java.awt.BorderLayout.NORTH);
            this.setVisible(true);
        }    public static void main(String[] args) {
            inner inner = new inner();
        }    public void table_mouseClicked(MouseEvent e) {
            if (e.getClickCount()==2)
            {
                new Dialog1(table.getSelectedRow());
            }
        }
    }
    class inner_table_mouseAdapter extends MouseAdapter {
        private inner adaptee;
        inner_table_mouseAdapter(inner adaptee) {
            this.adaptee = adaptee;
        }    public void mouseClicked(MouseEvent e) {
            adaptee.table_mouseClicked(e);
        }
    }-=================================================================package test;import java.awt.BorderLayout;
    import java.awt.Frame;import javax.swing.JDialog;
    import javax.swing.JPanel;
    import javax.swing.JLabel;public class Dialog1 extends JDialog {
        JPanel panel1 = new JPanel();
        BorderLayout borderLayout1 = new BorderLayout();
        JLabel lab = new JLabel();    public Dialog1(Frame owner, String title, boolean modal) {
            super(owner, title, modal);
            try {
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    public Dialog1(int row) {
            this(new Frame(), "Dialog1", true);
            lab.setText("你选中的是第"+(row+1)+"行");
            this.setVisible(true);
        }
        
            private void jbInit() throws Exception {
            panel1.setLayout(borderLayout1);
            this.setContentPane(panel1);
            this.setSize(100,100);
            this.add(lab, java.awt.BorderLayout.CENTER);
        }
    }