Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Is there a way to convert the RGB value of a BufferedImage pixel into hex? Alternatively, can the value of a pixel be gotten and set using hex?

Adbot
ADBOT LOVES YOU

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Oh, ok. I just wanted to know if there was an easier way of doing it that dvinnen said.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

dvinnen posted:

So I've been working on this applet/servlet combo for a while now. The applet communicates with a servlet that collects data and sends it back to the applet via HttpsURLConnection. I'm using an unsigned cert for now as everything is on my dev machine.

Everything was running good till I updated the Java version today and the applet started throwing "java.security.AccessControlException: access denied (java.net.SocketPermission localhost:8443 connect,resolve)

So far I've tried editing my java.policies file, disabling my firewall (though everything is local). I don't think it has to do with my cert as I can reach https://localhost:8443/, everything is encrypted. Also, when I first started using SSL with the applet I was getting different, more descriptive errors till I fixed it.


The code where it gets thrown is basically this:

code:
URL url = new URL("https://localhost:8443/WARFile/servletName");

HttpsURLConnection = (HttpsURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setDoInput(true);

OutputStream out = conn.getOutputStream();

ObjectOutputStream oos = new ObjectOutputStream(out);
The error gets thrown where 'out' is declared

edit: does the applet have to be signed or something? I'm not modifying anytihng on the client's system but I am connecting to something out of it's domain I guess. Like I said, it worked fine with 1.5 so I guess security is tighter in 1.6

You're missing a variable name. Shouldn't it be
code:
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setDoInput(true);

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
The ternary operator way to do it would be quite a bit faster, too. Modulus is a pretty long operation for the CPU.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
If it's private, you do, if it's public you don't.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
It looks like it's just not getting any matches. Try a .contains("`") to see if the character is being detected properly.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
You could try a JDialog with the Modal property set to true. Execution of the parent frame pauses until the dialog is disposed of. CropDialog is the dialog you're doing the selecting in.

code:
CropDialog dialog = new CropDialog(Image image);
dialog.setModal(true);
dialog.setVisible(true);
//Program pauses here while dialog is running
Rectangle rect = dialog.getCoordinates();

Ensign Expendable fucked around with this message at 19:10 on Jun 30, 2011

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Why is every single Swing component designed in the most obtuse way possible?

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
import java.util.InputMismatchException;

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Scanner has its own imports in its source. Importing a class that imports something else doesn't import its imports.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
The "throws" clause tells methods calling that method that somewhere in your method, an exception of that type may be thrown. Those methods should either catch that exception of throw it themselves so another method would have to handle it.

It's a bad idea to use recursion when you don't have to since it pollutes the stack with method calls needlessly. If the user enters a wrong file enough times, it will crash the JVM. On Java this isn't so bad, but in other programming languages this is a serious security flaw.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
When I was taught Java, the really basic stuff was taught using a package called Console that took care of the really basic IO and graphics stuff. Later on, they taught us Swing with more graphical ways to get input, and then Scanner/BufferedReader/FileWriter/etc.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Why bother throwing anything? Just suppress it! If the stack trace is never printed, that means it never happened!

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
If it gets stuck into an excel spreadsheet, you can set the formatting for those cells to have two decimal places displayed programmatically through Excel, but it's a giant pain in the rear end to get Office Interop working with Java in the first place, let alone actually doing useful things with it.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

Aleksei Vasiliev posted:

it should just be return s.startsWith("/");

or to make it unreadable and also throw a better exception, return Objects.requireNonNull(s, "Line must not be null.").startsWith("/")

Wow, I never read about this feature before. Seems really useful. Too bad my workplace is using ancient versions of Java for no good reason. It's not like we have apps that rely on specific hacks to make them work, one of the devs just refuses to upgrade to new versions.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
I have never heard of instanceof being a bad idea. You could do something like

code:
Instrument tabComponent = (Instrument)instrumentSettingsTabbedPane.getComponent(x);
instrumentSettings[x] = tabComponent.getSettings();
provided Instrument1 and Instrument2 are subclasses of Instrument that defines getSettings(). This will also call the Instrument1 and Instrument2 getSettings() methods automatically, depending on which Instrument the tabComponent is.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Write an interface Instrument that defines getSettings() and other stuff Instruments need.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
If the code is multithreaded, the condition may have changed. Also I guess it makes it a little more readable. Even if there are no external threads changing the condition, you still know when .doSomething() runs without having to scroll up to find out why myObject is or isn't null.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Java doesn't change anything between versions, too much. All the major changes from 6 to 7 are either under the hood or advanced features you will probably never encounter.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
I use JDOM, and it's really, really easy. When you read in the file, it forms a tree of Elements, which have all the relevant things associated with them.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
I didn't know it could get even easier than JDOM.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
There isn't any way for the program to know the doubles ended unless you tell it, either by some terminator character (a null or something that fails the double parse and returns false on hasNextDouble()) or by knowing how many doubles there are and going through it a finite amount of times. Are you reading from a file or from keyboard input?

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
The difference between .equals() and == is that the first compares the contents of the class, whereas the second compares their references. "a".equals("a") will return true, but "a"=="a" will return false, since those are two different String objects.

Also, in Java, you need an Exception for a try-catch. You don't need to make your own Exception class, really. The word you're thinking of is "extends".
code:
try
{
}
catch (Exception e)
{
}

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Technically, int is a primitive and Integer is a wrapper class, but autoboxing allows you to treat them basically the same way (aside from calling instance methods from them).

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
toString() is the standard method of getting a string representation from an object, so use that, even if they do the same thing internally.

Adbot
ADBOT LOVES YOU

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Scanner is really friendly and easy to use, but it's really slow performance-wise and not as versatile. Use FileReader or BufferedReader.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply