That has little to do with your program but much more with your operation system. You must register it to associate a file type with your program. It's probably easier to use an installer which handles that for you.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
It does have a little to do with your application. It must be able to handle command line arguments to pass the text file to open. You can use args from the main method (if args.length > 0) as the file to open.
You then need to set up a file association which calls your application. The command would be That %1 is the first argument to the file association handler. You enclose it in double quotes so that your JVM will receive it as one command if the file name has spaces in it.