R Johnson

Greenhorn
+ Follow
since Jan 05, 2010
R likes ...
Java
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 R Johnson

I currently have a websocket chat program I figured out how to intercept the traffic locally using Winsock and it gives me a somewhat encrypted hexadecimal message. I would like to write a java program that resends the same message to the server.



I get a connection to the host:port but my output stream doesn't seem to be working the server does not seem to register the packet. I also had to comment out the inputstream because it continues to error out . I just need to send the hex information to the server which is the exact same information I sent to it and copied from Winsock. Thanks for any help or tips!!
11 years ago
This question is a little in depth but essentially I am trying to ping an intranet page for updates and post any updates to a text box. Sort of like an rss feed. Using the Tools>Developers on Google Chrome I copied all the headers to match exactly. There are no cookies needed for the request and the program I wrote works but only for a little while then it gives me a 509 IOException error when attempting to connect. Looking up the error tells me it's a bandwidth exceeded error but when I hit refresh on Google Chrome which appears to send the exact same header information as I am in java it refreshes with no issues. There is a ton of code and the web page is an intranet page so I can't really provide exact code but maybe pseudo code if someone thinks it might help. Thanks to anyone who might be able to provide me with a direction to look for issues because I just can't even begin to understand where the issue is coming from unless it's sending something other than my headers to the page.

The intranet page I cannot access or change anything about it but I do know it's written in php and using an Apache Server.

Using HTTPURLConnection and BufferedReader for the response.

To clarify in case it's not clear accessing the intra-page in java using HTTPURLConnection works for about 2 minutes and then gives me the error. I would think it was blocking my ip or something if when I refreshed Google Chrome it blocked that as well. But for some reason I can refresh Google Chrome and get the page but not when I essentially "refresh" with Java.
This question is a little in depth but essentially I am trying to ping an intranet page for updates and post any updates to a text box. Sort of like an rss feed. Using the Tools>Developers on Google Chrome I copied all the headers to match exactly. There are no cookies needed for the request and the program I wrote works but only for a little while then it gives me a 509 IOException error when attempting to connect. Looking up the error tells me it's a bandwidth exceeded error but when I hit refresh on Google Chrome which appears to send the exact same header information as I am in java it refreshes with no issues. There is a ton of code and the web page is an intranet page so I can't really provide exact code but maybe pseudo code if someone thinks it might help. Thanks to anyone who might be able to provide me with a direction to look for issues because I just can't even begin to understand where the issue is coming from unless it's sending something other than my headers to the page.

The intranet page I cannot access or change anything about it but I do know it's written in php and using an Apache Server.
12 years ago
Thank you Darryl I will read the link you have provided. I do not like toolkit create because it creates an image and I need a buffered image in order to draw subimages, but it seems your link may address this so I may need to ask more on this after reading it. Thanks again for your help.

Edit:
I did not read past Image Creation mark, but it seems to disagree with the use of Toolkit/Applet/ImageIcon unless I'm only displaying the image and have no need for the bufferedImage capabilities. I have been avoiding a multithreaded solution for one because I assumed there might be an easier approach because I would think this to be a common issue. Thanks for the link though hopefully I can get a multithreaded solution to work. If you have any recommendations on the best place to implement and add such a thing I am all ears. Or if there is a way into the ImageIO thread to alter the effect this seems like it would be possible as well.
12 years ago
Thank you Darryl for your reply. I am curious though about the api. I believe Java is one of the best documented languages out there. Even Microsoft has third party programs to purchase just to read the .NET framework classes provided which I believe to be ridicioulous. Although my source for java api is just oracles website is there another location, because although I believe it is well documented I don't believe it is documented so well that they say java will not move forward with ImageIO and will with Toolkit. Here's a snippet of both ImageIO.read from oracles website perhaps I'm missing your reference to the api where it says this.


read

public static BufferedImage read(File input)
throws IOException

Returns a BufferedImage as the result of decoding a supplied File with an ImageReader chosen automatically from among those currently registered. The File is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.

The current cache settings from getUseCacheand getCacheDirectory will be used to control caching in the ImageInputStream that is created.

Note that there is no read method that takes a filename as a String; use this method instead after creating a File from the filename.

This methods does not attempt to locate ImageReaders that can read directly from a File; that may be accomplished using IIORegistry and ImageReaderSpi.

Parameters:
input - a File to read from.
Returns:
a BufferedImage containing the decoded contents of the input, or null.
Throws:
IllegalArgumentException - if input is null.
IOException - if an error occurs during reading.

