vector
如何传递给另一个班级?我想通过使用余弦相似性来比较Case.java中的向量1,它位于User.java和vector
2中。
User.java
JButton btnNewButton = new JButton("Process");
btnNewButton.setBounds(360, 296, 89, 23);
contentPane.add(btnNewButton);
btnNewButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String a=Integer.toString(comboBox.getSelectedIndex()+1);
String b=Integer.toString(comboBox_1.getSelectedIndex()+1);
String day=Integer.toString(comboBox_2.getSelectedIndex()+1);
Vector<String> myVector=new Vector <String> (3,2);
myVector.add(a);
myVector.add(b);
myVector.add(day);
myVector.add(valuesOfCheckBox);
String holder;
holder=myVector.toString();
Case ca= new Case();
try {
ca.addPlace(holder);
LoginGUI um= new LoginGUI();
um.setVisible(true);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Case.java
public void addPlace( int[] h) {
int vec1[] = h;
int vec2[] = [2,1,3,2];
double cos_sim = cosine_similarity(vec1,vec2);
}
答案 0 :(得分:0)
我用这种方式解决了它: -
<强> User.java 强>
ArrayList<Integer> myVector=new ArrayList<Integer>();
myVector.add(a);
myVector.add(b);
myVector.add(day);
if(chckbxLei.isSelected())
{
myVector.add(lei);
}
if(chckbxAdv.isSelected())
{
myVector.add(adv);
}
Case ca= new Case();
try {
ca.addPlace(myVector);
LoginGUI um= new LoginGUI();
um.setVisible(true);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Case.java
public void addPlace( ArrayList<Integer> h) throws Exception {
int[] vec1 = h.stream().mapToInt(t -> t).toArray();
int vec2[] = [2,1,3,2];
double cos_sim = cosine_similarity(vec1,vec2);
}