import java.awt.*; import java.io.*; import java.util.*; import oracle.jdeveloper.layout.*; import java.awt.event.*; public class DBAdminFrame extends Frame { Label lblDCU = new Label(); TextField txtDCU = new TextField(); Label lblUserName = new Label(); TextField txtUserName = new TextField(); Label lblPassword = new Label(); TextField txtPassword = new TextField(); Label lblDCN = new Label(); TextField txtDCN = new TextField(); Label lblInitCon = new Label(); TextField txtInitCon = new TextField(); Label lblIncr = new Label(); TextField txtIncr = new TextField(); Panel pnlControl = new Panel(); Button btnUpdate = new Button(); XYLayout xYLayout1 = new XYLayout(); Button btnCancel = new Button(); Label lblStatInitCon = new Label(); TextField txtStatInitCon = new TextField(); Label lblStatIncr = new Label(); TextField txtStatIncr = new TextField(); public DBAdminFrame() { super(); try { jbInit(); Properties props = getProperties(); fillProperties(props); } catch (Exception e) { e.printStackTrace(); } } private void fillProperties(Properties props){ if(props.getProperty("DBConURL") != null){ txtDCU.setText(props.getProperty("DBConURL")); txtUserName.setText(props.getProperty("UName")); txtPassword.setText(props.getProperty("PWord")); txtDCN.setText(props.getProperty("DClassName")); txtInitCon.setText(props.getProperty("InitCon")); txtIncr.setText(props.getProperty("Incr")); txtStatInitCon.setText(props.getProperty("StatInitCon")); txtStatIncr.setText(props.getProperty("StatIncr")); } } private Properties getProperties(){ boolean found = true; Properties props=null; ObjectInputStream oin=null; FileInputStream in=null; try{ in=new FileInputStream("DBProperties.props"); } catch(FileNotFoundException ex){ System.out.println("File not found "+ ex.getMessage()); try{ FileOutputStream fos = new FileOutputStream("DBProperties.props"); in=new FileInputStream("DBProperties.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 { lblDCU.setText("Db Connection URL"); lblUserName.setText("User Name"); lblPassword.setText("Password"); lblDCN.setText("Driver Class Name"); lblInitCon.setText("Initial Connections"); txtInitCon.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(KeyEvent e) { txtInitCon_keyTyped(e); } }); lblIncr.setText("Increment"); txtIncr.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(KeyEvent e) { txtIncr_keyTyped(e); } }); btnUpdate.setLabel("Update"); btnUpdate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnUpdate_actionPerformed(e); } }); xYLayout1.setHeight(333); btnCancel.setLabel("Cancel"); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnCancel_actionPerformed(e); } }); lblStatInitCon.setText("StatusInitialConnections"); txtStatInitCon.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(KeyEvent e) { txtStatInitCon_keyTyped(e); } }); lblStatIncr.setText("Status Increments"); xYLayout1.setWidth(387); this.setTitle("DB Server Administration"); this.setLayout(xYLayout1); this.setSize(new Dimension(387, 306)); this.setBackground(SystemColor.control); this.add(lblDCU, new XYConstraints(7, 55, 149, -1)); this.add(txtDCU, new XYConstraints(156, 55, 195, -1)); this.add(lblUserName, new XYConstraints(6, 78, 150, -1)); this.add(txtUserName, new XYConstraints(156, 78, 195, -1)); this.add(lblPassword, new XYConstraints(6, 101, 150, -1)); this.add(txtPassword, new XYConstraints(156, 101, 195, -1)); this.add(lblDCN, new XYConstraints(7, 124, 149, -1)); this.add(txtDCN, new XYConstraints(156, 124, 195, -1)); this.add(lblInitCon, new XYConstraints(7, 147, 149, -1)); this.add(txtInitCon, new XYConstraints(156, 147, 195, -1)); this.add(lblIncr, new XYConstraints(7, 170, 149, -1)); this.add(txtIncr, new XYConstraints(156, 170, 195, -1)); this.add(pnlControl, new XYConstraints(37, 244, -1, -1)); this.add(btnUpdate, new XYConstraints(93, 253, -1, -1)); this.add(btnCancel, new XYConstraints(195, 252, 67, -1)); this.add(lblStatInitCon, new XYConstraints(7, 193, 121, 21)); this.add(txtStatInitCon, new XYConstraints(154, 195, 199, 22)); this.add(lblStatIncr, new XYConstraints(8, 215, 135, 19)); this.add(txtStatIncr, new XYConstraints(154, 218, 197, 22)); } void btnUpdate_actionPerformed(ActionEvent e) { Properties props = prepareProperties(); writeProperties(props); String arg1=txtDCU.getText(); String arg2=txtUserName.getText(); String arg3=txtPassword.getText(); String arg4=txtDCN.getText(); String arg5=txtInitCon.getText(); String arg6=txtIncr.getText(); String arg7= txtStatInitCon.getText(); String arg8= txtStatIncr.getText(); if(arg1.length()==0 ) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblDCU.getText()); txtDCU.requestFocus(); ED.show(); } else if(arg2.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblUserName.getText()); txtUserName.requestFocus(); ED.show(); } else if(arg3.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblPassword.getText()); txtPassword.requestFocus(); ED.show(); } else if(arg4.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblDCN.getText()); txtDCN.requestFocus(); ED.show(); } else if(arg5.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblInitCon.getText()); txtInitCon.requestFocus(); ED.show(); } else if(arg6.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblIncr.getText()); txtIncr.requestFocus(); ED.show(); } else if(arg7.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblStatInitCon.getText()); txtStatInitCon.requestFocus(); ED.show(); } else if(arg8.length()==0) { FMErrorDialog ED=new FMErrorDialog(this,"Error",true,lblStatIncr.getText()); txtStatIncr.requestFocus(); ED.show(); } else {System.exit(0);} } private Properties prepareProperties(){ Properties props = new Properties(); props.put("DBConURL", txtDCU.getText()); props.put("UName", txtUserName.getText()); props.put("PWord", txtPassword.getText()); props.put("DClassName", txtDCN.getText()); props.put("InitCon", txtInitCon.getText()); props.put("Incr", txtIncr.getText()); props.put("StatInitCon", txtStatInitCon.getText()); props.put("StatIncr", txtStatIncr.getText()); return props; } private void writeProperties(Properties props){ FileOutputStream fstream = null; ObjectOutputStream ostream = null; try{ fstream = new FileOutputStream("DBProperties.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 btnCancel_actionPerformed(ActionEvent e) { System.exit(0); } void txtInitCon_keyTyped(KeyEvent e) { char ch; ch=e.getKeyChar(); if(!('0'<= ch && ch<='9')) { e.consume();} } void txtIncr_keyTyped(KeyEvent e) { char ch; ch=e.getKeyChar(); if(!('0'<= ch && ch<='9')) { e.consume();} } void txtStatInitCon_keyTyped(KeyEvent e) { char ch; ch=e.getKeyChar(); if(!('0'<= ch && ch<='9')) { e.consume();} } void txtStatIncr_keyTyped(KeyEvent e) { char ch; ch=e.getKeyChar(); if(!('0'<= ch && ch<='9')) { e.consume();} } }