One could add a node group to the main panel(Text Pane) by clicking "add group" button.
The class definition of the node group panel(JPanel) and the action listeners of "Add Group" button, "Remove" button are shown as following:
Class NodesGroupPanel:
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* Displays and generates nodes.
*
* @author chenyang
*/
public class NodesGroupPanel extends JPanel {
private int newWidth = 512;
private int newHeight = 27;
private JLabel groupNrBt;
private JTextField node1Txt, node2Txt, stepTxt, x1Txt, x2Txt, y1Txt, y2Txt;
public NodesGroupPanel(int groupNr) {
super();
if (groupNr<10){ groupnrbt =" new">=10&&groupNr<100){ groupnrbt =" new">=100&&groupNr<1000){ groupnrbt =" new" groupnrbt =" new" node1txt =" new" node2txt =" new" steptxt =" new" x1txt =" new" x2txt =" new" y1txt =" new" y2txt =" new">
jButton5ActionPerformed of "Add Group" button:
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
jPanel6.setText(jPanel6.getText() + "\n\n");
NodesGroupPanel ngp = new NodesGroupPanel(nodesManager.getGroupCount() + 1);
jPanel6.add(ngp);
nodesManager.addToGroup(ngp);
// repaint
jPanel6.validate();
jPanel6.repaint();
// add item to jComboBox1 in remove panel
jComboBox1.addItem(nodesManager.getGroupCount());
}
jButton4ActionPerformed of "Add Group" button:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
if (nodesManager.getGroupCount() > 0) {
removeNodeGroupDialog.setVisible(true);
}
}
%%%%%%%%%%%%%%
where removeNodeGroupDialog is shown as: And the "Remove" button on this Dialog acts as:
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
NodesGroupPanel ngp = nodesManager.removeNodesGroup(jComboBox1.getSelectedIndex() + 1);
if (ngp != null) {
jPanel6.remove(ngp);
jPanel6.validate();
jPanel6.repaint();
jComboBox1.removeItemAt(jComboBox1.getItemCount() - 1);
}
}
No comments:
Post a Comment