import java.awt.*; import oracle.jdeveloper.layout.*; import java.awt.event.*; public class Validations extends Frame { XYLayout xYLayout1 = new XYLayout(); public Label l_UserName = new Label(); TextField tf_UserName = new TextField(); Label l_Increments = new Label(); TextField tf_Increments = new TextField(); Button Save = new Button(); public Validations() { super(); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { this.setTitle("Validation Frame"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); l_UserName.setText("User Name"); l_Increments.setText("Increments"); Save.setLabel("Save"); Save.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { Save_actionPerformed(e); } }); tf_Increments.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(KeyEvent e) { tf_Increments_keyTyped(e); } }); this.setLayout(xYLayout1); this.setSize(new Dimension(400, 300)); this.setBackground(SystemColor.control); this.add(l_UserName, new XYConstraints(14, 48, 73, 25)); this.add(tf_UserName, new XYConstraints(134, 54, 102, 29)); this.add(l_Increments, new XYConstraints(17, 117, 79, 31)); this.add(tf_Increments, new XYConstraints(143, 113, 106, 32)); this.add(Save, new XYConstraints(109, 197, 66, 23)); } void this_windowClosing(WindowEvent e) { System.exit(0); } void tf_Increments_keyTyped(KeyEvent e) { char ch=e.getKeyChar(); if(!('0'<= ch && ch<='9')) e.consume(); } void Save_actionPerformed(ActionEvent e) { String arg=e.getActionCommand(); if(arg=="Save") { String arg1=tf_UserName.getText(); String arg2=tf_Increments.getText(); System.out.println(""+arg1); System.out.println(""+arg2); if(arg1.length()==0 ) { System.out.println("In Save_actionPerformed"); EDialog ED=new EDialog(this,"Error",true,l_UserName.getText()); System.out.println(""+l_UserName.getText()); tf_UserName.requestFocus(); ED.show(); // tf_UserName.getFocus(); } else if(arg2.length()==0) { EDialog ED=new EDialog(this,"Error",true,l_Increments.getText()); tf_Increments.requestFocus(); ED.show(); } } } }