Chandar S Vellithirumutha

Greenhorn
+ Follow
since May 29, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chandar S Vellithirumutha

Thanks for your help. I implemented with new Image and it worked.
Bill,
BTB I registered with new user name which complies with the Javaranch Standards
Chandar
Hi Milind
I haven't yet coded the client part yet. But i could not run rmi registry to keep the server process going. Can you please help me in this regard.
Thanks for your help
Chandar
23 years ago
Hi
i am trying to run a small rmi program. I am getting socket refused exception. Can any one help me in this. Here is the program.......

Thanks a bunch
Chandar
import java.util.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RMIMain extends Remote {
public int getRandomNumber() throws RemoteException;
}
import java.rmi.*;
import java.io.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class RemoteObject extends UnicastRemoteObject implements RMIMain {
Registry registry;
public RemoteObject() throws Exception {
setRMIRegistry();
}

public int getRandomNumber() {
return (int) (Math.random() * 100000) ;
}
public void setRMIRegistry() {
try {
registry = LocateRegistry.getRegistry(1099);
// registry.list();

if (registry == null) {
registry = LocateRegistry.createRegistry(1099);
}
registry.rebind("RMI",this);
}catch(Exception e) {
e.printStackTrace();
}
}
public void deleteRMIRegistry() {
try {
registry.unbind("RMI");
}catch(Exception e) {
e.printStackTrace();
}

}
public static void main(String args[]) throws Exception {

RemoteObject RObject = new RemoteObject();
}
}
23 years ago
Hi
I have a coded a simple chat server/chat client which is based on a frame with some Socket Connections. How do I put it in the Web through HTML code.
Your help is highly appreciated.
Thanks a bunch
Chandar
23 years ago
Hi
My application has a frame. With in the frame there is a list box. I have socket in the frame too. Basically i am reading the socket and removing the elements in the list box and creating new elements from the socket data. I am not able to see it immediately even though the code that adds the list elements is executed. How do I refresh the screen after updating the elements in the list box programmatically.
Appreciate your help....
Chandar
23 years ago
Pollai
This is the code I am writting in the run method of a chat i am trying to code. Please help me in this.
In this case my logic in the run method is to check whether data has to be written out to this socket(checking for null), if so I write it and after that I try reading the socket whether data is comming in. If there is no data comming in, then after writting the data it will be in a blocked state and i could not write data out to the socket if there are new message to be written after the first write. How can i resolve this.
Thanks in advance....
Chandar

Here is the code
public void run() {
int noOfAttempts = 0;
//Object to be serialized
private SObject readObj;
try {
while(socOpenFlag) {
//Sets the serialized object data
sObject.setData(dataToBeTxed);
try {
out.writeObject(sObject);
noOfAttempts = 0;
}catch(IOException e) {
e.printStackTrace();
noOfAttempts++;
}
//Discard the message after attempting 3 times
if (noOfAttemepts == 3) dataToBeTxed = null;

continue;
}

try {
readObj = (serObject) in.readObject();
}catch(IOException e) {
e.printStackTrace();
}

if (readObj != null) processReadObject(readObj);
}
}finally{
SocketCon.close();
}
}
While reading a stream from a socket, if there is no data comming in and if you are performing a readObject on the socket will it be in the blocked state or will it return null.
Thanks in advance....
I am using jswdk1.0.1. It is working when I connect to internet but not when i am offline even though the server is on. May i know for that please.
Thanks for your help bill
23 years ago
I am trying to find the hit counts using HttpSession object and i don't know why this code is not working.... Can any one help me in this....
Thanks a bunch
Chandar
x48588
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException, ServletException {

PrintWriter out = res.getWriter();

res.setContentType("text/html");

HttpSession session = req.getSession(true);

if (session.isNew()) {
synchronized(this) {
hitcounts++;
}
}
out.println("<html><title>Counts</title><body>");

out.println("<b>No. of visitors to the site = " +hitcounts + "</b>" );

}
23 years ago
Thanks frank. from where can i download the plugins. I have Internet Explorer.
23 years ago

I am trying to run an applet which should draw a graph with parameters it is passed with. When i run this with the help of applet viewer it works good. But when i try running it in a browser with the applet tag on it. It is giving a problem at setBounds method telling that java.awt.component nosuchmethod setBounds() at the bottom of the Browser at the status line.
Can any one help me in solving this problem.
Thanks a bunch
Chandar
The program is
import java.awt.*;
import java.applet.Applet;
/* <APPLET CODE=Graph width=1000 height=1000>
<param name=Hidden1 value="100000">
<param name=Hidden2 value="430000">
.....
<param name=Hidden2 value="430000">
<param name=Text1 value="Total Purchase Balance for jan 1998">
<param name=Text2 value="Total Purchase Balance for feb 1998">
....
<param name=Text12 value="Total Purchase Balance for dec 1998">
</applet> */
public class Graph extends Applet {
private String t[] = new String[100];
public double d[] = new double[100];
private int intD[] = new int[100];
public double bigElement,scaleFactor;
public int noOfElements;
private GraphCanvas drawArea;
public static final int CANVASXPOS = 20 ,CANVASYPOS = 20 , CANVASHEIGHT = 600, BARGRAPHWIDTH = 25;
public Color colorArray[] = {Color.yellow,Color.green,Color.blue,Color.cyan};
private void processParms() {
for (int i=0;i>=0;i++) {
String temp = getParameter("Hidden"+(i+1));
if (temp != null) {
try {
d[i] = Long.parseLong(temp);
}catch(Exception e) {
d[i] = 0;
}
bigElement = (d[i] > bigElement) ? d[i]:bigElement;
t[i] = getParameter("Text"+(i+1));
}
else {
noOfElements = i;
System.out.println(" No of Elements = " + noOfElements);
i = -10;
}
}
}
public void init() {
drawArea = new GraphCanvas();
drawArea.setBackground(Color.red);
drawArea.setBounds(CANVASXPOS,CANVASYPOS,GRAPHWIDTH,GRAPHHEIGHT);
add(drawArea);
processParms();
}
public void paint(Graphics g) {
super.paint(g);
setScale();
System.out.println("TEXT");
drawArea.storeApplet(this);
Graphics g1 = drawArea.getGraphics();
/*for (int i=0;i<noOfElements;i++) {
System.out.println("color = " + (i%colorArray.length) + " i = " + i);
g1.setColor(colorArray[i%colorArray.length]);
g1.fillRect(2*i*BARGRAPHWIDTH ,GRAPHHEIGHT - (int) (scaleFactor * d[i]),BARGRAPHWIDTH,(int)(scaleFactor * d[i]));
}*/
drawArea.paint(g1);
}
public void setScale() {
int i = 0;
while((bigElement = bigElement/Math.pow(10,i)) > Integer.MAX_VALUE) i++;
for (int x=0;x<noOfElements;x++) {
intD[x] =(int)(d[i] = d[i]/Math.pow(10,i));
}

scaleFactor = GRAPHHEIGHT / bigElement;
return;
}
}

