Suma MM

Ranch Hand
+ Follow
since Apr 30, 2001
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 Suma MM

Thank You Axel. Will check out the links.
-S
20 years ago
Hello!
I wanted to execute a simple servlet which extends HttpServlet. The compiler is unable to find the package javax! (I know i've messed something badly).
Ok now, I have downloaded jdk1.3.1_02. I dont see javax package anywhere. Need i download something else in order to "get" the javax package? And if so, how should the path and classpath variables be set?
I am a newbie to servlets. And moreover, i did try to "search" for an answer from the previously asked questions on this forum..but failed to!
I wud appreciate any help.
Thanks in advance.
-S
20 years ago
HTML FILE:
----------------------------------------------------------------
< html >
< applet code=A.class height=400 width=800>
< /applet>
< /body>< /html>
-----------------------------------------------------------------

SOURCE CODE:
-----------------------------------------------------------------import java.awt.*;
import javax.swing.*;
public class A extends JApplet
{
JPanel myPanel;
Container c;
public void init()
{
myPanel = new JPanel();
c = getContentPane();
c.add(myPanel);
}
public void paint(Graphics g)
{
g.drawRect(50,50,400,100);
}
}
-----------------------------------------------------------------
I don't understand why u would want to draw a shape on a panel because even without a panel, u would be getting the same output; the reason being that both JApplet and JPanel inherit (directly/indirectly) from the class "Container".
[This message has been edited by Suma MM (edited August 12, 2001).]
[This message has been edited by Suma MM (edited August 12, 2001).]
20 years ago
I just need store the objects in a file and will not be reading back the objects. Anyway, I could get the thing done using the following code:
------------------------------------------------------------------
FileWriter f = new FileWriter("AfterTrans.init",true);
BufferedWriter out = new BufferedWriter(f);
//File f = new File("AfterTrans.init");
//ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(f));
Account accobj;
String s = "";
for (int sz = 0; sz < AccountList.size(); sz++)
{
accobj = (Account)(AccountList.elementAt(sz));
s = s + accobj.toString() + "\n";
//output.writeObject(accobj);
}
out.write(s,0,s.length());
out.close();
out.flush();
---------------------------------------------------------------
As such, I did know that a Writer object or one of its sub-class' objects would be able to do this; but wanted to use ObjectOutputStream just to get out of the mind-block; but ended up 'strengthening' that block!! :-)
Thanks for the help anyway!
-K
20 years ago
Thanks Chad! That is what even i see........We can't use ObjectOutputStream alone (i.e. without chaining it to another stream object) in order to get a "textual" output, i guess...
-K
20 years ago
Thanks Larry for the reply!
Exactly!!! Thatz what the junk is looking like! I didn't try reading back the 'junk' into an object...I will try it. But that will not be solving my problem because the requirement is that the output of the program should be a list of accounts in a 'readable' format, in a physical file.
Thanks once again for the info.
-K
20 years ago
Thank You Michael for the reply. I did figure out the problem using printStackTrace(). Actually, the 'Account' class had, as one of its data members, an object of a different class 'ProductMatrix'. I didn't know even that class i.e. the 'Product Matrix' class needs implement the interface Serializable for the object of 'Account' class to be serialized properly.
But now, I am having some other problem with the code. Now no exception is thrown; but instead of the details of the 'Account' class objects, some junk (absolute junk rather!) is being written to the file "AfterTrans.init". Is there some other condition I need check in order that the objects are 'serialized properly'?! Is the code missing something very basic??
Thanks!
-K
20 years ago
Hi!
I 'm trying to use an ObjectOutputStream object to output some objects to a file named "AfterTrans.init". The code below is the one I am using. For some reason, IO exception is being caught. By the way, 'Account' is a class defined by myself and 'AccountList' is a vector of 'Account' objects. Also, the class 'Account' implements Serializable and I have imported the class java.io.Serializable. Is the problem arising because I am NOT creating a 'Account' object using 'new' operator?! If thatz the case, doesn't make any sense to me because "re"-creating the existing objects just to output them to a file is so very redundant!

Any help will be appreciated! Thanks!!
-K
(edited by Cindy to format code)

[This message has been edited by Cindy Glass (edited August 07, 2001).]
20 years ago
Thanks a lot! once again!!
20 years ago
Thanks Nathan!
20 years ago
Hi!
Is there a way I can add an 'image' object to a container in an application? (not an applet)......
For ex., when i say:
Container c = getContentPane();
c.add (img1); //img1 is an image object
Error is generated. Can somebody suggest an alternative?
As such, in my application, I need display images along with a button for each of the image....I am not able to figure out how to do this.
Thanks for any help
-S
20 years ago
Thanks Nathan!
I did figure out the problem when I tried to print out the height and width of the image. They got printed as -1, -1! So, I figured out that there was something wrong with the loading of the image and so made the same change u had suggested. The code worked fine.
One question on the same topic.....If I am loading more than 1 image, do I assign separate IDs to each of the image and wait for each of them to load in a "sequential" way??
Thanks once again
-S
20 years ago
Hi!
I am trying to 'grab the pixels' from an image using an object of the class PixelGrabber as shown below. The run-time error generated is listed below the code. Can somebody suggest the reason for the error? Any help will be appreciated. Thanks!
P.S: The image "img1.jpg" is stored in the directory in which the program is run.
-S
CODE:
-----------------------------------------------------------------
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
public class CBImageRetrieval extends JFrame
{
Image image = null;
Toolkit tk;
public static void main(String args[])
{
CBImageRetrieval ir = new CBImageRetrieval();
ir.setSize(900,700);
ir.show();
}
public void paint(Graphics g)
{

tk = this.getToolkit();
image = tk.getImage("img1.jpg");
g.drawImage(image,100,100,this);

int height = image.getHeight(this);
int width = image.getWidth(this);
int [] pixels = new int[width * height];
PixelGrabber imagegrabber;
imagegrabber = new PixelGrabber(image, 0,0, width, height, pixels, 0, width);
try
{
imagegrabber.grabPixels();
}
catch(Exception e)
{
System.out.println("Exception!!");
}
/*for (int i = 0; i < height*width; i++)
{
System.out.print(pixels[i] + " ");
}*/

}
}
-----------------------------------------------------------------
ERROR:
Uncaught error fetching image:
java.lang.ArrayIndexOutOfBoundsException
at java.awt.image.PixelGrabber.setPixels(Compiled Code)
at sun.awt.image.ImageDecoder.setPixels(Compiled Code)
at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:124)
at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:150
)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.j
ava:248)
at sun.awt.image.ImageFetcher.fetchloop(Compiled Code)
at sun.awt.image.ImageFetcher.run(Compiled Code)
20 years ago
Payam,

I am not able to figure out if u did define a .html file to make the applet run or if u had just changed the JFrame to JApplet and tried rerunning the same code using "javac" for compilation followed by "java" to run the applet.

U might want to "copy-paste" ur code in ur reply so that things get clearer.

-S
[This message has been edited by Suma MM (edited July 07, 2001).]
20 years ago
Assuming the vector u mentioned is v, the code for the retrieval and subsequent printing of the elements is:

----------------------------------------------------------------
for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
----------------------------------------------------------------

Please note that EVERY time u use the method nextElement() on the vector, the index of the vector gets incremented by 1; so do take all care that u r using the method exactly once inside the for loop u intend to use for printing the elements.

[This message has been edited by Suma MM (edited July 07, 2001).]
20 years ago