Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

use JDialog

0 views
Skip to first unread message

Terrence Mak

unread,
Dec 12, 2001, 11:29:28 AM12/12/01
to
Hi,

I tried to write a simple inference engine, with dialogs will pop up
to get user input.
I make it successfully when use JFrame, and add the JDialog to the
JFrame, how ever, things went wrong when I try to put it on the internet.
I change inherence from JFrame to JApplet, and I can view the applet
correctly in the appletviewer. However, when I open the html file in the
browser. The Applet is successfully loaded, BUT the dialog didn't
work......I can't show a dialog box appear in the applet.
Can anyone teach me how to make it work??

Thanks
Terrence


Paul Lutus

unread,
Dec 12, 2001, 12:58:34 PM12/12/01
to
"Terrence Mak" <st...@cuhk.edu.hk> wrote in message
news:9v80f8$9v6$1...@eng-ser1.erg.cuhk.edu.hk...

> Hi,
>
> I tried to write a simple inference engine, with dialogs will pop
up
> to get user input.
> I make it successfully when use JFrame, and add the JDialog to the
> JFrame, how ever, things went wrong when I try to put it on the internet.
> I change inherence from JFrame to JApplet, and I can view the
applet
> correctly in the appletviewer. However, when I open the html file in the
> browser. The Applet is successfully loaded, BUT the dialog didn't
> work......I can't show a dialog box appear in the applet.

Why not? What happens? What compiler or runtime error messages did you see?
What appears in the browser's Java console window?

--
Paul Lutus
www.arachnoid.com


wp

unread,
Dec 12, 2001, 4:58:20 PM12/12/01
to
It is not possible to add a JDialog to a JFrame since both are 'top level
containers'. In the case of an applet I think you should use another JFrame,
not a JDialog.

"Terrence Mak" <st...@cuhk.edu.hk> wrote in message
news:9v80f8$9v6$1...@eng-ser1.erg.cuhk.edu.hk...

Paul Lutus

unread,
Dec 12, 2001, 6:23:43 PM12/12/01
to
"wp" <wpl...@aon.at> wrote in message
news:3c17d2fc$0$18024$5039...@newsreader01.highway.telekom.at...

> It is not possible to add a JDialog to a JFrame since both are 'top level
> containers'. In the case of an applet I think you should use another
JFrame,
> not a JDialog.

It is not a question of "adding a JDialog to a JFrame." It is a question of
launching a JDialog from an applet. It can be done, after a fashion.

--
Paul Lutus
www.arachnoid.com


Terrence Mak

unread,
Dec 12, 2001, 10:50:32 PM12/12/01
to
Thanks

Now I 've try to commented the part related to the dialog, but even the
applet
can't load a text file from the same directory as the applet. In the console
it show
java.lang.NullPointerException

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Can I read file through an applet which with the same directory as the text
file?
If so, how can I do it??

Thanks
Terrence
"Paul Lutus" <nos...@nosite.zzz> 撰寫於郵件新聞
:eVMR7.77437$C8.47...@bin4.nnrp.aus1.giganews.com...

Paul Lutus

unread,
Dec 12, 2001, 11:27:46 PM12/12/01
to
"Terrence Mak" <st...@cuhk.edu.hk> wrote in message
news:9v98c7$197$1...@eng-ser1.erg.cuhk.edu.hk...

> Thanks
>
> Now I 've try to commented the part related to the dialog, but even
the
> applet
> can't load a text file from the same directory as the applet.

What? You asked whether you could use JDialog from an applet. The answer is
yes. Now you appear to have moved on to a different subject. If you have a
problem reading a file, then post your code.

> Can I read file through an applet which with the same directory as the
text
> file?
> If so, how can I do it??

You normally do this by writing a computer program. Please post your code,
because this conversation will solve nothing. You can say, "I cannot read a
file," but that is not true. Therefore the problem is not the inability to
read a file, but your code, the code you did not post.

One more thing. Did I remember to mention that you need to post your code?

--
Paul Lutus
www.arachnoid.com


Terrence Mak

unread,
Dec 13, 2001, 4:41:56 AM12/13/01
to
Here is my code, hope it's not too long.

