// minister.java, by jeffery // abstract the questioning of the ruler // use Swing if available, else console. import javax.swing.*; import java.io.*; public class minister { boolean use_swing; BufferedReader in; public int ask(String prompt) { int i=0; if (use_swing) { return Integer.parseInt(JOptionPane.showInputDialog(null,prompt)); } else { System.out.println(prompt); try { i = Integer.parseInt(in.readLine()); } catch (IOException e) { System.out.println("can't read: "); } return i; } } public void tell(String s) { if (use_swing) { JOptionPane.showMessageDialog(null, s); } else { System.out.println(s); } } public minister() { use_swing = true; try { JOptionPane.showMessageDialog(null, "Minister says we are swinging"); } catch (java.lang.OutOfMemoryError e) { System.out.println("Minister says oh joy, let's use the console."); use_swing = false; } catch (Exception e) { System.out.println("Minister says we are using the console."); use_swing = false; } in = new BufferedReader(new InputStreamReader(System.in)); } }