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

Problem deploying applet

0 views
Skip to first unread message

chye_t...@yahoo.com

unread,
Dec 21, 2000, 3:09:59 AM12/21/00
to
Hi,

I'm try to run Java 1.2.2 Swing Applet with RMI on Netscape 4.7 and
IE5.5 but failed. It is OK is I run it using appletviewer. Currently
I'm using Win2000. What is wrong with my environment.

Thank,
Teong Wah

Exception stack from java console:-
Java(TM) Plug-in: Version 1.3.0-C

Using JRE version 1.3.0 Java HotSpot(TM) Client VM

User home directory = C:\Documents and Settings\administrator

----
my applet code:-
package examples.hello;

import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JScrollBar;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.rmi.*;
import java.io.*;
import java.text.*;
import java.lang.*;
import java.util.Vector;

public class HelloApplet extends JApplet {

private boolean STOP = false;
private final int NO_OF_COLUMN = 12;
public static Object[][] objData = new Object [1][12];
private String[] columnNames =
{"Name", "Code", "P.Close", "Last", "Chg", "High", "Low", "B.Qty", "B.Pr
ice", "S.Qty", "S.Price", "Volume"};
private JTable table;
Hello obj;
Vector vDataElement = new Vector();
private int giIndex = 0;
private int giRowSize = 0;
static Thread appletThread = null;

//constructor
public HelloApplet()
{
try{
if(appletThread == null)
{
//create thread
appletThread = new Thread((Runnable)
new AppletThread());
appletThread.start();
}
}//end try
catch(Exception ex){
//cannot create thread
objData = new Object [1][NO_OF_COLUMN];
objData[0][0] = ex.getMessage();
}//end catch
}

public void init() {
try {
obj = (Hello)Naming.lookup("//"+getCodeBase
().getHost() + "/test");
System.out.println("HelloApplet : "+getCodeBase
().getHost());
vDataElement = obj.sayHello();
putValue(vDataElement);

//start init JTable
JLabel label = new JLabel("Using JTable");

table = new JTable(objData, columnNames);
table.setPreferredScrollableViewportSize(new Dimension
(700, 70));
table.setGridColor(Color.black);
table.setSelectionBackground(Color.yellow);
table.setBackground(Color.lightGray);
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);

//add mouse listner on the table header
final JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
header.setResizingAllowed(false);
header.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
// find which header cell was hit
TableColumnModel columnModel =
header.getColumnModel();
giIndex = columnModel.getColumnIndexAtX
(e.getX());
if(giIndex == 0 || giIndex == 1)
IndexTable(giIndex, true);
else if(giIndex >= 2 && giIndex <
NO_OF_COLUMN)
IndexTable(giIndex);
}
});//end header.addMouseListener

//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);

//Add the scroll pane to this window.
getContentPane().add(scrollPane, BorderLayout.CENTER);

}//end try

catch (Exception e) {
System.out.println("HelloApplet
exception: "+e.getMessage());
e.printStackTrace();
}
}//end init

public void start()
{
STOP = false;
}//end start

public void stop()
{
try{
if(appletThread != null)
{
STOP = true;
Thread.sleep(1000);
}
}//end try
catch(Exception ex){}
appletThread = null;
}//end stop

public void destroy()
{
try{
if(appletThread != null)
{
STOP = true;
Thread.sleep(1000);
}
}//end try
catch(Exception ex){}
appletThread = null;
}//end destroy

public void UpdateTable()
{
try{
if(giIndex == 0 || giIndex == 1)
IndexTable(giIndex, true);
else if(giIndex >= 2 && giIndex < NO_OF_COLUMN)
IndexTable(giIndex);

((AbstractTableModel)table.getModel
()).fireTableDataChanged();

Thread.sleep(5000);//make thread sleep for 5
seconds
}//end try
catch(Exception ex){}//end catch

}//end UpdateTable

