For my school, we use these two classes.
I don't really know if these are releases, but here.
Okay.
Code for IO class.
How to use :Code:import java.io.*; import javax.swing.*; public class IO{ public static int getInt(String message){ String s = JOptionPane.showInputDialog(message); int num; try{ num = Integer.parseInt(s.trim()); //convert String s to an int System.out.println(message+": "+num); }catch(NumberFormatException e){ //test for bad input num=0; System.err.println(e.toString()); //error message System.exit(0); //stop program } return num; } public static double getDouble(String message){ String s = JOptionPane.showInputDialog(message); double num; try{ num = Double.parseDouble(s.trim()); //convert String s to an int System.out.println(message+": "+num); }catch(NumberFormatException e){ //test for bad input num=0; System.err.println(e.toString()); //error message System.exit(0); //stop program } return num; } public static String getString(String message){ String s = JOptionPane.showInputDialog(message); System.out.println(message+": "+s); return s; } public static char getChar(String message){ String s = JOptionPane.showInputDialog(message); if(s.length()==0){ System.out.println(message+": "); return '\0';//null char }else{ System.out.println(message+": "+ s.charAt(0)); return s.charAt(0); //first char } } public static void println(String message){ System.out.println(message); JOptionPane.showMessageDialog(null, message); } }
First, save this anywhere (preferably in the folder where you save your java programs).
Second, you have to use the IO like this, Don't really know how to say it, so I'll show you.
Okay, now to explain it. It's pretty much self - expanitory, unless you don't know anything about Java. The variable word is IO.getString <make note that the new class is IO.getString> with parentheses showing "Enter word" . This basically just lets you enter any word, without having to change the variable a million times. It can just be "word".Code:public class MyFirstProgram { public static void main(String[] args) { String word; word = IO.getString("Enter word") ; System.out.println(word); } }
Try it, I can't really get a pic right now, so I'll get it later.
Now, DoAgain.
Basically, just doAgain. Just like it says, the code just makes you do it again, basically you don't have to run a million times.Code:import javax.swing.*; public class Doagain{ public Doagain(){} public static boolean ask(){ return ask("Another? "); } public static boolean ask(String message){ String again; do{ again = JOptionPane.showInputDialog(message+" y or n? "); System.out.println(message+" y or n? "+ again); }while(again.compareTo("y") !=0 && again.compareTo("n") !=0); return again.compareTo("y") == 0; } }
(This is good use with the IO.getString)
How to use,
Okay, just put the bold stuff on, and that is really all to it.Code:public class MyFirstProgram { public static void main(String[] args) { String word; do { word = IO.getString("Enter word") ; System.out.println(word); }while(Doagain.ask()) ; } }
Make sure the do {
Is always after you set all the variables.
Well, yea this is all the releases~
Have fun with it.
One more thing~
Must save all these things as .java~!!


Reply With Quote![[Java] IO class + Doagain class](http://ragezone.com/hyper728.png)


