Swing Repainting JButton

by GarciaPL on Monday, 2 March 2015

At my currently project written mainly in Swing, I had an issue where there was a need to show some text on JButton before some calculations. Unfortunately after setting some custom text on this component using .setText method, I was invoking some quite heavy operations which blocks UI. I tried using .repaint and .revalidate methods (once on component, once on RootPane) before those operations, but they did not work. Finally, I managed to obtain how to force change this text using method paintImmediately.

getButtonLogin().paintImmediately(0, 0, 600, 600)

Finance Currency Convert

by GarciaPL on Tuesday, 17 February 2015

After my last trip do Budapest with my wife (I really recommend going to this town! It's wonderful! not only building, but also people are very very nice to tourists), I had a little forints. There is not such much of them, but recently I was checking what is the current currency rate of forint to exchange those money. It was no such difficult to do it, I just did request to Google like '9000 HUF to PLN'. Then idea came to me, that I can wrote some script in Perl which can do it for me and additionally inform via email when there is a good opportunity to exchange those money.

For sending emails I used very nice API called Mandrill [2]. For currency convert from HUF to PLN I used module called Finance::Currency::Convert::Yahoo [3].

#!/usr/bin/perl -w
use strict;
use POSIX;
use WebService::Mandrill;
use Finance::Currency::Convert::Yahoo;
$Finance::Currency::Convert::Yahoo::CHAT = 1;
$_ = Finance::Currency::Convert::Yahoo::convert(9430,'HUF','PLN');
if (defined($_)) {
   if (floor($_) gt 135) {
      print "Sell HUF : ".floor($_)."\n";
      send_email('receiver@gmail.com', 'Sell HUF', 'Right now there is the time to sell HUF');
   } else {
      print "Keep HUF\n";
} else {
   print "Error\n";  
sub send_email {
        (my $to, my $subject, my $body) = @_;
        my $mandrill = WebService::Mandrill->new(
                debug   => 1,
                api_key => 'YOUR_API_TO_MANDRILL',
        my $response = $mandrill->send(
                subject      => $subject,
                from_email   => "sender\@gmail.com",
                text         => $body,
                track_opens  => 1,
                track_clicks => 1,
                to => [
                    { email => $to }

Reference : [1] Pastebin Source Code Finance Current Convert [2] Mandrill.com [3] CPAN Finance::Currency::Convert::Yahoo

Launch4j - Generate exe from jar

by GarciaPL on Saturday, 7 February 2015

Sometimes there is a some particular need that your program (of course mainly written in Java, that's obvious) must also be able to work under Windows environment (sic!). There is no such problem if you program will have still .jar extension, but recently business in my company demanded to create such program with .exe extension. I was convinced that it's not really possible. I was thinking how to mix different approaches to create applications under Windows and Linux environment.

But I finally found a very helpful and customizable tool called Launch4j [1]. This tool is mainly used by Graphical User Interface (GUI) where you define all configuration for instance Input (jar) and Output file (exe), some classpath, header, JRE version required by application to work, some custom environment variables, splash and of course information about version, copyright, product and company name etc.

Regarding to my case in company I must transform .jar to .exe file without using GUI. There was a need to create some REST interface which will receive some parameters like .jar file, .icon and other specified information to generate generic .exe file using of course launch4j.

To do so, you must include launch4j.jar to your project and use below Java code to generate .exe.

    public static void main(String[] args) {
        try {
            File file = new File("/home/lciesluk/configuration.xml");
            try {
            } catch (ConfigPersisterException ex) {
                System.out.println("ConfigPersisterException " + ex.getMessage());

            Config config = ConfigPersister.getInstance().getConfig();
            System.out.println("Input : " + config.getJar().getAbsolutePath());
            System.out.println("Output : " + config.getOutfile().getAbsolutePath());

            File baseDir = new File("/home/lciesluk/launch4j"); //extracted launch4j
            Builder b = new Builder(Log.getAntLog(), baseDir);
            File build = b.build();
            System.out.println("EXE location : " + build.getAbsolutePath());
        } catch (BuilderException ex) {
            System.out.println("BuilderException " + ex.getMessage());

I added also an additional sample of configuration file used by launch4j [2].
  <errtitle>Please download and install Java</errtitle>

Reference : [1] Launch4j Home Page [2] Launch4j Configuration XML

Grand Prix BIHAPI

by GarciaPL

On 29th January in European Center of Solidarność in Gdańsk were announced results of BIHAPI competition. First winner of competition was "CoSieStao" which allows users access to various types of information related with town/district where they live. Application was created by Paweł Konieczny and Piotr Martyniak. There were also awarded such applications like "Via CRM the first passenger relationship management in the world", "Poczytaj mi", "Stacz kolejkowy" and "IfCity". More information about competition and awarded applications can be found under www.bihapi.pl.

Competition partners :

Oracle Communication (technology partner), Capital City Warsaw, Gdańsk, Poznań, Poznańskie Centrum Superkomputerowo-Sieciowe, IQ Partners, Black Pearls, SpeedUp Group, Investin, Fundacja TechSoup, Orange Foundation, Fundacja Pracownia badań i innowacji społecznych Stocznia, Centrum Cyfrowe Fundacja Projekt: Polska, geecon.org, Gdański Park Naukowo-Techniczny, Uniwersytet Ekonomiczny w Poznaniu, Warsaw University of Technology, Międzynarodowe Targi Poznańskie.

 BIHAPI Grand Prix

Atom RSS Parser Android

by GarciaPL on Wednesday, 21 January 2015

One of my Android applications requires to fetch and process external RSS resource. My first thought was that I should use very useful and well documented library called ROME [1]. Unfortunately I had some difficulties using this library because of there is a lack of java.beans package in Android's Java API implementation [2]. Of course you can fix this issue by installing some missing packages, but I was looking for some out-of-box solution. Finally, I found library called Simple Feed Parser [3]. It may for some of you be quite outdated (last commit was 4 years ago) and I found that there is a some issue with accessing date of single RSS entry, but it has very simple implementation, it is compatible with Android SDKs and it does not require any further library dependencies! Below you can find some example usage of this library in Java.

import com.ernieyu.feedparser.Feed;
import com.ernieyu.feedparser.FeedException;
import com.ernieyu.feedparser.FeedParser;
import com.ernieyu.feedparser.FeedParserFactory;
import com.ernieyu.feedparser.Item;

try {
                InputStream inputstream = new URL("http://rss.android.com/rss).openStream();
                FeedParser parser = FeedParserFactory.newParser();
                Feed feed = parser.parse(inputstream);
                List itemList = feed.getItemList();
                for (Item item : itemList) {
                    logger.info("Title : " + item.getTitle());
                    logger.info("Item : " + item.getLink());
                    logger.info("Description : " + item.getDescription());
                    logger.info("Date : " + item.getPubDate()); //might be null
            } catch (IOException e) {
                logger.info("IOException : " + e.getMessage());
            } catch (FeedException e) {
                logger.info("FeedException : " + e.getMessage());

References :  [1] ROME - All feeds lead to Rome! [2] Java.Beans on Android [3] Simple Feed Parser

Android Debug Keystore

by GarciaPL on Tuesday, 23 December 2014

For some of you I have this very useful command line for getting Android Debug Key which can be used for signing Android applications.

keytool -keystore /home/lukasz/.android/debug.keystore -v -list -alias androiddebugkey -storepass android -keypass android

After executing this command you will some something like that :

Alias name: androiddebugkey
Creation date: 2014-12-18
Entry type: PrivateKeyEntry
Certificate chain length: 1
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 32435620
Valid from: Thu Dec 18 21:04:11 CET 2014 until: Sat Dec 10 21:04:11 CET 2044
Certificate fingerprints:
  MD5:  XXX
  SHA256: XXX
  Signature algorithm name: SHA256withRSA
  Version: 3


#1: ObjectId: Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 20 B4 60 1E 46 B5 AD B0   45 49 93 48 C2 D6 0C BF   .`.F...EI.H....
0010: 9C CD 8D 02                                        ....
Information under SHA1 can be used to signing Android apps. More information about signing Android apps you can find under this link Developer.android.com - App Signing.