private void putValue(Vector vData)
{
String message = null;
String sData = null;
int OutCount = 0;
int InCount = 0;
int iPost;
int iPrevRowSize = 0;

try
{
iPrevRowSize = giRowSize;
giRowSize = vData.size();
if(giRowSize > iPrevRowSize && giRowSize > 0)
objData = new Object[giRowSize]
[NO_OF_COLUMN];

//break the vector to feed into objData
for(int i=0; i<vData.size(); i++)
{
message = (String)vData.elementAt(i);
iPost = message.indexOf(124);//looking
for '|'
if(iPost > 0)
{
while(iPost > 0 || InCount <
NO_OF_COLUMN)
{
sData =
message.substring(0, iPost);
message =
message.substring(iPost+1, message.length());
//if there is changes,
then make changes on the display data
if(sData.compareTo
(String.valueOf(objData[i][InCount])) != 0)
objData[i]
[InCount] = sData;
InCount++;
iPost = message.indexOf
(124);
}//end while
InCount = 0;
}//end if
}//end for
}//end try

catch(Exception ex){}

}//end putValue

private void IndexTable(int index, boolean bIsStr)
{
int i=0;
int k=0;
String sCompare = null;
String sStkShtName = null;
String sStkCode = null;
String sClsPrice = null;
String sLstDonePrice = null;
String sChgPrice = null;
String sHighPrice = null;
String sLowPrice = null;
String sBestBuyQty = null;
String sBestBuyPrice = null;
String sBestSellQty = null;
String sBestSellPrice = null;
String sTradedVol = null;

//perform insertion sort
try
{
if(index == 0 || index == 1)
{
for(k = 1; k < objData.length; k++)
{
sStkShtName = objData[k]
[0].toString();
sStkCode = objData[k]
[1].toString();
sClsPrice = objData[k]
[2].toString();
sLstDonePrice = objData[k]
[3].toString();
sChgPrice = objData[k]
[4].toString();
sHighPrice = objData[k]
[5].toString();
sLowPrice = objData[k]
[6].toString();
sBestBuyQty = objData[k]
[7].toString();
sBestBuyPrice = objData[k]
[8].toString();
sBestSellQty = objData[k]
[9].toString();
sBestSellPrice = objData[k]
[10].toString();
sTradedVol = objData[k]
[11].toString();

//string to be compare based on
the index=0
sCompare = objData[k]
[index].toString();

for(i=k-1; i>=0 &&
sCompare.compareTo(objData[i][index].toString())<0; i--)
{
objData[i+1][0] =
objData[i][0];
objData[i+1][1] =
objData[i][1];
objData[i+1][2] =
objData[i][2];
objData[i+1][3] =
objData[i][3];
objData[i+1][4] =
objData[i][4];
objData[i+1][5] =
objData[i][5];
objData[i+1][6] =
objData[i][6];
objData[i+1][7] =
objData[i][7];
objData[i+1][8] =
objData[i][8];
objData[i+1][9] =
objData[i][9];
objData[i+1][10] =
objData[i][10];
objData[i+1][11] =
objData[i][11];
}//end for
objData[i+1][0] = sStkShtName;
objData[i+1][1] = sStkCode;
objData[i+1][2] = sClsPrice;
objData[i+1][3] = sLstDonePrice;
objData[i+1][4] = sChgPrice;
objData[i+1][5] = sHighPrice;
objData[i+1][6] = sLowPrice;
objData[i+1][7] = sBestBuyQty;
objData[i+1][8] = sBestBuyPrice;
objData[i+1][9] = sBestSellQty;
objData[i+1][10] =
sBestSellPrice;
objData[i+1][11] = sTradedVol;
}//end for
}//end if
}//end try

catch(Exception ex){}

}//end IndexTable

