如何将向量传递给不同的class?
How to pass vector to different class?
vector
如何传递给另一个 class?我想通过使用余弦相似度来比较 User.java 中的向量 1 和 Case.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);
}
我是这样解决的:-
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);
}
vector
如何传递给另一个 class?我想通过使用余弦相似度来比较 User.java 中的向量 1 和 Case.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);
}
我是这样解决的:-
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);
}