The code for GraphCanvas is
import java.awt.*;
public class GraphCanvas extends Canvas {
Graph GraphApplet;
public void storeApplet(Graph x) {
GraphApplet = x;
}
public void paint(Graphics g){
for (int i=0;i<GraphApplet.noOfElements;i++) {
System.out.println("color = " + (i%GraphApplet.colorArray.length) + " i = " + i);
g.setColor(GraphApplet.colorArray[i%GraphApplet.colorArray.length]);
g.fillRect(2*i*GraphApplet.BARGRAPHWIDTH ,GraphApplet.GRAPHHEIGHT - (int) (GraphApplet.scaleFactor * GraphApplet.d[i]),GraphApplet.BARGRAPHWIDTH,(int)(GraphApplet.scaleFactor * GraphApplet.d[i]));
}
}
}








23 years ago
I am trying run an applet with the paint method as below. The paint method gets called in an infinite loop. CAn any one help me.
Thanks
Chandar
public void paint(Graphics g) {
setScale();
Graphics g1 = drawArea.getGraphics();
for (int i=0;i<noOfElements;i++) {setForeground(colorArray[i%colorArray.length]);
g.fillRect(i*BARGRAPHWIDTH,GRAPHHEIGHT - (int)
(scaleFactor * d[i]),BARGRAPHWIDTH,(int)(scaleFactor * d[i]));
}
}
public void setScale() {
int i = 0;
while((bigElement = bigElement/Math.pow(10,i)) > Integer.MAX_VALUE) i++;
for (int x=0;x<noOfElements;x++) {
intD[x] =(int)(d[i] = d[i]/Math.pow(10,i));
}

scaleFactor = GRAPHHEIGHT / bigElement;
return;
}
23 years ago
Thanks Frank. You the man.....
23 years ago
Can any one help me in telling the ways to serialize an applet after creating & painting(drawing graph) the applet. The applet will be passed with parameters with which it has to draw a graph and need to send it as a response.
I am trying to pass some parameter from an HTML which will call a servlet, which needs to send an applet that should be the bar graph of the parameters that i have sent.
(ie) i need to call a servlet xyz with parameter lets say a1=10,a2=20,a3=30..... like
http://127.0.0.1:8080/examples/servlet/graph?a1=10&a2=20&a3=3....
I have the following methods in the applet
class xyzApplet extends Applet {
int parms[];
public void setParameter(int a[]){
parms = a;
}
public void DrawGraph() {
//take the values of parms[] and draw graph
}
}
I am doing the following piece of code in the doGet of servlet
{
int d[];
d[0] = req.getParameter("Graph1");
.
......
xyzApplet x= new xyzApplet();
x.setParameter(d);
x.paint(x.getGraphics());
...
}

How do I serialize the painted applet from the servlet. Can any one help me? If you could not understand the question please let me know.
Thanks a bunch
Chandar
23 years ago
Here is my code for connecting to Personal Oracle 8.0.3.0.0. The program compiles well and when i tried running this program i am getting the following exception. (I have downloaded the Oracle driver and set apppriate classpath.)
java.sql.SQLException The network Adapter could not establish connection.
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.OracleConnection.<init>(OracleConnection.java:210)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver java:251)
at oracle.jdbc.driver.OracleDriver.Connect(OracleDriver java:224)
at oracle.jdbc.driver.OracleDriver.getConnection(DriverManager java:457)
at oracle.jdbc.driver.OracleDriver.getConnection(DriverManager java:137)
at DBConnection.main(DBConnection.java,Compiled Code)

Can any one help me.
:confused
Thanks a bunch
Chandar
import java.io.*;
import java.sql.*;
public class DBConnection {
public static void main(String args[]) {
Connection con = null;
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// DriverManager.registerDriver(
// new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc racle:thin:@:1521:","scott","tiger");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SElect username from registry");
while (rs.next()) {
System.out.println("name - " + rs.getString("username"));
}
}catch(ClassNotFoundException e)
{System.out.println("CLASSNOT FOUND");
e.printStackTrace();
}
catch(SQLException e)
{System.out.println("SQLException ");
e.printStackTrace();
}
catch(Exception e)
{System.out.println("Exception ");
e.printStackTrace();
}
finally{
if (con!=null)
try {
con.close();
}catch(Exception e) {
System.out.println("Exception @ close");
e.printStackTrace();
}
}
}
}