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 @$50 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

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs