import java.awt.*; import java.io.*; import java.util.*; import oracle.jdeveloper.layout.*; import java.awt.event.*; public class FMAdminFrame extends Frame implements WindowListener{ Label lblPath = new Label(); TextField txtPath = new TextField(); Label lblSent = new Label(); TextField txtSent = new TextField(); Label lblInBox = new Label(); TextField txtInBox = new TextField(); Label lblOffLine = new Label(); TextField txtOffLine = new TextField(); Panel pnlControl = new Panel(); Button btnUpdate = new Button(); Button btnCancel = new Button(); XYLayout xYLayout1 = new XYLayout(); Button btnBrowse = new Button(); FileDialog FD; FMErrorDialog ED; public FMAdminFrame() { super(); try { jbInit(); Properties props = getProperties(); fillProperties(props); } catch (Exception e) { e.printStackTrace(); } } private void fillProperties(Properties props){ if(props.getProperty("Path") != null){ txtPath.setText(props.getProperty("Path")); txtSent.setText(props.getProperty("SFN")); txtInBox.setText(props.getProperty("IFN")); txtOffLine.setText(props.getProperty("OFN")); } } private Properties getProperties(){ boolean found = true; Properties props=null; ObjectInputStream oin=null; FileInputStream in=null; try{ in=new FileInputStream("FMProperties.props"); } catch(FileNotFoundException ex){ System.out.println("File not found "+ ex.getMessage()); try{ FileOutputStream fos = new FileOutputStream("FMProperties.props"); in=new FileInputStream("FMProperties.props"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(new Properties()); oos.flush(); fos.close(); } catch(FileNotFoundException subEx){ System.out.println("File not found "+ ex.getMessage()); found=false; } catch(IOException subEx){ System.out.println("File not found "+ ex.getMessage()); } } catch(SecurityException ex){System.out.println("Security exception-I "+ex.getMessage());} if(found){ try{ oin=new ObjectInputStream(in); } catch(StreamCorruptedException ex){ System.out.println("StreamCorruptedException-I "+ex.getMessage()); } catch(IOException ex){ System.out.println("IOException-I "+ex.getMessage()); } try{ props=(Properties)oin.readObject(); } catch(ClassNotFoundException ex){ System.out.println("ClassNotFoundException "+ex.getMessage()); } catch(InvalidClassException ex){ System.out.println("InvalidClassException "+ex.getMessage()); } catch(StreamCorruptedException ex){ System.out.println("StreamCorruptedException-II "+ex.getMessage()); } catch(OptionalDataException ex){ System.out.println("OPtionalDataException "+ex.getMessage()); } catch(IOException ex){ System.out.println("IOException-II "+ex.getMessage()); } } return props; } private void jbInit() throws Exception { addWindowListener(this); lblPath.setText("Path"); lblSent.setText("Sent Folder"); lblInBox.setText("InBox Folder"); lblOffLine.setText("OffLine Folder"); btnUpdate.setLabel("Update"); btnUpdate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnUpdate_actionPerformed(e); } }); btnCancel.setLabel("Cancel"); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnCancel_actionPerformed(e); } }); btnBrowse.setLabel("Browse"); btnBrowse.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnBrowse_actionPerformed(e); } }); this.setTitle("File Server Administration"); this.setLayout(xYLayout1); this.setSize(new Dimension(387, 306)); this.setBackground(SystemColor.control); this.add(lblPath, new XYConstraints(28, 55, 128, -1)); this.add(txtPath, new XYConstraints(156, 55, 195, -1)); this.add(lblSent, new XYConstraints(28, 78, 128, -1)); this.add(txtSent, new XYConstraints(156, 78, 195, -1)); this.add(lblInBox, new XYConstraints(28, 101, 128, -1)); this.add(txtInBox, new XYConstraints(156, 101, 195, -1)); this.add(lblOffLine, new XYConstraints(28, 124, 128, -1)); this.add(txtOffLine, new XYConstraints(156, 124, 195, -1)); this.add(pnlControl, new XYConstraints(28, 193, 323, 31)); pnlControl.add(btnBrowse, null); pnlControl.add(btnUpdate, null); pnlControl.add(btnCancel, null); } void btnUpdate_actionPerformed(ActionEvent e) { Properties props = prepareProperties(); writeProperties(props); String arg=e.getActionCommand(); if(arg=="Update") { String arg1=txtPath.getText(); String arg2=txtSent.getText(); String arg3=txtInBox.getText(); String arg4=txtOffLine.getText(); if(arg1.length()==0 ) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblPath.getText()); ED.show(); } else if(arg2.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblSent.getText()); ED.show(); } else if(arg3.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblInBox.getText()); ED.show(); } else if(arg4.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblOffLine.getText()); ED.show(); } else {System.exit(0);} } } private Properties prepareProperties(){ Properties props = new Properties(); props.put("Path", txtPath.getText()); props.put("SFN", txtSent.getText()); props.put("IFN", txtInBox.getText()); props.put("OFN", txtOffLine.getText()); // props.put("InitCon", txtInitCon.getText()); // props.put("Incr", txtIncr.getText()); return props; } private void writeProperties(Properties props){ FileOutputStream fstream = null; ObjectOutputStream ostream = null; try{ fstream = new FileOutputStream("FMProperties.props"); } catch(IOException ex){System.out.println("IOException-III "+ex.getMessage());} catch(SecurityException ex){System.out.println("Security exception-II "+ex.getMessage());} try{ ostream = new ObjectOutputStream(fstream); } catch(IOException ex){ System.out.println("IOException-IV "+ex.getMessage()); } try{ ostream.writeObject(props); } catch(InvalidClassException ex){ System.out.println("InvalidClassException-II "+ex.getMessage()); } catch(NotSerializableException ex){ System.out.println("NotSerializableException "+ex.getMessage()); } catch(IOException ex){ System.out.println("IOException-V "+ex.getMessage()); } try{ ostream.flush(); } catch(IOException ex){ System.out.println("IOException-VI "+ex.getMessage()); } try{ fstream.close(); ostream.close(); } catch(IOException ex){ System.out.println("IOException-VI "+ex.getMessage()); } } void btnBrowse_actionPerformed(ActionEvent e) { FD=new FileDialog(this,"File Dialog Box"); FD.show(); txtPath.setText(FD.getDirectory()); } public void windowActivated(WindowEvent evt) { try{ FileInputStream fis=new FileInputStream("FMProperties.props"); ObjectInputStream ois=new ObjectInputStream(fis); Properties pr=new Properties(); pr=(Properties)ois.readObject(); fillProperties(pr);} catch(Exception exp){} } public void windowClosed(WindowEvent e){} public void windowOpened(WindowEvent e){} public void windowClosing(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowIconified(WindowEvent e){} void btnCancel_actionPerformed(ActionEvent e) { System.exit(0); } }