Přeskočit na hlavní obsah

Příspěvky

Zobrazují se příspěvky z duben, 2013

Checking internet connection and connection to a particular server in Java

In AgroSense we need to know, if the computer is connected to the internet or not. And we don’t want to bother the user by throwing UnknownHostException or IOException also. So we need two things: Check the connection Notify everybody interested, that the connectivity changed When the first point is successfully implemented, the second one is easy – it is just a listener, so we will look only at the connectivity check problem. Solution For checking internet connectivity you need some host address. You will probably use the address, which you actually call, in our case it is www.openstreetmap.org. In first step, we check, if there is some internet connection, this is done in a method isOnlineFastCheck: private boolean isOnlineFastCheck() {         boolean check = false;         try {             InetAddress.getByName(hostName);             check = true;     ...

How to remember zillion passwords to zillion sites

I use about 6 different passwords to access my let’s say 25 accounts over the internet, including email, internet banking, linkedIn, oDesk, cloud9, openshift, bitbucket, twitter, facebook, icq, project1709, Amazon …  There are just too many. Some of them I don’t want to type every day and I don’t see a problem in being signed permanently, so I check the Keep me logged in option when I can. Some of them are so important and leave no way to forget the password, like work account or internet banking login. But some are used so rarely, I sometimes don’t remember event login name, not speaking about the password. How to solve this? OpenId Great solution (although one of those, where I don’t remember my password :-) ). The idea is great, but still there exists too many sites, that don’t support this type of logging. Maybe in a few years it could become a standard. There is always hope. Google / Facebook This is very similar to the OpenId project. I am not so...

Really responsive Java application

This article isn’t about concurrency or threads synchronizing, neither about responsive design. It is about making your Java application user responsible and friendly. All that threads Working with threads in Java is … well I can’t say easy, but at least well documented and great supported. You can create your own Thread object and pass it the Runnable object with logic, which should be executed in background. You can use SwingWorker API, which is great for long running tasks with callbacks to GUI (for example to update progressbar). There is also ExecutorService (part of java.util.cuncurent API), which solves asynchronous issues and starting in Java 7 there is the Fork/Join framework to add even more support for parallel programming (but it solves different problem, than described in this article). Working with threads has its own quirks, but when using threads together with GUI, we always have to keep in mind two major rules: Time–consuming tasks shouldn’t be run on ...