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
RitualConfuser
Apr 22, 2008

Aleksei Vasiliev posted:

I also need the examples, which are apparently in a separate JAR. com/sun/jna/examples has empty directories in these.
Thanks for the repo tip, though.

There are some demos under the contrib dir in the repository but I'm not sure if those were the examples that were in the distribution.

Adbot
ADBOT LOVES YOU

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Found the examples in svn/tags/3.2.7/jnalib/contrib/platform/src/com/sun/jna/platform/win32
I think.

That's not complicated at all.

Thanks!

edit: Wait, no I didn't. I found code that the examples need. Fuuuck.
At least the examples are probably somewhere in this, though.
editedit: wait I think these are what I needed, whatever
edit3: Yaaay. Now I can load User32 and do GetWindowRect and GetClientRect so I can find a window's position and size.

Malloc Voidstar fucked around with this message at 06:24 on Feb 11, 2011

Oxyclean
Sep 23, 2007


I'm trying to make a calculator for this assigment, and I need to have a class that sends the button's value (text) to the display field.

I can't seem to figure out how to retrieve this text; I assume I need to pull it from the event.getSource(); but getText doesn't work on that.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Oxyclean: Let's have a look at the Javadoc.

EventObject.getSource() returns an Object. If it is a JButton, we can call getText() on it.

code:
class Quux implements ActionListener {
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source instanceof JButton) {
       String label = ((JButton)source).getText();

       ...
    }
  }
}
Note that this is not by any means the only approach for tying button presses to numerical values.

Internet Janitor fucked around with this message at 03:33 on Feb 12, 2011

Oxyclean
Sep 23, 2007


Oh, ok, that works, the example I saw of getSoruce didn't call the object type (it was just comparing the source to an object)

I was trying to do
code:
 String label = source.getText(); 
the whole time, and it was telling me it couldn't find symbol.

Thanks a ton.

amr
Feb 28, 2005
I love boxes of toast
Not sure that this warrants its own thread, but I'm not sure if it's a Java problem I'm having, more than likely it's my understanding.

I'm implementing (or trying to) a Gaussian filter for greyscale images in Java - I don't want to use the ConvolveOp class as it's for University work so I'll probably lose marks in that respect.

The problem I'm having is that the resulting image is about half the brightness that it should be, as shown by the classic Lena:

from

I'm extending an ImageFilter class (which just sets some basic variables like isColour, loads the image, etc) as I'm going to be implementing a few different filters.

I can't tell whether it's my implementation of the Gaussian function, though I'm not sure as that's straight from my lectures, or whether I'm using it incorrectly! Would really appreciate anyone point out where I might be going wrong

My source is here - I'm using a 3x3 maskSize (just set to 3)

Edit: Interestingly, If I change the 3x3 matrix to consist of just (1/9) at each location I get a similar ouput, in that it's a bit blurry (yay) but the brightness has been reduced (boo) - most odd!

Edit 2: The bottom right pixel (255,255) on the original should be 106 after shifting to get the R component (R=G=B in greyscale) it says it's 173 - which is wrong! Hmmm...

\/ Woahhh, I wonder what I broke! Guess I'll have to look at the rest of the program then, thanks! :)

amr fucked around with this message at 15:40 on Feb 13, 2011

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
closed: WORKSFORME



(seriously, I just got your code runnable, gave it lena, and it blurred it)
edit: fixed paste link to not point to code that causes a nullpointerexception :downs:

Malloc Voidstar fucked around with this message at 15:39 on Feb 13, 2011

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
What is the deal with preCalc in getGreyGaussianPixel()? If you're just going to sum the list in the end and never access any elements of the list, why aren't you simply accumulating in a double as you go?

amr
Feb 28, 2005
I love boxes of toast

Internet Janitor posted:

What is the deal with preCalc in getGreyGaussianPixel()? If you're just going to sum the list in the end and never access any elements of the list, why aren't you simply accumulating in a double as you go?

Oh that was just left over from when I was doing something differently, I'll change that eventually - well spotted though thanks, added to my list of things to fix.

amr
Feb 28, 2005
I love boxes of toast
Just tried using a JPG image instead, and it worked! I was originally trying with a BMP image, which I think was natively B/W and the way I was accessing it wasn't working - relief to know it works alright!

Thanks :)

Howmuch
Apr 29, 2008
I've decided to try to make a small home budget program in java to teach myself some new stuff.

But I'm kind of stuck because I have no idea what would be the best/easiest/smartest way to store the data that gets put into the program. (user would enter data into table and then just click a "Save" button)

Would storing the data in an xml file be the right way to go ?
That's the only idea I have and my google-fu keeps failing me.

Outlaw Programmer
Jan 1, 2008
Will Code For Food

Howmuch posted:

I've decided to try to make a small home budget program in java to teach myself some new stuff.

