/** *generic "About..." popup, along with licensing stuff * However, also planned to handle reading files, for trivial * "Help" window * * Note that this DOES NOT DISPOSE OF ITSELF.. it just makes * itself INVISIBLE, until you call setVisible(true) again. * * originally @version @(#) About.java 1.2@(#) * @author Philip Brown */ import java.awt.Frame; import java.awt.Button; import java.awt.Panel; import java.awt.TextArea; import java.awt.event.*; import java.io.*; class About extends Frame implements WindowListener,ActionListener { public void windowOpened(WindowEvent evt) { } public void windowClosing(WindowEvent evt) { setVisible(false); } public void windowClosed(WindowEvent evt) { } public void windowActivated(WindowEvent evt) { } public void windowDeactivated(WindowEvent evt) { } public void windowIconified(WindowEvent evt) { } public void windowDeiconified(WindowEvent evt) { } public void actionPerformed(ActionEvent e) { // we only have one possibility!! dismiss... windowClosing(null); } TextArea ta; void sharedinit() { ta = new TextArea(); ta.setEditable(false); ta.setColumns(62); ta.setRows(10); add(ta, "Center"); addWindowListener(this); Button dismiss = new Button("dismiss"); dismiss.addActionListener(this); Panel tmppanel = new Panel(); tmppanel.add(dismiss); add(tmppanel, "South"); } // little utility function, to load help files // This will load the file if we are in a directory, // OR if we are in a .jar file String fileToString(String filename) { InputStream fin=getClass().getResourceAsStream(filename); String filestring; byte buff[]; try { if(fin==null){ fin=new FileInputStream(filename); } buff=new byte[fin.available()]; fin.read(buff); } catch (java.io.IOException err) { return new String("Could not load help file\n"+err.getMessage()+"\n"); } filestring = new String(buff); return filestring; } /** * Popup for displaying text, for help info, etc. * Note that the file cannot contain more info than can * be held in a single String * * @param filename file to read in, for text * @param title what title to give this window */ public About(String filename, String title) { sharedinit(); setTitle(title); String filetext = fileToString(filename); ta.append(filetext); } /** * Basic constructor, hardcoded with some info */ public About() { sharedinit(); setTitle("About box"); ta.append("This is a program written by Philip Brown"); ta.append(" (phil@bolthole.com)\n"); ta.append("You may use it, copy it for yourself, or others, at no charge\n"); ta.append("You may NOT, however:\n"); ta.append(" a) claim it is yours, or you wrote it\n"); ta.append(" b) sell it\n"); ta.append(" c) modify it in any way\n"); ta.append(" without consent from the author\n"); ta.append("No guarantee is made about this software\n"); ta.append("No liability of any kind is assumed by the author, etc, etc\n"); ta.append("\n The above weasel-words are here for two reasons:\n"); ta.append(" 1. to deter criminal activity\n"); ta.append(" 2. to prevent splintering of distributions\n"); ta.append("If you have suggestions, or would even like to add some\n"); ta.append("code, please let me know\n"); } }