private void IndexTable(int index)
{
int i=0;
int k=0;
double dCompare = 0;
String sStkShtName = null;
String sStkCode = null;
String sClsPrice = null;
String sLstDonePrice = null;
String sChgPrice = null;
String sHighPrice = null;
String sLowPrice = null;
String sBestBuyQty = null;
String sBestBuyPrice = null;
String sBestSellQty = null;
String sBestSellPrice = null;
String sTradedVol = null;

//perform insertion sort
try
{
if(index >= 2 && index <= 11)
{
for(k = 1; k < objData.length; k++)
{
sStkShtName = objData[k]
[0].toString();
sStkCode = objData[k]
[1].toString();
sClsPrice = objData[k]
[2].toString();
sLstDonePrice = objData[k]
[3].toString();
sChgPrice = objData[k]
[4].toString();
sHighPrice = objData[k]
[5].toString();
sLowPrice = objData[k]
[6].toString();
sBestBuyQty = objData[k]
[7].toString();
sBestBuyPrice = objData[k]
[8].toString();
sBestSellQty = objData[k]
[9].toString();
sBestSellPrice = objData[k]
[10].toString();
sTradedVol = objData[k]
[11].toString();

//string to be compare based on
the index=0
dCompare = Double.valueOf
(objData[k][index].toString()).doubleValue();

for(i=k-1; i>=0 &&
dCompare<Double.valueOf(objData[i][index].toString()).doubleValue(); i--
)
{
objData[i+1][0] =
objData[i][0];
objData[i+1][1] =
objData[i][1];
objData[i+1][2] =
objData[i][2];
objData[i+1][3] =
objData[i][3];
objData[i+1][4] =
objData[i][4];
objData[i+1][5] =
objData[i][5];
objData[i+1][6] =
objData[i][6];
objData[i+1][7] =
objData[i][7];
objData[i+1][8] =
objData[i][8];
objData[i+1][9] =
objData[i][9];
objData[i+1][10] =
objData[i][10];
objData[i+1][11] =
objData[i][11];
}//end for
objData[i+1][0] = sStkShtName;
objData[i+1][1] = sStkCode;
objData[i+1][2] = sClsPrice;
objData[i+1][3] = sLstDonePrice;
objData[i+1][4] = sChgPrice;
objData[i+1][5] = sHighPrice;
objData[i+1][6] = sLowPrice;
objData[i+1][7] = sBestBuyQty;
objData[i+1][8] = sBestBuyPrice;
objData[i+1][9] = sBestSellQty;
objData[i+1][10] =
sBestSellPrice;
objData[i+1][11] = sTradedVol;
}//end for
}//end if
}//end try

catch(Exception ex){}

}//end IndexTable

//---- start class AppletThread -----
class AppletThread implements Runnable
{
public void run()
{
try{
while(STOP == false)
{
init();
UpdateTable();
}//end while
}//end try

catch(Exception ex){
}//end catch
}//end run

}//end class AppletThread
}

--
package examples.hello;

import java.io.*;
import java.text.*;
import java.lang.*;
import java.util.Vector;

public interface Hello extends java.rmi.Remote {
//String sayHello() throws java.rmi.RemoteException;
Vector sayHello() throws java.rmi.RemoteException;
}

--
package examples.hello;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;
import java.text.*;
import java.lang.*;
import java.util.Vector;
import java.sql.*;

