哎,用FLASH不要太简单哦,呵呵!

解决方案 »

  1.   

    偶也可以用flash做。楼主真是有钱人啊!
      

  2.   

    不过我感觉用vector不是很妥当用hashtable比较好
      

  3.   

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.Vector;
    public class Frame2 extends JFrame {
      String column[]={"name","sex","phone"};
      String row[][]={{"name","sex","phone"},{"people1","Male","12234"},{"people2","Female","3423"},{"people2","Female","34435"}};
      boolean date[][]=new boolean[100][100];
      Vector vector=new Vector() ;
      MyTable jTable1=new MyTable(row,column);
      
      JButton Button1 = new JButton();
      JButton Button2 = new JButton();  public Frame2() {
        try {
          MyInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
         setSize(400,400);
         setVisible(true);
      }
      public static void main(String[] args) {
        Frame2 frame2 = new Frame2();
        
        
        
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
      }
      private void MyInit() throws Exception {
        this.getContentPane().setLayout(null);
        jTable1.setCellSelectionEnabled(true);
        jTable1.setframe(this);
        clear();    jTable1.setBounds(new Rectangle(28, 57, 350, 223));
        Button1.setBounds(new Rectangle(59, 9, 81, 32));
        Button1.setText("Button1");
        Button1.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e)
         {
            Button2.setEnabled(true);
            Button1.setEnabled(false);
            jTable1.clearSelection() ;
               clear();
            
         }
        
        
            }
            );
        Button2.setBounds(new Rectangle(226, 13, 112, 28));
        Button2.setText("Button2");
        Button2.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e)
         {
         jTable1.clearSelection();
         Button1.setEnabled(true);
         Button2.setEnabled(false);
         clear();
            
         }
        
        
            }
            );
        
        
        this.getContentPane().add(jTable1, null);
        this.getContentPane().add(Button1, null);
        this.getContentPane().add(Button2, null);
      }
      
      public void clear()
      {
       for(int i=0;i<date.length;i++)
         for(int j=0;j<date[0].length;j++)
            date[i][j]=false;
       }
      public void set1(int r1,int c1,boolean state)
      {
       date[r1][c1]=state;
       if(state)
       {
       vector.add(jTable1.getValueAt(r1,c1));
       Button1.setEnabled(false);
       Button2.setEnabled(true); 
       }
      
      
      
       }
      public boolean IsSelected(int r1,int c1)
      {
       return date[r1][c1];
       } 
         
    }class MyTable extends JTable
    {
    Frame2 frame2;
    MyTable(Object[][] rowData, Object[] columnNames)
    {
    super(rowData,columnNames);
    }
    public boolean isCellEditable(int row, int column) 
    {
    return false;
    }

    public void setframe(Frame2 frame)
    {
    frame2=frame;
    }
    public void valueChanged(ListSelectionEvent e)
    {
    if(frame2==null){System.out.println("null");return;}

    super.valueChanged(e);

    int r1=getSelectedRow();
    int c1=getSelectedColumn();
    if(!frame2.IsSelected(r1,c1))
    {
    //System.out.println("unselected");
    setSelectionBackground(Color.white);
            frame2.set1(r1,c1,true);
    }

    else 
                    {
                     //System.out.println("selected");
                     setSelectionBackground(Color.blue);
                     frame2.set1(r1,c1,false);
                    }
                    
    }
    }
      

  4.   

    楼主的星星,是vc版的高手吧,怎么转java了?
      

  5.   

    有没有方法实现鼠标点选两个不同的cell?不是选择一片
      

  6.   

    把这个双击过的cell的信息存在vector中~
    等我在双击表格的其它某一cell时~
    这一cell变蓝~
    前面双击过的cell的颜色也是蓝色~
    如果我双击蓝色的cell~此蓝色cell变回原色~这个~上面的~
      

  7.   

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.Vector;
    public class Frame2 extends JFrame {
      String column[]={"name","sex","phone"};
      String row[][]={{"name","sex","phone"},{"people1","Male","12234"},{"people2","Female","3423"},{"people2","Female","34435"}};
      boolean date[][]=new boolean[100][100];
      Vector vector=new Vector() ;
      MyTable jTable1=new MyTable(row,column);
      
      JButton Button1 = new JButton();
      JButton Button2 = new JButton();  public Frame2() {
        try {
          MyInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
         setSize(400,400);
         setVisible(true);
      }
      public static void main(String[] args) {
        Frame2 frame2 = new Frame2();
        
        
        
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
      }
      private void MyInit() throws Exception {
        this.getContentPane().setLayout(null);
        jTable1.setCellSelectionEnabled(true);
        jTable1.setframe(this);
        clear();    jTable1.setBounds(new Rectangle(28, 57, 350, 223));
        Button1.setBounds(new Rectangle(59, 9, 81, 32));
        Button1.setText("Button1");
        Button1.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e)
         {
            Button2.setEnabled(true);
            Button1.setEnabled(false);
            try{
            jTable1.clearSelection() ;
             }
             catch(Exception ex)
             {
               ex.printStackTrace();
              }
               clear();
            
         }
        
        
            }
            );
        Button2.setBounds(new Rectangle(226, 13, 112, 28));
        Button2.setText("Button2");
        Button2.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e)
         {
        
         Button1.setEnabled(true);
         Button2.setEnabled(false);
         try{
         jTable1.clearSelection();
                  }
                  catch(Exception ex)
                  {
                   ex.printStackTrace();
                 }
                  
                  
         clear();
            
         }
        
        
            }
            );
        
        
        this.getContentPane().add(jTable1, null);
        this.getContentPane().add(Button1, null);
        this.getContentPane().add(Button2, null);
      }
      
      public void clear()
      {
       for(int i=0;i<date.length;i++)
         for(int j=0;j<date[0].length;j++)
            date[i][j]=false;
       }
      public void set1(int r1,int c1,boolean state)
      {
       date[r1][c1]=state;
       if(state)
       {
       if(!vector.contains(jTable1.getValueAt(r1,c1)))
       vector.add(jTable1.getValueAt(r1,c1));
       Button1.setEnabled(false);
       Button2.setEnabled(true); 
       }
      
      
      
       }
      public boolean IsSelected(int r1,int c1)
      {
       return date[r1][c1];
       } 
         
    }class MyTable extends JTable implements MouseListener
    {
    Frame2 frame2;
    MyTable(Object[][] rowData, Object[] columnNames)
    {
    super(rowData,columnNames);
    addMouseListener(this);
    }
    public boolean isCellEditable(int row, int column) 
    {
    return false;
    }
    public boolean isCellSelected(int row, int column)
    {
    boolean m_boolean=super.isCellSelected(row,column);
    if(frame2==null)return m_boolean;
    boolean m_boolean2=frame2.IsSelected(row,column);
    //System.out.println(m_boolean2);


    return m_boolean2;

    }
    public void setframe(Frame2 frame)
    {
    frame2=frame;
    }
    public void mouseClicked(MouseEvent e)
    {
    if(frame2==null){return;}
    int r1=getSelectedRow();
    int c1=getSelectedColumn();
    if(!isCellSelected(r1,c1))
    {
    //System.out.println("unselected");
            frame2.set1(r1,c1,true);
            setSelectionBackground(Color.blue);
            repaint();
    }

    else 
                    {
                     //System.out.println("selected");
                     frame2.set1(r1,c1,false);
                     setSelectionBackground(Color.blue);
                     repaint();
                    
                    }
    }
    public void mousePressed(MouseEvent e)
    {

    }
    public void mouseReleased(MouseEvent e)
    {

    }
    public void mouseEntered(MouseEvent e)
    {

    }
    public void mouseExited(MouseEvent e)
    {
    }}
      

  8.   

    楼上的是单击,加上if(e.getClickCount()==2)就是双击了,呵呵
      

  9.   

    只实现了鼠标单击代替双击,暂时找不到双击的办法,如果要用单击模拟双击,那还要写上一段代码,比较麻烦。再想想看有没有简单的方法。java 中好像找不到处理双击的事件,谁知道请告诉我,谢谢。
      

  10.   

    用e,getClientCount()可以得到点击次数,为2是双击。
      

  11.   

    to beyond_xiruo(希偌) 
    谢谢,我看看
      

  12.   

    public void mouseClicked(MouseEvent e)
    {
    if(frame2==null){return;}
    int r1=getSelectedRow();
    int c1=getSelectedColumn();
    if(!isCellSelected(r1,c1))
    {
    //System.out.println("unselected");
            frame2.set1(r1,c1,true);
            setSelectionBackground(Color.blue);
            repaint();
    }

    else 
                    {
                     //System.out.println("selected");
                     frame2.set1(r1,c1,false);
                     setSelectionBackground(Color.blue);
                     repaint();
                    
                    }
    }
    改为————————————————————————————
            public void mouseClicked(MouseEvent e)
            {
                    if(Frame1==null){return;}
                    if(e.getClickCount()==2) {
                    int r1=getSelectedRow();
                    int c1=getSelectedColumn();
                    if(!isCellSelected(r1,c1))
                    {
                            //System.out.println("unselected");
                            Frame1.set1(r1,c1,true);
                            setSelectionBackground(Color.blue);
                            repaint();
                    }                else
                    {
                            //System.out.println("selected");
                            Frame1.set1(r1,c1,false);
                            setSelectionBackground(Color.blue);
                            repaint();                }}
            }
      

  13.   

    好了,谢了,可以在public void mouseClicked(MouseEvent e)中
    if(frame2==null){return;}
    后加上一句if(e.getClickCount()!=2)return;
    这样就可以了。
      

  14.   

    beyond_xiruo(希偌)又慢了,呵呵,今天的网速啊。
      

  15.   

    直接
    if(Frame1==null||e.getClickCount!=2){return;}
    最简单
      

  16.   

    总觉得在 MyTable 中调用Frame2有点怪怪的,不过我也懒得想其它的方法了,大家有什么好方法来谈谈。