I was needing a way to change up some of my code so that when I sent out the application I could send it with no license key file and make the user put in the valid key. This way could have a basic installer and just send the key/keys along with the installer, telling them what to do. So I found the code below and worked it right in, and everything is just the way I wanted it now.
import javax.swing.JOptionPane;
public class JavaInputDialog
{
public static void main(String[]args)
{
//Pop up an input box with text ( What is your name ? )
String a=JOptionPane.showInputDialog(null,"What is your name ?");
//Print into command prompt what you put into input dialog box
System.out.println("My name is : "+a);
}
}
* Found this info at http://java2everyone.blogspot.com/2009/01/input-box-in-java.html, I am not trying to take credit for the info just listing it to share the info with other out there that might be looking for it as well.
The Java things that we learn
Saturday, August 11, 2012
Some Java code to Write to a file
How to
write java program to write to a file, we will use the class FileWriter and BufferedWriter to write to a file.
Class FileWriter
The FileWriter is a class used for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
BufferedWriter
The BufferWriter class is used to write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
Here is the code of java program to write text to a file:
import java.io.*;
class FileWrite
{
public static void main(String args[])
{
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
* this info was found at http://www.roseindia.net/java/beginners/java-write-to-file.shtml, I just found it really nice and simple and want to share it with more people as well. I am not trying to take the credit for the example.
Class FileWriter
The FileWriter is a class used for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
BufferedWriter
The BufferWriter class is used to write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
Here is the code of java program to write text to a file:
import java.io.*;
class FileWrite
{
public static void main(String args[])
{
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
* this info was found at http://www.roseindia.net/java/beginners/java-write-to-file.shtml, I just found it really nice and simple and want to share it with more people as well. I am not trying to take the credit for the example.
Friday, August 10, 2012
Having to learn Java
So over the last few months been racking more and more time with Java... I have not been liking it at all, it is so different from Perl. Well, tonight I was playing around with some of the code that I have and finally it starts to click more and more. I have to say here that lynda.com's videos has helped get me to where I am starting to get it and can see the logic. It is still going to take some time before I feel like I know it as well as I do Perl but hey still going to give it a go.
The other new things is all so putting in some time with PHP and Zend Framework. Have a project that is going on and needed to get to know the framework the out source company uses and how it all works and such just so that when the project is done with the out sourcing I can still keep everything running and such. It started out as a rocky road, but once again it has started to click as well, guess being a person that wanted to do every thing by hand to start with I do make it harder then it needs to be but I want to understnad all the moving parts so that if something goes wrong I can fix that part and not just break the whole thing and start the whole thing over again.
Oh well just have to keep going and learn it all.
The other new things is all so putting in some time with PHP and Zend Framework. Have a project that is going on and needed to get to know the framework the out source company uses and how it all works and such just so that when the project is done with the out sourcing I can still keep everything running and such. It started out as a rocky road, but once again it has started to click as well, guess being a person that wanted to do every thing by hand to start with I do make it harder then it needs to be but I want to understnad all the moving parts so that if something goes wrong I can fix that part and not just break the whole thing and start the whole thing over again.
Oh well just have to keep going and learn it all.
Subscribe to:
Comments (Atom)