import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
class Demo1 extends JFrame implements KeyListener{
JTextField jt;
JLabel jl;
Demo1(){
jt=new JTextField(15);
jl=new JLabel("Enter String ");
Container c=getContentPane();
c.setLayout(new FlowLayout());
setSize(500,500);
c.add(jl);
c.add(jt);
jt.addKeyListener(this);
}
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode()>=65 && e.getKeyCode()<=91){
//jt.setText(e.getKeyCode());
jt.setText("");
String s=jt.getText();
int l=s.length();
s=s.substring(0,l-1);
jt.setText(s);
}else
{
}
}
}
public class Textbox {
public static void main(String arg[]){
Demo1 d=new Demo1();
d.setVisible(true);
}
}
A blog provide anexample with sample code for swing , servlet, jdbc and odbc connection to database, jsp, servlets, taglib, sql server, cassandra and many more. we also provide Apache camel sample code for integration.
Sunday, November 4, 2012
Textbox with only number
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment