我开发了一个使用 neo4j 创建本体的软件。构建本体后,我开始将 200 万行的数据集映射到它,这大约需要 20 分钟才能完成。因此,我希望添加一个显示流程执行的 JFrame。下面的代码在开始时创建 JFrame,然后开始映射数据集。但是,我可以在执行期间看到 JFrame,但它的组件在映射完成后出现在 JFrame 内。我读过这个问题可能是由于缺少围绕代码的线程。谁能帮我解决这个问题??
void createGraphDataset(String [][] choices , final ArrayList<String[]> DatabaseFile, GraphDatabaseService BORO_DB){
JFrame converterFrame = new JFrame();
converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
converterFrame.setBounds(100, 100, 650, 288);
JPanel contentPane = new JPanel();
contentPane.setLayout(null);
contentPane.setVisible(true);
converterFrame.getContentPane().add(contentPane);
JPanel panelNeo1 = new JPanel();
panelNeo1.setBounds(6, 6, 638, 254);
panelNeo1.setVisible(true);
contentPane.add(panelNeo1);
panelNeo1.setLayout(null);
JLabel labelNeo1 = new JLabel("CSV BORO Converter");
labelNeo1.setBounds(16, 19, 260, 37);
panelNeo1.add(labelNeo1);
labelNeo1.setVisible(true);
JPanel panelNeo2 = new JPanel();
panelNeo2.setBounds(16, 60, 605, 167);
panelNeo1.add(panelNeo2);
panelNeo2.setLayout(null);
panelNeo2.setVisible(true);
/*
JProgressBar progressBar = new JProgressBar();
progressBar.setBounds(27, 89, 547, 20);
panelNeo2.add(progressBar);
panelNeo2.setVisible(true);
*/
JLabel labelNeo2 = new JLabel(" Processing: Number of row");
labelNeo2.setOpaque(true);
labelNeo2.setBounds(28, 36, 184, 20);
panelNeo2.add(labelNeo2);
labelNeo2.setVisible(true);
JLabel labelNeo3 = new JLabel("");
labelNeo3.setBounds(212, 36, 76, 20);
panelNeo2.add(labelNeo3);
labelNeo3.setVisible(true);
JLabel labelNeo4 = new JLabel();
labelNeo4.setText(String.valueOf(DatabaseFile.size()));
labelNeo4.setBounds(311, 36, 70, 20);
panelNeo2.add(labelNeo4);
labelNeo4.setVisible(true);
JLabel labelNeo6 = new JLabel("of");
labelNeo6.setBounds(288, 36, 23, 20);
panelNeo2.add(labelNeo6);
labelNeo6.setVisible(true);
converterFrame.setVisible(true);
TopNode= new Node [DatabaseFile.get(0).length];
//Create TopNodes
Transaction tx0 = BORO_DB.beginTx();
try{
for(int u =0; u<DatabaseFile.get(0).length;u++){
TopNode[u]=BORO_DB.createNode();
TopNode[u].setProperty("name", choices[u][0]);
}
tx0.success();
}
finally{
tx0.finish();
}
//Create the database
for(int i =0; i<DatabaseFile.size();i++){
Transaction tx2 = BORO_DB.beginTx();
try
{
// Nodes for each row
Node []graphNode= new Node [DatabaseFile.get(i).length];
// Relationships for each row ingoing
Relationship [] graphRelOn = new Relationship [DatabaseFile.get(i).length-1];
// Relationships for each row outgoing
Relationship [] graphRelOut = new Relationship [DatabaseFile.get(i).length-1];
//Relationship to TopNode ingoing
Relationship TopNodeRelIn[]=new Relationship [DatabaseFile.get(i).length];
//Creates Nodes for row and relationship to TopNode
for(int j=0; j<DatabaseFile.get(i).length;j++){
//Stores Database values
String []ValuesRow =DatabaseFile.get(i);
//Creates nodes for 1 row
graphNode[j] = BORO_DB.createNode();
graphNode[j].setProperty("name", ValuesRow[j]);
//From row to TopNode Relationship (enter)
TopNodeRelIn[j]=graphNode[j].createRelationshipTo(TopNode[j], RelTypes.typeInstances);
TopNodeRelIn[j].setProperty("relationship-type", "typeInstances");
}
//Creates Relationships
for(int k=0; k<(DatabaseFile.get(i).length)-1;k++){
//Between same elements of the same row (left to right)
graphRelOn[k]=graphNode[k].createRelationshipTo(graphNode[k+1], RelTypes.relatesTo);
graphRelOn[k].setProperty("relationship-type", "relatesTo");
//Between same elements of the same row (right to left)
graphRelOut[k]=graphNode[(DatabaseFile.get(i).length)-1].createRelationshipTo(graphNode[(DatabaseFile.get(i).length)-(2+k)], RelTypes.relatesTo);
graphRelOut[k].setProperty("relationship-type", "relatesTo");
}
tx2.success();
}
finally
{
tx2.finish();
}
}
}