Hi all, I am trying to call a 2D array from another class, and equate the 2D array to a 2D array in the class its at. However, I'm having some problems. I can call the 2D array from the class that I want to, but it seems like my 2D array is empty after it is being called. May I know what went wrong?
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
class MatchApplet extends JApplet
{
TextArea outputArea;
JButton button;
JButton reset;
JTextField tF1;
JTextField tF2;
JLabel l1;
JLabel l2;
String s1;
String s2;
static String display1 = "";
static String display2 = "";
static double[][] myDouble = new double[1000][1000];
static int x=0, y=0;
public static void main(String[] args)
{
//Application for program
Frame f = new Frame();
f.addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent e)
{
System.exit(0);
};
});
MatchApplet ut = new MatchApplet();
ut.setSize(900,900); // same size as defined in the HTML APPLET
f.add(ut);
f.pack();
ut.init();
f.setSize(900,900 + 100); // add 20, seems enough for the Frame title,
f.show();
//end of application for program
}//end of public static void main(String[] args)
public void init()
{
try
{
BufferedReader in1 = new BufferedReader(new FileReader("C:\\Users\\Serene\\Documents\\Major Project\\Alignment Algorithms\\1a00(50).txt")); //reading files in specified directory
BufferedReader in2 = new BufferedReader(new FileReader("C:\\Users\\Serene\\Documents\\Major Project\\Alignment Algorithms\\1a0a(50).txt")); //reading files in specified directory
BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Serene\\Documents\\Major Project\\Alignment Algorithms\\Testing2.txt")); //reading files in specified directory
String str1;
while ((str1 = in1.readLine()) != null) //file reading
{
display1 = str1;
System.out.print(display1);
}
in1.close();
System.out.println("");
String str2;
while ((str2 = in2.readLine()) != null) //file reading
{
display2 = str2;
System.out.print(display2);
}
in2.close();
System.out.println("");
String line;
while ((line = in.readLine()) != null) //file reading
{
String[] values = line.split(",");
for (String str : values)
{
double str_double = Double.parseDouble(str);
myDouble[x][y] = str_double;
System.out.print(myDouble[x][y]);
y=y+1;
}
x=x+1;
y=0;
System.out.println("");
}
in.close();
Container c = getContentPane();
c.setLayout(new FlowLayout());
outputArea = new TextArea(40,110);
Font font = new Font("Courier", Font.PLAIN, 12);
outputArea.setFont(font);
outputArea.setEditable(false);
tF1 = new JTextField(display1);
tF2 = new JTextField(display2);
l1 = new JLabel("Sequence 1:");
l2 = new JLabel("Sequence 2:");
c.add(l1);
c.add(tF1);
c.add(l2);
c.add(tF2);
c.add(outputArea);
final Substitution sub = new Blosum50();
s1 += tF1.getText();
s2 += tF2.getText();
Output out = new Output ()
{
public void print(String s)
{ outputArea.append(s); }
public void println(String s)
{ outputArea.append(s); outputArea.append("\n"); }
public void println()
{ outputArea.append("\n"); }
};
outputArea.setText("");
(new NW (sub, 8, s1, s2)).domatch(out, "GLOBAL ALIGNMENT");
(new SW (sub, 8, s1, s2)).domatch(out, "LOCAL ALIGNMENT");
}catch( IOException ioException ) {}
}//end of init()
static double[][] getMyDouble()
{ return myDouble; }
}//end of class
// The class of substitution (scoring) matrices
abstract class Substitution
{
public double[][] score;
void buildscore(String residues, String residues2, double[][] residuescores)
{
// Allow lowercase and uppercase residues (ASCII code <= 127):
score = new double[127][127];
for (int i=0; i<residues.length(); i++)
{
char res1 = residues.charAt(i);
for (int j=0; j<=i; j++)
{
char res2 = residues2.charAt(j);
score[res1][res2] = score[res2][res1]
= score[res1][res2+32] = score[res2+32][res1]
= score[res1+32][res2] = score[res2][res1+32]
= score[res1+32][res2+32] = score[res2+32][res1+32]
= residuescores[i][j];
}
}
}
abstract public String getResidues();
abstract public String getResidues2();
}
// The BLOSUM50 substitution matrix for amino acids (Durbin et al, p 16)
class Blosum50 extends Substitution
{
private String residues = MatchApplet.display1;
private String residues2 = MatchApplet.display2;
public String getResidues()
{ return residues; }
public String getResidues2()
{ return residues2; }
private double[][] residuescores = MatchApplet.getMyDouble();
void array()
{
System.out.print(residuescores);
}
public Blosum50()
{ buildscore(residues, residues2, residuescores); }
}