write a java program with set Textbox and displaying the Text Box information and set the text box validation
import java.awt.*;
import java.awt.event.*; class Prog extends Frame implements ActionListener { Label la; TextField tf; Button sb; int x; String str; Prog() { setLayout(new FlowLayout()); x= 1; str=" "; la= new Label("Enter the Text:"); tf = new TextField(25); sb= new Button("Submit"); add(la); add(tf); add(sb); sb.addActionListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } public void actionPerformed(ActionEvent ae) { str=tf.getText(); String s= ae.getActionCommand(); if (s.equals("Submit")) { if(str.trim().length()==0) { x=0; repaint(); } else { x=1; repaint(); } } } public void paint(Graphics g) { if(x==0) g.drawString("Must Enter Text in Text Feild",100,200); if(x==1) g.drawString(" "+str,100,200); } public static void main( String args[]) { Prog p; p=new Prog(); p.setSize(400,500); p.setVisible(true); } } |