Implements interface Using Java Swing.

xiaoxiao2021-03-31  231

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 unloadITable.

Public Boolean IscelleDitable (int Row, Int col) {

IF (col! = 0) {

Return True;

} else {

Return False;

}

}

b) Implement TreeView by Use JButton / Graphics2D / Line2D.double.

Fig1. The picture of tre.

1) CREATE CLASS Node Which Contain these Variable and methods.

Node ParentNode;

Node rootnode;

List 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, The set the level of perent node recursively.

}

Public void setparentLevel () {

// Make Sure the Parent is not null

// set the level of pent 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 activityListener () {

Public Void ActionPerformed (ActionEvent E) {

IndexOfcrienterion ;

DataModel.inSertrow (TableView.Getrowcount (), new object [] {new jbutton ("="), "=", "});

TableView.selectrowSelectionInterval (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) (SELECTEDROW, 0));

DataModel.inSertrow (SELECTEDROW 1, New Object [] {criterionIndex, "=", "});

TableView.setrowSelectionInterval (SELECTEDROW 1);

}

});

// Handler "delete conputing" event.

ButtOndelcondition.AddActionListener (new activityListener () {

Public Void ActionPerformed (ActionEvent E) {

IF (TableView.getSelectedRow ()! = -1) {

Int selectedrow = TableView.getSelectedRow ();

DataModel.RemOverow (SELECTEDROW);

IF (SELECTEDROW> 0) {

TableView.selectRowSelectionInterval (SELECTEDROW - 1, SELECTEDROW - 1);

} else if (TableView.GetrowCount ()> 0) {

TableView.setrowSelectionInterval (0, 0);

}

}

}

});

转载请注明原文地址:https://www.9cbs.com/read-130923.html

New Post(0)