But I'm kind of stuck because I have no idea what would be the best/easiest/smartest way to store the data that gets put into the program. (user would enter data into table and then just click a "Save" button)

Would storing the data in an xml file be the right way to go ?
That's the only idea I have and my google-fu keeps failing me.

The simplest approach would probably be a comma delimited file like:

code:
last,first,age,weight
smith,bob,45,180
smith,mary,42,130
This would be really fast to whip up. I would direct your attention to the 'PrintWriter', 'FileWriter' and 'Scanner' classes, as well as the 'String.split' function.

CSV files are pretty basic, and will really start to buckle when you're dealing with a lot of data. Anything but the most basic applications will probably need to store data in a relational database. Relational DBs let you quickly retrieve individual records or groups of records, and they do a lot of the heavy lifting of indexing, sorting, etc. I recommend something lightweight like JavaDB. "Lightweight" means you can embed the database directly in your application; no need to startup a separate process like MySQL.

Paolomania
Apr 26, 2006

You could also play around with automatic serialization to file with ObjectOutputStream/ObjectInputStream, and from there experiment with manually serializing/deserializing your objects in a custom format with DataOutputStream/DataInputStream, and then for a more advanced exercise, go back to using Object*Stream and implement custom serialization through implementing the Externalizable interface.

Howmuch
Apr 29, 2008
Awesome, I'm definitely going to check out JavaDB and then later on dive into what Paolomania posted. Thanks for the tips.

chippy
Aug 16, 2006

OK I DON'T GET IT
Help me guys. I have a tool used by a few people where I work. Someone's asked me if it can read the SIM number from a USB GSM/3G modem attached to the PC running the tool. There's an AT command for this so I thought it would be quite straightforward, but I'm running into some issues. I've found javax.comm and thought I could use it to send the AT commands, but I'm not sure if it will work for a USB COM port and also, because it's a USB COM port, it's not going to have the same number (e.g. COM1, COM2 etc.) every time.

I've found javax.usb but I'm not entirely clear if I could use that either. It's looking at the moment like I could maybe use javax.usb to locate the USB modem by device name and then work work out what COM port it's on, then hand off to javax.comm to do the AT Command work. Does this sound feasible? Is there an easier approach I'm not seeing? I'm getting a bit lost in API documents at the moment.

edit: Hmmm, ok maybe I could just send "AT" on every COM port until I get an "OK" response. That would work round the problem of having to forceClaim the the interface from Windows, since Windows is going to need to use the device after the tool is done with it. That might work except there is also an old school analog modem on one of the serial ports.

chippy fucked around with this message at 14:17 on Feb 18, 2011

Stubb Dogg
Feb 16, 2007

loskat naamalle

chippy posted:

edit: Hmmm, ok maybe I could just send "AT" on every COM port until I get an "OK" response. That would work round the problem of having to forceClaim the the interface from Windows, since Windows is going to need to use the device after the tool is done with it. That might work except there is also an old school analog modem on one of the serial ports.
You could always send ATI commands for manufacturer string or something GSM specific to each port and try to identify which of the modems is the GSM one.

Though when I was doing something similar with GSM modems with Java we found out hard way that Java serial port support at least on Windows was somewhat unreliable and we had to rewrite serial comms componets with C#.

chippy
Aug 16, 2006

OK I DON'T GET IT
Yeah, that would be the best idea I think, there's going to be max 2 modems present and it should be easy enough to tell them apart with a couple of choice AT commands. You're right though, javax.comm apperas to have been officially discontinued for Windows.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
I'm trying to write an application that uses TCAP network transport. The problem is that TCAP seems to be inextricably linked to SS7, whereas we're supposed to be using IP. Are there any libraries that allow me to use TCAP over IP?

FamDav
Mar 29, 2008
I want to use a ThreadPoolExecutor to maintain processes sent to the server. However, I would like the logging output to show which thread in the pool performed which actions.

1. Is there a way to synchronize the running of the thread run() with the runnable object's run()? That is if I had the thread print it's ID to the log could I guarantee it to be immediately followed by its runnable process?
2. Is there a way to pass the threadID to the runnable object?
3. Is there some way to do this that I haven't thought of?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

FamDav posted:

3. Is there some way to do this that I haven't thought of?

Is Thread.currentThread().getId() what you are looking for?

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

FamDav posted:

I want to use a ThreadPoolExecutor to maintain processes sent to the server. However, I would like the logging output to show which thread in the pool performed which actions.

Log4j (and I assume other logging frameworks?) can tell you which thread in a pool is logging which output.

If you have a pool named 'foo', the output could look something like this:
code:
 2011-02-23 15:31:14,450 [foo-0] INFO blahblahblah
 2011-02-23 15:31:14,662 [foo-1] INFO feefeefeefee
                          ^^  ^
                   pool-name  thread-number