public class HelloImpl
extends UnicastRemoteObject
implements Hello
{
private final String STR_SEPERATOR = "|";
private String name;

public HelloImpl(String s) throws RemoteException {
super();
name = s;
}

//public String sayHello() throws RemoteException {
// return "Hello World!";
public Vector sayHello() throws RemoteException {
Vector vData = new Vector();
//String url
= "jdbc:odbc:cartoon;UID=administrator;PWD=PASSWORD";
String url = "jdbc:odbc:stock_detail";
String query = "SELECT * FROM stock_quotes";

try
{
Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
}

catch(Exception ex)
{
vData.addElement(ex.getMessage());
ex.printStackTrace();
return vData;
}

try
{
System.out.println("querying!!!!");
Connection con = DriverManager.getConnection
(url, "administrator", "PASSWORD");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

while (rs.next())
{
String text1 = null;
String text2 = rs.getString
("stq_stock_code");
String text3 = rs.getBigDecimal
(3,3).toString();//stq_price_prv_day_close
String text6 = rs.getBigDecimal
(5,3).toString();//stq_price_high
String text7 = rs.getBigDecimal
(6,3).toString();//stq_price_low
String text4 = rs.getBigDecimal
(7,3).toString();//stq_price_last_done
String text9 = rs.getBigDecimal
(8,3).toString();//stq_price_best_buy
String text11 = rs.getBigDecimal
(11,3).toString();//stq_price_best_sell
String text8 = rs.getBigDecimal
(14,3).toString();//stq_qty_best_buy
String text10 = rs.getBigDecimal
(17,3).toString();//stq_qty_best_sell
String text12 = rs.getBigDecimal
(26,3).toString();//stq_norm_lot_traded_vol
//stq_price_last_done-stq_price_high
String text5 = String.valueOf
(Float.valueOf(text4).floatValue()-Float.valueOf(text6).floatValue
());//here

//result from stock_counter_info
String queryInfo = "SELECT * FROM
stock_counter_info WHERE sci_stock_code = "

+ "'" + text2 + "'";
try{
boolean found = false;
Connection con2 =
DriverManager.getConnection(url, "administrator", "PASSWORD");
Statement stmt2 =
con2.createStatement();
ResultSet rs2 =
stmt2.executeQuery(queryInfo);
found = rs2.next();
if(found)
{
text1 = rs2.getString
("sci_stock_short_name");
}
else
{
text1 = null;
}
stmt2.close();
con2.close();
}
catch(SQLException ex){
vData.addElement(ex.getMessage
());
ex.printStackTrace();
return vData;
}

String results = text1 + STR_SEPERATOR
+ text2 + STR_SEPERATOR +
text3
+ STR_SEPERATOR + text4 + STR_SEPERATOR +
text5
+ STR_SEPERATOR + text6 + STR_SEPERATOR +
text7
+ STR_SEPERATOR + text8 + STR_SEPERATOR +
text9
+ STR_SEPERATOR + text10 + STR_SEPERATOR +
text11
+ STR_SEPERATOR + text12 + STR_SEPERATOR;
vData.addElement(results);
}

stmt.close();
con.close();
return vData;
}

catch(SQLException ex)
{
vData.addElement(ex.getMessage());
ex.printStackTrace();
return vData;
}

}

public static void main(String args[])
{
// Create and install a security manager
System.setSecurityManager(new RMISecurityManager());

try {
HelloImpl obj = new HelloImpl("test");
Naming.rebind("//localhost/test", obj);
System.out.println("HelloServer bound in
registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " +
e.getMessage());
e.printStackTrace();
}
}
}

Proxy Configuration: no proxy

JAR cache enabled.

java.security.AccessControlException: access denied
(java.lang.RuntimePermission modifyThreadGroup)

at java.security.AccessControlContext.checkPermission(Unknown
Source)

at java.security.AccessController.checkPermission(Unknown
Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at sun.applet.AppletSecurity.checkAccess(Unknown Source)

at java.lang.ThreadGroup.checkAccess(Unknown Source)

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

at java.lang.Thread.<init>(Unknown Source)

at javax.swing.TimerQueue.start(Unknown Source)

at javax.swing.TimerQueue.<init>(Unknown Source)

at javax.swing.TimerQueue.sharedInstance(Unknown Source)

at javax.swing.JApplet.<init>(Unknown Source)

at examples.hello.HelloApplet.<init>(HelloApplet.java:33)

at java.lang.Class.newInstance0(Native Method)

at java.lang.Class.newInstance(Unknown Source)

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

at sun.plugin.AppletViewer.createApplet(Unknown Source)

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

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

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


Sent via Deja.com
http://www.deja.com/

0 new messages