Implements interface using java swing.



a) Set the first column to be uneditable in JTable.

    /** Table model of the table. */
    final DefaultTableModel dataModel = new DefaultTableModel(
            new Object[][] {{1,"=",""}},
            new String[] {"criterion id", "operation name", "value"}
           
        ){

        // Set col 0 to uneditable.
        public boolean isCellEditable(int row, int col){
            if(col != 0){
                return true;
            }else{
                return false;
            }
        }

b) Implement  TreeView by using JButton/Graphics2d/Line2D.Double.

   
  fig1. the picture of TreeView.   
     1) Create class Node which contain these variable and methods.
                   Node parentNode;
                   Node rootNode;
                   List<Node> children;
                   int layer,level;
                   Line2D.Double line;
                   public void addChild(Node childNode);
                   public void setPrentLevel()
     2) Implement the addChild&setParentLevel method.
                 
                   public void addChild(Node childNode){
                         //make sure the child node is not exist.
                         //set the layer of child node to be layer of parent plus 1.
                         //set the level of child node to be the number of child node in this layer currently.
                         // if the child node is leaf node, then set the level of parent node recursively.
                   }

                   public void setParentLevel(){
                         //Make sure the parent is not null
                         //Set the level of parent to be the mid-level of all the children totally.
                         //Call setParentLevel of this parent node. recursive call.
                   }

c) Implement add/del row in JTable.

        // Handler "new criterion" event.
        buttonNewCriterion.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                indexOfCriterion++;
                dataModel.insertRow(tableView.getRowCount(), new Object[]{new JButton("1"),"=",""});
                tableView.setRowSelectionInterval(tableView.getRowCount() - 1,tableView.getRowCount() - 1);
               
            }
        });
       
        // Handler "new condition" event.
        buttonNewCondition.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                int selectedRow = tableView.getSelectedRow();
                Integer criterionIndex = (Integer)(dataModel.getValueAt(selectedRow, 0));
                dataModel.insertRow(selectedRow + 1, new Object[]{criterionIndex,"=",""});
                tableView.setRowSelectionInterval(selectedRow + 1,selectedRow + 1);
               
            }
        });   
       
        // Handler "delete condition" event.
        buttonDelCondition.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if(tableView.getSelectedRow() != -1){
                    int selectedRow = tableView.getSelectedRow();
                    dataModel.removeRow(selectedRow);
                    if(selectedRow > 0){
                        tableView.setRowSelectionInterval(selectedRow - 1,selectedRow - 1);
                    }else if(tableView.getRowCount() > 0){
                        tableView.setRowSelectionInterval(0, 0);
                    }
                }
            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值