public class ChainApplet extends Applet{

TextArea outputArea;
//JScrollPane scroll=new JScrollPane(outputArea);
Panel jp;
TextField input;
Button btForward, btBackward;
LinkedList IfPart, ThenPart;
InfEngine inference;

public void init(){
outputArea=new TextArea("", 30,40,TextArea.SCROLLBARS_BOTH);
jp=new Panel(new FlowLayout());
input=new TextField(30);
btForward=new Button("Forward Chaining");
btBackward=new Button("Backward Chaining");
IfPart=new LinkedList();
ThenPart=new LinkedList();
}
public void start(){

this.setSize(500,500);

jp.add(input);


this.add(jp, BorderLayout.SOUTH);
this.add(outputArea);
this.setVisible(true);


//read datafile the rule base into the ifPart and thenPart linkedlist
RandomFileReader readFile = new RandomFileReader();

readFile.readFile(outputArea, "test.txt" , IfPart, ThenPart);
}


class RandomFileReader {

byte[] b=new byte[8];
LinkedList premise;
//String tempLine;
public void readFile(TextArea outputArea, String fileName, LinkedList
ifPart, LinkedList thenPart){


try{

StreamTokenizer stoken=new StreamTokenizer(new FileReader(fileName));
stoken.eolIsSignificant(true);
stoken.parseNumbers();
stoken.wordChars(60,62);
stoken.slashSlashComments(true);
stoken.slashStarComments(true);
Variable var=new Variable();
boolean isThenPart=false, isPremiseUpdated=false;

while(true){
stoken.nextToken();
if(stoken.ttype==StreamTokenizer.TT_EOF)
break;
else if(stoken.ttype==StreamTokenizer.TT_EOL)
{

if(isPremiseUpdated==true){
ifPart.add(premise);
outputArea.append(" --------Insert If Part Database----------- \n");
isPremiseUpdated=false;
}
else if(isThenPart==true){
outputArea.append(" --------Insert Conclusion----------- \n");
thenPart.add(var);
isPremiseUpdated=true;
isThenPart=false;
}
else
{
premise.add(var);
outputArea.append(stoken.lineno() +"---------Insert Premise---------
\n");
isPremiseUpdated=true;
}

}
else if(stoken.ttype==StreamTokenizer.TT_NUMBER){
//load the value
outputArea.append("Number here: "+stoken.nval +"\n");
var.setValue((float)stoken.nval);
outputArea.append("Value here"+var.getValue()+"\n");
}
else if(stoken.ttype==StreamTokenizer.TT_WORD)
{
//If Part
if((stoken.sval).equals("IF")){
outputArea.append("What a fucking IF!! \n");
isThenPart=false;
premise=new LinkedList();
var=new Variable();
}
else if((stoken.sval).equals("AND")){
outputArea.append("What a fucking AND!! \n");
var=new Variable();
isPremiseUpdated=false;
}

//Then Part
else if((stoken.sval).equals("THEN")){
outputArea.append("What a fucking THEN!! \n");
isThenPart=true;
var=new Variable();
}
else
if(((stoken.sval).equals(">"))||((stoken.sval).equals(">="))||((stoken.sval)
.equals("<"))||((stoken.sval).equals("<="))||((stoken.sval).equals("=")))
{
//load the <
outputArea.append("What a fucking Comparator \n");
var.setComparator(stoken.sval);
outputArea.append("variable here"+var.getComparator()+"\n");
}
else
{
//load the Name
outputArea.append("Word here: "+stoken.sval+"\n");
var.setName(stoken.sval);
outputArea.append("Name here"+var.getName()+"\n");
isPremiseUpdated=false;
}
}
else if(stoken.sval!=null)
outputArea.append("Conditions : "+stoken.sval+"\n");


}
}
catch(Exception e){
outputArea.append("cannot read");
}
}
}


Thanks
Terrence


Paul Lutus

unread,
Dec 13, 2001, 1:13:38 PM12/13/01
to
"Terrence Mak" <st...@cuhk.edu.hk> wrote in message
news:9v9sv3$dps$1...@eng-ser1.erg.cuhk.edu.hk...

> Here is my code, hope it's not too long.

Please:

1. Tell us what you hoped your program would do.

2. Tell us what it did instead.

3. Tell us how (2) differs from (1).

Include all compiler and runtime error messages, with the original text, and
the line numbers to which they refer.

If you cannot do this, then use standard debugging methods using your own
IDE to locate the problem.

--
Paul Lutus
www.arachnoid.com


0 new messages