hi everyone,

I have a textpane using the default styled document. This textpane contains a icon and some formatted text. Next i have a file saved to my disk which is a document of another textpane. What i want to do is be able to append the two documents together and make those two documents into one document.

Can someone show me any codings or explain me how this can actually achieved.

My e-mail is freesoft_2000@yahoo.com

Yours Sincerely

Richard West

hi everyone,

This is as far as i have gotten. The below class compiles without any errors but it still does not work. Maybe some one can check and see what i am doing wrong in my code. The document i am using is from a textpane that i have somewwhere else and then call this class in to do some clip board operations for me.

The values i passed into the class is as follows:

JDocumentClipboard Clip1 = new JDocumentClipboard();
Document Doc1;
int a1, b1, c1, d1;
Doc1 = TextPane1.getDocument();
a1 = TextPane1.getSelectionStart();
b1 = TextPane1.getSelectionEnd();
c1 = Doc1.getLength();
d1 = TextPane1.getCaretPosition();
Clip1.documentvalues(Doc1, a1, b1, c1, d1);
Clip1.documentcopy();

The below class is the class that doe most of the manipulation but does not seem to work

public class JDocumentClipboard

{

Document Doc2;
int a, b, c, d;

public void documentvalues (Document Doc1, int a1, int b1, int c1, int d1)
{
Doc2 = Doc1;
a = a1;
b = b1;
c = c1;
d = d1;
}

public Document documentparse ()
{
Document Doc3;

Doc3 = Doc2;

try
{
Doc3.remove(0, a - 1);
Doc3.remove(b + 1, c);
}

catch (BadLocationException e)
{

}

return Doc3;
}

public Document documentupper ()
{
Document Doc4;

Doc4 = Doc2;

try
{
Doc4.remove(d, c);
}

catch (BadLocationException e)
{

}

return Doc4;
}

public Document documentlower ()
{
Document Doc5;

Doc5 = Doc2;

try
{
Doc5.remove(0, d);
}

catch (BadLocationException e)
{

}

return Doc5; 
}

public void documentcopy ()
{
Document Doc6, Doc7, Doc8;

Doc6 = documentupper();
Doc7 = documentparse();
Doc8 = documentlower(); 

try
{
File file1 = new File("C:/Clip.dat");
FileOutputStream fStream = new FileOutputStream(file1);
ObjectOutput stream = new ObjectOutputStream(fStream);
stream.writeObject(Doc6);
stream.writeObject(Doc7);
stream.writeObject(Doc8);
stream.flush();
stream.close();
fStream.close();
}

catch (Exception e)
{

}

}

public Document documentpaste ()
{
Document Doc9 = null;

try
{
File file2 = new File("C:/Clip.dat");
FileInputStream fStream = new FileInputStream(file2);
ObjectInput stream = new ObjectInputStream(fStream);
Object obj = stream.readObject();
if(obj instanceof Document)
{
Doc9 = ((Document) obj);
}
stream.close();
fStream.close();
}

catch (Exception e)
{

}

return Doc9; 
}

} 

Maybe someone can help me with this problem as i don't really know what i have done wrong

Thank You

Your Sincerely

Richard West

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.