修改之后的java 代码:

package com.platformda.optimize;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Point;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List; import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import com.platformda.optimize.algorithm.BFGSSetting;
import com.platformda.optimize.algorithm.BFGSSettingEditor;
import com.platformda.optimize.algorithm.CGSetting;
import com.platformda.optimize.algorithm.CGSettingEditor;
import com.platformda.optimize.algorithm.DFPSetting;
import com.platformda.optimize.algorithm.DFPSettingEditor;
import com.platformda.optimize.algorithm.DifferentialEvolutionSetting;
import com.platformda.optimize.algorithm.DifferentialEvolutionSettingEditor;
import com.platformda.optimize.algorithm.LMSetting;
import com.platformda.optimize.algorithm.LMSettingEditor;
import com.platformda.optimize.algorithm.NewSDSetting;
import com.platformda.optimize.algorithm.NewSDSettingEditor;
import com.platformda.optimize.algorithm.NewTRSetting;
import com.platformda.optimize.algorithm.NewTRSettingEditor;
import com.platformda.optimize.algorithm.PSOSetting;
import com.platformda.optimize.algorithm.PSOSettingEditor;
import com.platformda.optimize.algorithm.PatternSearchSetting;
import com.platformda.optimize.algorithm.PatternSearchSettingEditor;
import com.platformda.optimize.algorithm.SimplexSetting;
import com.platformda.optimize.algorithm.SimplexSettingEditor;
import com.platformda.optimize.algorithm.TRSetting;
import com.platformda.optimize.algorithm.TRSettingEditor; public class OptmanagerPanel {
OptmanagerPanel mOptmanagerPanel ; JButton addButton = new JButton();
JButton delButton = new JButton();
JButton editButton = new JButton(); ImageIcon addIcon = new ImageIcon();
ImageIcon delIcon = new ImageIcon();
ImageIcon editIcon = new ImageIcon(); Button editOkButton = new Button(" Ok ");
Button editCancleButton = new Button("Cancle");
Button addOkButton = new Button(" Ok ");
Button addCancleButton = new Button("Cancle");
JPanel okandCancleJPanel = new JPanel(); String[] columnName = { "AlgorithmName", "Duration" };
String[][] rowData ;
String[] rowName; DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable();
JScrollPane scrollPane = new JScrollPane(); JPanel tableJPanel = new JPanel();
JPanel headerJPanel = new JPanel();
JPanel addJPanel = new JPanel(); static OptSettingEditor settingEditor ;
static OptSetting setting; int row;
int editRow;
int delRow; // static JPanel editJPanel ; JFrame disEditFrame = new JFrame();
JFrame disaddFrame = new JFrame(); Point mousePoint ;
String obName;
int[] delSelected ; OptAlgorithmManager manager = new OptAlgorithmManager();
List<OptAlgorithm> algorithmlist = OptAlgorithmManager.getAllAlgorithms(); String[] addrowData = new String[2]; JPanel durationJPanel = new JPanel(); JList<Object> rowNameList;
JScrollPane addScrollPane;
String rowListName;
String delName; Box Editbox = Box.createVerticalBox();
Box addCenterBox = Box.createHorizontalBox();
Box addLeftBox = Box.createVerticalBox();
Box addBottomBox = Box.createVerticalBox();
JPanel addCenterJPanel = new JPanel(); //--
JPanel bfgsJPanel ,cgJPanel , dfpJPanel , lmJPanel,newSDJPanel ,newTRJPanel, pSJPanel, deJPanel,psoJPanel,splxJPanel,trJPanel; public void initPanel(){
mOptmanagerPanel = new OptmanagerPanel(); JFrame mJFrame = new JFrame();
mJFrame.setLayout(new BorderLayout());
mJFrame.add(mOptmanagerPanel.tableHeaderJPanel(),BorderLayout.NORTH);
mJFrame.add(mOptmanagerPanel.tablePanel(), BorderLayout.CENTER);
mJFrame.setBounds(300, 300, 300, 100);
mJFrame.pack();
mJFrame.setVisible(true);
mJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public JPanel tablePanel(){
mOptmanagerPanel = new OptmanagerPanel();
rowData = mOptmanagerPanel.getAlgorithmData(); model = new DefaultTableModel(rowData,columnName);
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrollPane = new JScrollPane(table);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //所获取的行,在删除后会自动后移
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
mousePoint = e.getPoint();
System.out.println(table.rowAtPoint(mousePoint)); obName = table.getValueAt(table.rowAtPoint(mousePoint), 0).toString();
System.out.println(obName); }
}); tableJPanel.setLayout(new BoxLayout(tableJPanel,BoxLayout.Y_AXIS));
tableJPanel.add(Box.createVerticalStrut(10));
tableJPanel.add(scrollPane);
tableJPanel.add(Box.createVerticalStrut(10)); return tableJPanel;
} public JPanel tableHeaderJPanel(){
mOptmanagerPanel = new OptmanagerPanel(); headerJPanel.setLayout(new BoxLayout(headerJPanel, BoxLayout.X_AXIS)); addIcon = new ImageIcon("Picture/add.png");
addButton.setIcon(addIcon);
delIcon = new ImageIcon("Picture/remove.png");
delButton.setIcon(delIcon);
editIcon = new ImageIcon("Picture/edit.png");
editButton.setIcon(editIcon); //存在问题:未选,则点击删除报错,已解决:加try catch
delButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { try {
delRow = table.rowAtPoint(mousePoint);
if (delRow !=-1 ) {
int delresponse = JOptionPane.showConfirmDialog(null, "Sure to remove ?", "Warning", JOptionPane.OK_CANCEL_OPTION);
if (delresponse == JOptionPane.OK_OPTION) {
model.removeRow(table.rowAtPoint(mousePoint));
} }
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "please choose before remove ! ","warning",JOptionPane.YES_OPTION);
}
}
});
//貌似都是第一个是正确的,但是点击第二次或者之后的可能就存在问题??已解决:box.remove
//还存在一个问题,修改过某一个值后,会在之后的修改框中显示同样名字的变量的修改后的值,而不是最开始的值:已解决
//不是显示 修改之后的值
//存在问题:点击删除后,再点击编辑,还可以编辑。解决:分别获取editRow和delRow
editButton.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
try {
editRow = table.rowAtPoint(mousePoint);
obName = table.getValueAt(editRow, 0).toString();
if ( editRow !=-1 ) {
switch (obName) {
case "BFGS":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.bfgsjJPanel());
disEditFrame.setTitle("BFGS");
break;
case "CG":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.cgJpanel());
disEditFrame.setTitle("CG");
break;
case "DFP":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.dfpJpanel());
disEditFrame.setTitle("DFP");
break;
case "LM":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.lmJpanel());
disEditFrame.setTitle("LM");
break;
case "NewTR":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.newTrJpanel());
disEditFrame.setTitle("NewTR");
break;
case "NewSD":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.newSdJpanel());
disEditFrame.setTitle("NewSD");
break;
case "PS":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.psJpanel());
disEditFrame.setTitle("PS");
break;
case "DE":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.deJpanel());
disEditFrame.setTitle("DE");
break;
case "PSO":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.psoJpanel());
disEditFrame.setTitle("PSO");
break;
case "SPLX":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.splxJpanel());
disEditFrame.setTitle("SPLX");
break;
case "TR":
Editbox.removeAll();
Editbox.add(mOptmanagerPanel.trJpanel());
disEditFrame.setTitle("TR");
break;
default:
System.out.println("please choose edit item");
break;
}
}
editPanel();
}catch (Exception e) {
JOptionPane.showMessageDialog(null, "please choose first !");
//System.out.println("please choose again !");
}
}
}); addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) { addPanel();
}
}); headerJPanel.add(addButton);
headerJPanel.add(delButton);
headerJPanel.add(editButton); return headerJPanel;
} public void addPanel(){
addLeftBox.removeAll();
disaddFrame.setVisible(true); mOptmanagerPanel = new OptmanagerPanel();
disaddFrame.setLayout(new BorderLayout());
addCenterJPanel.setLayout(new BorderLayout()); DefaultListModel listModel = new DefaultListModel<>();
for (OptAlgorithm mAlgorithm :algorithmlist) {
listModel.addElement(mAlgorithm.getName().toString());
}
rowNameList = new JList(listModel);
rowNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); addScrollPane = new JScrollPane(rowNameList);
addScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); rowNameList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
System.out.println(rowNameList.getSelectedIndex());
rowListName = rowNameList.getSelectedValue().toString();
System.out.println(rowListName);
switch (rowListName) {
case "BFGS":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.bfgsjJPanel());
disaddFrame.validate();
break;
case "CG":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.cgJpanel());
disaddFrame.validate();
break;
case "DFP":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.dfpJpanel());
disaddFrame.validate();
break;
case "LM":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.lmJpanel());
disaddFrame.validate();
break;
case "NewSD":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.newSdJpanel());
disaddFrame.validate();
break;
case "NewTR":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.newTrJpanel());
disaddFrame.validate();
break;
case "PS":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.psJpanel());
disaddFrame.validate();
break;
case "DE":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.deJpanel());
disaddFrame.validate();
break;
case "PSO":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.psoJpanel());
disaddFrame.validate();
break;
case "SPLX":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.splxJpanel());
disaddFrame.validate();
break;
case "TR":
addCenterBox.removeAll();
addCenterBox.add(mOptmanagerPanel.trJpanel());
disaddFrame.validate();
break;
default:
break;
}
} catch (Exception e2) {
//JOptionPane.showMessageDialog(null, "please choose add item first");
//System.out.println("again");
}
addOkButton.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
addrowData[0] = rowListName;
addrowData[1] = String.valueOf(0);
model.addRow(addrowData);
disaddFrame.setVisible(false); }
});
}
}); addCancleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disaddFrame.setVisible(false);
//System.exit(0);
}
}); addLeftBox.add(addScrollPane);
addBottomBox.add(initAddOkandCancleJPanel()); addCenterJPanel.add(addCenterBox,BorderLayout.NORTH); disaddFrame.add(addLeftBox,BorderLayout.WEST);
disaddFrame.add(addCenterJPanel,BorderLayout.CENTER);
disaddFrame.add(addBottomBox,BorderLayout.SOUTH);
disaddFrame.setTitle("Add");
disaddFrame.setBounds(750,400,300,400);
//disaddFrame.pack();
disaddFrame.setVisible(true);
} public void editPanel(){ //存在关闭后第二次打开有滚动条嵌套和确定取消按钮位置不一致的问题,已解决:box.removeAll();
editOkButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
if(settingEditor.stopEditing()){}
disEditFrame.setVisible(false);
Editbox.removeAll();
}
});
editCancleButton.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) {
disEditFrame.setVisible(false);
Editbox.removeAll();
}
}); Editbox.add(initEditOkandCancleJPanel()); disEditFrame.add(Editbox);
disEditFrame.setBounds(750,400,300,400);
disEditFrame.setVisible(true);
disEditFrame.pack();
} public String[][] getAlgorithmData(){ rowData = new String[algorithmlist.size()][2];
for (int i = 0; i < algorithmlist.size(); i++) {
rowData[i][0] = algorithmlist.get(i).getName();
rowData[i][1] = String.valueOf(i);
}
return rowData;
} /*public String[] getRowName(){
rowName = new String[algorithmlist.size()];
for (int i = 0; i < algorithmlist.size(); i++) {
rowName[i] = algorithmlist.get(i).getName();
}
return rowName;
}*/ public JPanel initAddOkandCancleJPanel(){
okandCancleJPanel = new JPanel();
okandCancleJPanel.add(addOkButton);
okandCancleJPanel.add(addCancleButton);
return okandCancleJPanel;
}
public JPanel initEditOkandCancleJPanel(){
okandCancleJPanel = new JPanel();
okandCancleJPanel.add(editOkButton);
okandCancleJPanel.add(editCancleButton);
return okandCancleJPanel;
}
/*public JPanel initdurationJPanel(){
durationJPanel.setLayout(new GridLayout(1, 2,30,10));
durationJPanel.add(new Label("Duration"));
durationJPanel.add(new TextField(0));
return durationJPanel;
}*/ public JPanel bfgsjJPanel(){
setting = new BFGSSetting();
settingEditor = new BFGSSettingEditor((BFGSSetting) setting);
bfgsJPanel = (JPanel) settingEditor.getEditorComponent();
return bfgsJPanel;
}
public JPanel cgJpanel(){
setting = new CGSetting();
settingEditor = new CGSettingEditor((CGSetting) setting);
cgJPanel = (JPanel) settingEditor.getEditorComponent();
return cgJPanel;
}
public JPanel dfpJpanel(){
setting = new DFPSetting() ;
settingEditor = new DFPSettingEditor((DFPSetting) setting);
dfpJPanel = (JPanel) settingEditor.getEditorComponent();
return dfpJPanel;
}
public JPanel lmJpanel(){
setting = new LMSetting();
settingEditor = new LMSettingEditor((LMSetting) setting);
lmJPanel = (JPanel) settingEditor.getEditorComponent();
return lmJPanel;
}
public JPanel newTrJpanel(){
setting = new NewTRSetting();
settingEditor = new NewTRSettingEditor((NewTRSetting) setting);
newTRJPanel = (JPanel) settingEditor.getEditorComponent();
return newTRJPanel;
}
public JPanel newSdJpanel(){
setting = new NewSDSetting();
settingEditor = new NewSDSettingEditor((NewSDSetting) setting);
newSDJPanel = (JPanel) settingEditor.getEditorComponent();
return newSDJPanel;
}
public JPanel psJpanel(){
setting = new PatternSearchSetting();
settingEditor = new PatternSearchSettingEditor((PatternSearchSetting) setting);
pSJPanel = (JPanel) settingEditor.getEditorComponent();
return pSJPanel;
}
public JPanel deJpanel(){
setting = new DifferentialEvolutionSetting();
settingEditor = new DifferentialEvolutionSettingEditor((DifferentialEvolutionSetting) setting);
deJPanel = (JPanel) settingEditor.getEditorComponent();
return deJPanel;
}
public JPanel psoJpanel(){
setting = new PSOSetting();
settingEditor = new PSOSettingEditor((PSOSetting) setting);
psoJPanel = (JPanel) settingEditor.getEditorComponent();
return psoJPanel;
}
public JPanel splxJpanel(){
setting = new SimplexSetting();
settingEditor = new SimplexSettingEditor((SimplexSetting) setting);
splxJPanel = (JPanel) settingEditor.getEditorComponent();
return splxJPanel;
}
public JPanel trJpanel(){
setting = new TRSetting();
settingEditor = new TRSettingEditor((TRSetting) setting);
trJPanel = (JPanel) settingEditor.getEditorComponent();
return trJPanel;
} }