read

public static BufferedImage read(InputStream input)
throws IOException

Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. The InputStream is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.

The current cache settings from getUseCacheand getCacheDirectory will be used to control caching in the ImageInputStream that is created.

This methods does not attempt to locate ImageReaders that can read directly from an InputStream; that may be accomplished using IIORegistry and ImageReaderSpi.

Parameters:
input - an InputStream to read from.
Returns:
a BufferedImage containing the decoded contents of the input, or null.
Throws:
IllegalArgumentException - if input is null.
IOException - if an error occurs during reading.



But I do believe you answered my question and will test it tomorrow. I am greatly appreciative of your help because I have posted this question in many different forums and places and was beginning to lose hope on getting an answer. My alternative move next was to multi-thread the image loading somehow.

Thanks
12 years ago
Hello all,
First let me take a second and explain that I'm not providing real code (code will not compile) at the moment because the actual code is very very long and I have no issues other than I'm just trying to make a splash screen because it is taking a little while to load the images in the beginning. I am happy to offer real code and I realize that I may not be very efficient in my code and am very interested in how I can be more efficient once I figure out how to complete the task I need. Currently I have an applet














The only thing that happens though is I don't get the splash page until the images have loaded because the images load one by one as evidence by my System.out.println("getting image : "+path); in the ImageHandler class's addImage method and I never get the StoryPage run method System.out.println("story page running"); . I would like the images to load with a splash screen and I had thought mediatracker was the way to go with this. Any suggestions or help would be greatly appreciated. Again the code above is not real and I hand coded it in the forum text box so there is probably a lot wrong with it I was just attempting to provide the architecture of the program so I could be given the best place to test the images.

Thanks again for any help this community can provide I have had better luck here then most other forums.
12 years ago
You need to look into the Integer Wrapper class this is where your problem lies.



When working with primitives and strings you can just concat the primitive int to a null string like so:

int i=0;
String s=i+"";

Otherwise you would have to use the Integer class wrapper of Java in order to use the toString() method



Your line 36 problem is pretty much the same you would need to use the Integer class wrapper to parse out strings to integers.
12 years ago
I would


it's probably identical to having two loops but it is easy to read and you don't have to reinvent the wheel. I didn't add any protection for trying to access outside of the array but just thought I'd give an alternative.

cheers
12 years ago
Hello all,
First let me take a second and explain that I'm not providing real code (code will not compile) at the moment because the actual code is very very long and I have no issues other than I'm just trying to make a splash screen because it is taking a little while to load the images in the beginning. I am happy to offer real code and I realize that I may not be very efficient in my code and am very interested in how I can be more efficient once I figure out how to complete the task I need. Currently I have an applet














The only thing that happens though is I don't get the splash page until the images have loaded because the images load one by one as evidence by my System.out.println("getting image : "+path); in the ImageHandler class's addImage method and I never get the StoryPage run method System.out.println("story page running"); . I would like the images to load with a splash screen and I had thought mediatracker was the way to go with this. Any suggestions or help would be greatly appreciated. Again the code above is not real and I hand coded it in the forum text box so there is probably a lot wrong with it I was just attempting to provide the architecture of the program so I could be given the best place to test the images.

Thanks again for any help this community can provide I have had better luck here then most other forums.
12 years ago
That works great thanks Pete!
13 years ago
If you change the size of an Object that is a component of JScrollPane what method allows resizing of the scrollbars so that it knows it's looking at a smaller/larger portion of the image?
in my code I tried using paint and revalidate and invalidate none of which gives the desired effect

13 years ago

But a JPanel and a BufferedImage are two completely different animals and should not be expected to behave the same. The Graphics object obtained from a JPanel is only temporary and will be replaced any time the JPanel is repainted including repainting that is not under your control such as when the operating system requests a repaint of a portion of your app. So using this knowledge you will expect a JComponent's Graphics object will not to persist and adjust your code accordingly. Nothing strange here as long as you understand what's going on.

A great link that explains a lot of the inner workings of Swing painting is this one: Painting in Swing and AWT



