The Artima Developer Community
Sponsored Link

Java Answers Forum
Applet does not work.Why???

4 replies on 1 page. Most recent reply: Jul 24, 2002 1:56 AM by Joey

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
DAYO

Posts: 22
Nickname: done
Registered: Jun, 2002

Applet does not work.Why??? Posted: Jul 11, 2002 9:27 PM
Reply to this message Reply
Advertisement
I have written an applet program but it does not work.
I get a blank page.
Is there anything else i have to set/change .
I have installed java plug-in and jdk
in the same folder(called myjava).
The two files(LPCTEST.html and testing4.java)
are also in myjava.And ordinary applications are
running fine.

HTML CODE:
<html> <title>LPC
</title> <!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<OBJECT classid="clsid:E19F9331-3110-11d4-991C-005004D3B3DB"
WIDTH = 400 HEIGHT = 110 codebase="http://java.sun.com/products/plugin/1.3.0_02/jinstall-130_02-win32.ca b#Version=1,3,0,2">
<PARAM NAME = CODE VALUE = "testing4.class" >
<PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.3.0_02">
<PARAM NAME="scriptable" VALUE="false">
<COMMENT>
<EMBED type="application/x-java-applet;jpi-version=1.3.0_02" CODE = "testing4.class" WIDTH = 400 HEIGHT = 110 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3.0_02/plugin-install.html"& gt;<NOEMBED></NOEMBED>
</EMBED>
</COMMENT>
</OBJECT&g t;
<!--
<APPLET CODE = "testing4.class" WIDTH = 400 HEIGHT = 110>
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
</html> ;

APPLET CODE

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
//import java.lang.Object;
public class testing4 extends JApplet
{ private JTextArea display;
private JScrollPane scrollPane2;
private JButton paste;
private JPanel P2;
private File fileName;
public void init()
{ paste=new JButton("paste");
paste.setMinimumSize(new Dimension(90,20));
paste.setPreferredSize(new Dimension(90,20));
paste.setMaximumSize(new Dimension(90,20));
copyhandler pa=new copyhandler();
paste.addActionListener(pa);
display=new JTextArea();
scrollPane2=new JScrollPane(display);
scrollPane2.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane2.setMinimumSize(new Dimension(200,58));
scrollPane2.setPreferredSize(new Dimension(200,58));
scrollPane2.setMaximumSize(new Dimension(200,58));
P2=new JPanel();
P2.setMinimumSize(new Dimension(200,80)); P2.setPreferredSize(new Dimension(200,80)); P2.setMaximumSize(new Dimension(200,80)); P2.setLayout(new BoxLayout(P2,BoxLayout.Y_AXIS)); scrollPane2.setAlignmentX (Component.LEFT_ALIGNMENT);
P2.add(scrollPane2);
paste.setAlignmentX(Component.LEFT_ALIGNMENT);
P2.add(paste);
Container c=getContentPane();
c.add(P2);
}
//COPIES TEXT FROM FILE ON MY DISK TO THE TEXTAREA
private class copyhandler implements ActionListener
{ public void actionPerformed(ActionEvent event)
{ JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY );
int result = fileChooser.showOpenDialog(testing4.this);
// user clicked Cancel button on dialog if ( result == JFileChooser.CANCEL_OPTION ) return;
fileName = fileChooser.getSelectedFile();

if ( fileName == null || fileName.getName().equals( "" ) ) JOptionPane.showMessageDialog( null,"Invalid File Name", "Invalid File Name", JOptionPane.ERROR_MESSAGE );
else
{ try
{ FileReader in = new FileReader(fileName);
BufferedReader reading= new BufferedReader(in);
String store="";
while (reading.ready())
{ StringTokenizer st = new StringTokenizer(reading.readLine());
store=store+st.nextToken()+"\n";
} display.setText(store);
}
catch ( IOException e )
{ JOptionPane.showMessageDialog( null, "Error Opening File", "Error", JOptionPane.ERROR_MESSAGE );
}
}
}
}
public static void main (String [] args)

{ testing4 done =new testing4();
//you did not set applet's width and height:
//applet is a container too
done.setWidth(205);
done.setHeight(110);
JFrame frame = new JFrame("testing");
frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } );
done.init();
frame.getContentPane().add(done);
frame.pack();
frame.setSize(205,110);
frame.setVisible(true);
}
}


Trung

Posts: 9
Nickname: chitrung
Registered: Jun, 2002

Re: Applet does not work.Why??? Posted: Jul 12, 2002 5:26 AM
Reply to this message Reply
hi,
may be there are more bugs, but one thing why it doesnt work is that you want to load a file from your harddisk. applets dont have the permission the read or write files to the harddisk until they are signed.
go to the java homepage to read more about signed applets.

regards,
trung

DAYO

Posts: 22
Nickname: done
Registered: Jun, 2002

Re: Applet does not work.Why??? Posted: Jul 12, 2002 6:38 PM
Reply to this message Reply
I am afraid that's not the case.
I've tried an example from a textbook which does not
read/write from/to harddisk and it still does'nt work

Joey

Posts: 12
Nickname: joey
Registered: Jul, 2002

Re: Applet does not work.Why??? Posted: Jul 24, 2002 1:35 AM
Reply to this message Reply
I think the best thing you could do is first download a javacompiler like JBuilder, where you can compile and see if the applet works there.

Joey

Posts: 12
Nickname: joey
Registered: Jul, 2002

Re: Applet does not work.Why??? Posted: Jul 24, 2002 1:56 AM
Reply to this message Reply
What I was trying to say, run it in a console window
djees...to early for me

Flat View: This topic has 4 replies on 1 page
Topic: Making small program w/ filter... filters dont work. Help? Previous Topic   Next Topic Topic: Making small program w/ filter... filters dont work. Help?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use