TextEvent

Google Advertisements

Prev Tutorial Next Tutorial

Event Handling for TextField

TextEvent class and TextListener interface are associated with both textfield and textarea. If we want to performed any operation, if the value of textfield and textarea are changed than the logic should be written in the textValueChanged().

GUI ComponentEvent classListener InterfaceMethod (abstract method)
TextFieldTextEventTextListenerpublic void textValueChanged(TextEvent e)

Example of TextEvent

import java.awt.*;
import java.awt.event.*;

class TextEventEx extends Frame implements TextListener
{
TextField tf1,tf2,tf3;
Label l1,l2,l3;
String nm="",xc="",yc="";
int x,y;
Panel p1;
TextEventEx()
{		
setBackground(Color.cyan);
p1=new Panel();
p1.setBackground(Color.yellow);
l1=new Label("Name");
l2=new Label("X-axies");
l3=new Label("y-aixes");

tf1=new TextField(15);
tf2=new TextField(5);
tf3=new TextField(5);
		    
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
add("North",p1);
		
tf1.addTextListener(this);
tf2.addTextListener(this);
tf3.addTextListener(this);
}

public void textValueChanged(TextEvent e)
{
nm=tf1.getText();
xc=tf2.getText();
x=Integer.parseInt(xc);
yc=tf3.getText();
y=Integer.parseInt(yc);
repaint();
}

public  void paint(Graphics g)
{
setFont(new Font("TimesRoman",Font.BOLD,30));
g.setColor(Color.red);
g.drawString("Name"+nm,x,y);
}

public static void main(String args[])
{
TextEventEx t=new TextEventEx();
Toolkit tx=Toolkit .getDefaultToolkit();
t.setSize(tx.getScreenSize());
t.setVisible(true);
}
}

Download code Click

textevent example
Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs