Im new to Java and have a problem
I need to calculate longest common substring between two
strings and show it like this:

my code for get the LCS
from two strings is this:
public class FindLCS {
public static String lcs(String str1, String str2)
{
int i, j;
int m = str1.length();
int n = str2.length();
String[][] b = new String [m][n];
for (int s = 1; s<m; s++)
b[s][0] = "";
for (int z = 1; z<n; z++)
b[0][z] = "";
for (i = 1; i<m; i++)
for(j = 1; j<n; j++)
{
if(str1.charAt(i-1) == str1.charAt(j-1))
b[i][j] = b[i-1][j-1]+str1.charAt(+1);
else if(b[i-1][j].length() >= b[i][j-1].length())
b[i][j]= b [i-1][j];
else
b[i][j] = b[i][j-1];
}
return b [m-1][n-1]
}
}
and my view class
so far
public class LCSView extends JFrame
{
public void Frame()
{
JFrame frame = new JFrame();
setSize(500,200);
}
public void modString(String str1, String str2)
{
repaint();
}
public void paintComponent(Graphics g)
{
g.setColor(Color.BLACK);
g.drawString(str1, 50, 50);
g.drawString(str2, 50, 60);
int w = g.getFontMetrics().charWidth('a');
}
the method modstrings changes these two strings so
that they repaints with the common subsequences they have.
I want to create a line between all the subsequence
in in the same color as viewing a sub from 2 strings
so all lcs between two strings should be painted
not sure how to do it
so would be very helpful if someone could help out here
main should probably look like this:
public class main
{
public static void main (String[] args)
{
String strTest1 = JOptionPane.showInputDialog("Type the first String");
String strTest2 = JOptionPane.showInputDialog("Type the second String");
Frame progam = new Frame();
program.show();
}
}
The main methods should repeatedly ask a user to provide two strings
and use the view class to display them
first time posting here so hope I have provided with enough
for you to understand


Sign In
Create Account


Back to top