java 表格项的删除、编辑、增加 修改版的更多相关文章

  1. 控制面板中java设置项如何删除

    卸载jdk或者jre后,如果控制面板中仍然有java项,重新安装可能仍然无法设置,提示找不到"javacpl.exe" 解决办法:删除C:\windows\system32\下的j ...

  2. 分享一个表格插入和删除编辑功能用jQuery实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 日常Java(测试 (二柱)修改版)2021/9/22

    题目: 一家软件公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道四则运算题目给小学生做. 二柱一下打印出好多份不同的题目,让孩子做了.老师看了作业之后,对二柱赞许有加.别的老师闻讯, 问二柱 ...

  4. java表格 JTable实例 (带滚动条,内嵌选择框)

    import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import javax.swing.JScrollPa ...

  5. 图解微信小程序---实现行的删除和增加操作

    图解微信小程序之实现行的删除和增加操作 代码笔记部分 第一步:在项目的app.json中创建一个新的页面(页面名称英文,可自定义) 第二步:在创建的新页面中编写页面(注意bindtap属性值,因为是我 ...

  6. Java学习-012-文件删除实例及源代码

    此文源码主要为应用 Java 创建文件的源代码.若有不足之处,敬请大神指正,不胜感激! 文件删除源代码如下: /** * @function 文件操作:删除文件.若文件存在且未被占用,则删除文件:若文 ...

  7. 对JAVA集合进行遍历删除时务必要用迭代器

    java集合遍历删除的方法: 1.当然这种情况也是容易解决,实现方式就是讲遍历与移除操作分离,即在遍历的过程中,将需要移除的数据存放在另外一个集合当中,遍历结束之后,统一移除. 2.使用Iterato ...

  8. IE浏览器中的加载项怎么删除

    IE浏览器中的加载项是一些软件或者浏览器的功能控件,我们可以通过禁用.开启来控制是否使用某些加载项,同时可以将一些加载项删除. 比如当我们遇到了一些不好的加载项,想要将它删除,通过这篇经验,教大家怎么 ...

  9. JQuery Easyui/TopJUI表格基本的删除功能(删除当前行和多选删除)

    需求:数据表格datagrid实现删除当前行和多选删除的功能. html <a href="javascript:void(0)" data-toggle="top ...

随机推荐

  1. Android(java)学习笔记183:判断SD卡状态和存储空间大小

    当我们在使用SD卡时候,如果我们想往SD卡里读写数据,我们必须在这之前进行一个逻辑判断,那就是判断SD卡状态和SD存储空间大小: 核心代码: String status = Environment.g ...

  2. linux tar 压缩解压缩

    解压 .tar.bz tar zxvf file.tar.gz .tar.gz2 tar jxvf file.tar.bz2 .bz gzip -d file.bz .gz2 bzip2 -d fil ...

  3. 为什么要设置Java环境变量(详解)

    关于java环境变量配置讲解: 1. PATH环境变量.作用是指定命令搜索路径,在shell下面执行命令时,它会到PATH变量所指定的路径中查找看是否能找到相应的命令程序.我们需要把 jdk安装目录下 ...

  4. LIB库加载方法-引用百度百科

    LIB库加载方法,有三种,如下: 1.LIB文件直接加入到工程文件列表中 在VC中打开File View一页,选中工程名,单击鼠标右键,然后选中\"Add Files to Project\ ...

  5. Android学习笔记(SQLite的简单使用)

    1.SQLite介绍 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp建立的公有领域项目.它的设计目标是嵌入式的,而且 ...

  6. iOS程序员的自我修养之道

    新技术的了解渠道 WWDC开发者大会视频 官方文档 General -> Guides -> iOS x.x API Diffs 程序员的学习 iOS技术的学习 官当文档 Sample C ...

  7. 关于通过bindService启动的service,在unbindService后service是否继续运行的讨论

    有三种情况:如果直接使用服务,则没有必要进行绑定,但是如果要使用服务里面的方法,则要进行绑定.具体的启动情况有下: 1.当启动时,单独调用bindService方法,在unbindService后,会 ...

  8. Codevs 1010 过河卒 2002年NOIP全国联赛普及组

    1010 过河卒 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 如图,A 点有一个过河卒 ...

  9. Jquery插件之信息弹出框showInfoDialog(成功、错误、警告、通知)

    一.信息种类说明: 1.1.操作成功信息 1.2.错误信息 1.3.警告信息 1.4.通知信息 二.使用说明 <!DOCTYPE html PUBLIC "-//W3C//DTD HT ...

  10. jQuery源码整体结构(源码2.0.3)

    拨开jQuery的面纱,最近了解了下jQuery源码整体框架.主要包括: (1)  jQuery 核心模块 (2)  sizzle 选择器引擎 (3)  Deferred 异步队列 (4)  Supp ...