Paolomania
Apr 26, 2006

I just want to express how much I hate apache source code. Seriously its like Dark City in there - everything keeps looping back in on itself.

epswing
Nov 4, 2003

Soiled Meat
Example?

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa
"We're an Apache project, therefore we must use Apache Commons Logging!" would be an excellent example of that.

Just no.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Parantumaton posted:

"We're an Apache project, therefore we must use Apache Commons Logging!" would be an excellent example of that.

Just no.

slf4j or :frogout:

Paolomania
Apr 26, 2006

epswing posted:

Example?

Currently I'm trying to trace the flow of data from a HTTP request in Tomcat 6 all the way from the socket to the point of dispatch to a servlet's doGet method. It is an obfuscated mess of abstractions including a dizzying array of wrappers, pipelines, filters, and custom NIO-like classes. There are probably good reasons for their intensive use of abstraction, but it sure as hell makes it a pain in the rear end to read the code.

Fly
Nov 3, 2002

moral compass

MEAT TREAT posted:

slf4j or :frogout:

We've got adapters for log4j, slf4j, and commons in our code base. Maybe more.

It all gets converted to our own logger that predates them all, but our logger is kind of nice since it will output to multiple places, such as our logging database, and writing converters is easier than spitting.

So in the end who cares?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Right but you're not an Apache Project. That's who my comment was directed at.

Fly
Nov 3, 2002

moral compass

MEAT TREAT posted:

Right but you're not an Apache Project. That's who my comment was directed at.
I misunderstood. Why should an Apache project use a different library?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Because a lot of Apache projects already switched.

quote:

Apache Archiva
Apache Directory
Apache FTPServer
Apache Geronimo
Apache Graffito
Apache Jackrabbit
Apache Mina
Apache Qpid
Apache Sling
Apache Solr
Apache Tapestry
Apache Wicket

Mr VacBob
Aug 27, 2003
Was yea ra chs hymmnos mea

gastownlabs posted:

How can I get java.awt.Robot createScreenCapture to give me the correct colors? Is it applying the color profile on my Mac before taking the screenshot?

Something like that.

quote:

It was saved as a PNG and this PNG matches up with any getRGBs I perform on the BufferedImage. However, the colors don't correspond to the hex codes next to them. If I take a normal OS X screenshot, they match perfectly.

Is there a way around this?

Ask on java-dev and include what you're actually trying to do.

covener
Jan 10, 2004

You know, for kids!

MEAT TREAT posted:

Because a lot of Apache projects already switched.

Seems fallacious, different people on different projects use different logging. Who could possibly give a gently caress?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

covener posted:

Seems fallacious, different people on different projects use different logging. Who could possibly give a gently caress?

I gave a gently caress when I had to include 5 projects and each one used a different logging API. Thankfully now I've consolidated all of that poo poo using slf4j adapters and redirect it to whatever my container uses.

My point was that now that slf4j exists there isn't any reason to use the commons logging API in new projects. Parametrized logging is loving awesome and you don't have to deal with the classpath issues of the JCL.

Paolomania
Apr 26, 2006

Those drop-in slf4j bridging jars look pretty cool.

Chairman Steve
Mar 9, 2007
Whiter than sour cream
They're a God-send when you're using multiple third-party libraries - without them, a deployer would have to configure JDK logging, Log4j logging, and Commons Logging for a single application.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

Paolomania posted:

Those drop-in slf4j bridging jars look pretty cool.

Implementing your own (for whatever purpose) is also laughably easy.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

A lot of posts about logging when pros just use System.out

Paolomania
Apr 26, 2006

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

Paolomania posted:



Finnish logging supremacy.

Adbot
ADBOT LOVES YOU

Cojawfee
May 31, 2006
I think the US is dumb for not using Celsius
After a few years of doing nothing, I've decided to get back into Java. I want to redo some dungeon crawler game I made for a final project in high school. I'm off to a somewhat decent start as NetBeans easily created a nice GUI for me (the one I made in high school was some sort of Frankenstein's monster I created out of frantic googlings of Swing and AWT). But I've fallen into an old habit where I want to try something that I probably will never use but I can't move forward until I've made it work.

Basically I want to type something in to a JTextField, press enter, then it appends the text to a JTextArea, then it sets the text field to uneditable, sets the textfield to say "wait" and then three seconds later clears that field and sets it back to editable. I've successfully been able to do everything except the wait three seconds part. I've tried using Thread.sleep(), but no matter where I put it, it seems to do the sleep before all the other parts. I tried to use the Timer class but NetBeans says there aren't any constructors for it.

I've tried moving all the different parts into their own methods. It seems that if I call my waiting method, it will always do it before any method before it or something.

Just another case out of many where my brain doesn't work the same as whoever designed whatever language I'm using.

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