Farid KHEZZAR wrote:

i'm sorry but in the Romeo and Juliet example you only use your variable 'act' in "onEvent" methods : onchapter, onendpage but NOT in your method main

That's only a detail. I think you're the one that doesn't understand.

: this is the problem. I hava tested and retested and reretested i can't use a variable like 'act' initilazed in the main methods in other events methods.
You have been walking in circles overlooking the obvious.

This is what i need to do.
Let me show you a sample
There are two ways to solve this.
Class A is your main class, Class B your implementation of the page events.
=== 1st solution ===

Class A has a variable test:
protected String test = "test";
and a corresponding getter and setter.
public void setTest(String test) { this.test = test; }
public String getTest() { return test; }
while you do stuff in class A, you can change the value of test.

Class B has a variable of type A:
protected A myMainClass;
this class is passed with the constructor of class B:
public B(A myMainClass) { this.myMainClass = myMainClass; }

Now you have access to test from your onDocumentOpen():
public void onDocumentOpen(...) {
 System.out.println(myMainClass.getTest());
}

=== 2nd solution (the one I prefer) ===

Class B has a variable test:
protected String test = "test";
and a corresponding getter and setter.
public void setTest(String test) { this.test = test; }
Of course you have access to the value of test from your events:
public String getTest() { return test; }public void onDocumentOpen(...) {
 System.out.println(getTest());
}

Class A has a variable of type B:
protected B myEvent;
myEvent = new B();
writer.setPageEvents(myEvent);
While you are doing stuff in A, you can change the value of test:
myEvent.setTest("changed");

===

It's as simple as that...
Please note that you have kept me from writing a page of my book 'iText in Action'.
Bruno


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to