I'm not disagreeing and I understand the behavior my only confusion is that all a JPanel or any component for that matter is is colored pixels on a computer screen. If tell it to draw on it's graphics it seems a waste to have a method that allows it without saving the drawing/colored pixels to it's vector of colored pixels. I understand I can create a bufferedImage and draw this any time the component asks for paint()/paintComponent()/updateUI/etc etc. The problem I'm having is I'm trying to implement a feature at the moment that should be simple. If I draw on a bufferedimage and resize it to grow or shrink unlike in MSPaint the drawing does not scale correctly and stay in it's correct place. I created a grid with JPanels and first tried just drawing on a big image that overlapped all the JPanels and as I said the bufferedImage does not scale correctly with the JPanels to remain in it's placement on the grid. So I tried making individual images for each panel and allowing to draw on that I believe I'll still have an zoom loss problem but at least whatever remains will be in the correct cell. As I'm writing this I'm thinking of just drawing the grid and everything on one image and getting rid of the JPanels. I know I'll still have the zoom problem but it will remain in the correct cell and then will only have the one problem.

Perhaps an example and thanks again for all the replies and help.
In the example I'm just drawing circles if I make the frame smaller the circles become non-circles and I know I'm copying the image with non-circles and making them larger so all I have now is larger non-circles. I also understand I could just programmically draw things larger and bigger according to the images size but since the user is drawing the images and could draw at different zoom levels I would have to take snapshots anytime a person drew on the image and then just shrink or grow the original snapshot, if I didn't take a snapshot and just stored it as an image then my only other guess would be to capture the array of colored pixels and adjust it as it grows or shrink,but both of these seem overly complicated and I was just wondering if their was an easier solution.

13 years ago
I believe I understood the tutorial but that would mean I would have to create a vector of pixels that I've colored so I could minimize or view other windows in order to repaint what I've drawn when the frame is repaired. This seems a bit redundant because there is a vector of pixels being colored already and I would assume stored when I adjust the graphics of a component. If creating a vector or instead drawing on the same sized bufferedImage and then just having to paint the image on the frame in the paintComponent method is the only way then I'm sad but will accept it... I was just wondering if there was another solution.

For that matter bufferedImage is a great example of being able to draw on it using the createGraphics and what is drawn is stored on the Object...... It seems strange that the behavior would be different for a panel.
13 years ago
I too have a problem with paint.. I can get the component to let me draw on it however if somethings obscures/damages the view or is minimized and then restored all the graphics are lost. I tried createImage(ImageProducer) but the ImageProducer confuses me since I'm calling createImage on the object I want to produce the image. I Also tried createImage(width,height) and get null values. I was trying to store a temp image of the canvas and then redraw it in the paint method. I also tried getGraphics but it returns a graphics how do you draw one graphics onto another? Or what would be a better solution?
13 years ago
I'm working on a project with three JTables(Master/Employees who need to log in in the next 30 minutes/Temporary Employee logged in Table) The first column in all three tables is a boolean clocked in. The master has it's own model and the other two have new instances of a different model. The model for the other two tables use an ArrayList<Integer> to store an index of the Master List to essentially point to and retrieve information. I made a SwitchTables class which points to the of the models of all the tables. I use the same instance of this class and just point to it in all the tables so that when column0 value is changed it will switch from/too Temp Emp logged in table and then from/too Needs to Log in. I haven't worked on the coding for time or anything just trying to get the over all desire to work. It works fine as long as I click slowly in any one table. If quick rapid clicks occur in the master table duplicates occur in the destination table. If quick rapid clicks occur in the other tables the boolean value will change however it will not transfer to the other table. I tried to synchronize the methods getValueAt setValueAt firetablecellupdated methods and even Thread.wait(100) to maybe slow things down. I also created Field variable boolean to attempt to turn on/off isCellEditable method of column 0 while changing value. At first I was trying to prevent from searching the ArrayList for duplicates for fear of slowing the program, but as a last resort before asking for help I decided to try it. It didnt' work made things worse. I realize the remove method of an ArrayList can take an Obj/int and the int would be the place in the arraylist so me using Integers I tried to use the Object Integer still didn't work so I tried to (I don't know if this term is right) polymorph like this

tologin.remove((Object)masterindex));

Still didn't work. So then I just changed the ArrayList<Integer> to ArrayList<String> and changed everything to String.valueOf/Integer.parseInt depending on what I needed. Still no luck.
I would provide code but to display even just a TableModel is at least 15 lines of code or more so I was afraid it would be too large and discouraging for any help someone might be able to provide. So to my question:

Is there a way to prevent JTables from double clicking or clicking too fast on boolean checkboxes so that code can execute and finish?
Thanks for any help!
13 years ago