Παρασκευή 27 Φεβρουαρίου 2009

J2ee Start a class when application server starts

If you want to start a class when your application server starts, you simply have to follow two steps:

1) create a new class that implements ServletContextListener.
then implement the two methods: contextInitialized(ServletContextEvent event) and contextDestroyed(ServletContextEvent event).

example:

public final class MyContextListener implements
ServletContextListener {

public void contextInitialized(ServletContextEvent event) {

/* This method is called when the servlet context is
initialized(when the Web Application is deployed).
You can initialize servlet context related data here.
*/
MainThread mainthread1 = new MainThread();
mainthread1.start();
}

public void contextDestroyed(ServletContextEvent event) {

/* This method is invoked when the Servlet Context
(the Web Application) is undeployed or
WebLogic Server shuts down.
*/

System.out.println("goodbye");
//thread's clean up code
}
}



Then add:

Tools.MyContextListener


under the web-app of web.xml file.

That's it!

Τετάρτη 25 Φεβρουαρίου 2009

Android get Screen orientation

You can check your screen orientation by calling:
[code]int orientation = getWindowManager().getDefaultDisplay().getOrientation()[/code]
and checking if it equals on of the following...

Configuration.ORIENTATION_PORTRAIT
Configuration.ORIENTATION_LANDSCAPE
...

Δευτέρα 23 Φεβρουαρίου 2009

Eclipse line break [wrap]


Καλό χρυσό όμορφο το eclipse, αλλά ο formater του μου έσπαγε τα νεύρα όταν "δίπλωνε" τις γραμμές στον κώδικα κατα το source formating λες και δούλευα σε 13'' οθόνη...

Μετά απο αρκετό καιρό, μια καλή ημέρα (σήμερα) αποφάσισα να το ψάξω λίγο περισσότερο και να βρω μια λύση.

Έχουμε και λέμε λοιπόν:
Windows -> Preferences -> Java -> Code Style -> Formatter -> Edit -> Maximum line width.

Επίσης για αυτούς που δεν θέλουν ΚΑΘΟΛΟΥ wrapping, μπορούν να το αλλάξουν, πειράζοντας το πεδίο "Line wrapping policy" σε Do not wrap.

Do not wrap my code λοιπόν bitch!

Σάββατο 14 Φεβρουαρίου 2009

Android unknown socket error -1

Exception:
[code]E/OSNetworkSystem( 164): unknown socket error -1
W/System.err( 164): java.net.SocketException: unknown error
W/System.err( 164): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native Method)
W/System.err( 164): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java:79)
W/System.err( 164): at org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java:59)
W/System.err( 164): at java.net.Socket.checkClosedAndCreate(Socket.java:763)
W/System.err( 164): at java.net.Socket.connect(Socket.java:910)
W/System.err( 164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:61)
W/System.err( 164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
W/System.err( 164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
W/System.err( 164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:800)
W/System.err( 164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:786)
W/System.err( 164): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1030)
[/code]

add this permission to your android manifest file
[code] package="com.android.app.myapp" >



[/code]

References:
http://code.google.com/android/devel/security.html#permissions
http://code.google.com/android/reference/android/Manifest.permission.html#INTERNET

Τετάρτη 4 Φεβρουαρίου 2009

Always native look & feel

try {
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}

from http://www.dimitrisk.gr/blog/?p=8