import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class textfield1 extends JApplet implements FocusListener,ActionListener{
static final int BoldAction = 0;
JTextField t1,t2,t3,t4,t5,t6,t7;
JButton b1,b2;
public void init(){
t1=new JTextField("hello");
add(t1);
setLayout(null);
t1.setBounds(30,30,100,30);
t1.selectAll();
t1.setSelectionColor(Color.red);
t1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
t1.setBackground(Color.cyan);
}
}
);
t2=new JTextField(20);
add(t2);
setLayout(null);
t2.setBounds(140,30,170,30);
t2.selectAll();
t2.setSelectionColor(Color.BLUE);
t2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t2.setText("Yes You Clicked On Enter");
}
});
t3=new JTextField("Words Entered Already");
add(t3);
setLayout(null);
t3.setBounds(330,30,500,30);
t3.selectAll();
t3.setSelectionColor(Color.BLUE);
t3.setHorizontalAlignment(JTextField.LEFT);
t3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t3.setText("Words Entered Already Thanx For Click Again");
if(t3.getHorizontalAlignment()==JTextField.LEFT)
t3.setHorizontalAlignment(JTextField.CENTER);
else if(t3.getHorizontalAlignment()==JTextField.CENTER)
t3.setHorizontalAlignment(JTextField.RIGHT);
else if(t3.getHorizontalAlignment()==JTextField.RIGHT)
t3.setHorizontalAlignment(JTextField.LEFT);
}
});
t4=new JTextField("When you click on enter Thil text will hide");
add(t4);
setLayout(null);
t4.setBounds(630,90,500,30);
t4.selectAll();
t4.setSelectionColor(Color.RED);
t4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t4.setText("");
}
});
t5=new JTextField("Enter First name");
t6=new JTextField("Enter Last name");
add(t5);
add(t6);
setLayout(null);
t5.setBounds(40,160,500,30);
t6.setBounds(40,200,500,30);
t5.selectAll();
t6.selectAll();
t5.setSelectionColor(Color.cyan);
t6.setSelectionColor(Color.cyan);
t5.addFocusListener(this);
t6.addFocusListener(this);
t7=new JTextField("Click here for type");
add(t7);
setLayout(null);
t7.setBounds(530,330,500,30);
t7.selectAll();
t7.setSelectionColor(Color.RED);
b1=new JButton("Int");
b2=new JButton("Char");
add(b1);
add(b2);
b1.setBounds(530, 380, 100, 30);
b2.setBounds(650, 380, 100, 30);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource()==t5)
{
t6.setText("Lname");
t5.selectAll();
}
else if(arg0.getSource()==t6)
{
t5.setText("Fname");
t6.selectAll();
}
}
@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
t5.setText("Now Type here For Enter First Name");
t6.setText("Now Type here For Enter Last Name");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1)
{
JOptionPane.showMessageDialog(null, "Please Enter numeric values");
}
if(e.getSource()==b2)
{
JOptionPane.showMessageDialog(null, "Please Enter Char Values");
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class textfield1 extends JApplet implements FocusListener,ActionListener{
static final int BoldAction = 0;
JTextField t1,t2,t3,t4,t5,t6,t7;
JButton b1,b2;
public void init(){
t1=new JTextField("hello");
add(t1);
setLayout(null);
t1.setBounds(30,30,100,30);
t1.selectAll();
t1.setSelectionColor(Color.red);
t1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
t1.setBackground(Color.cyan);
}
}
);
t2=new JTextField(20);
add(t2);
setLayout(null);
t2.setBounds(140,30,170,30);
t2.selectAll();
t2.setSelectionColor(Color.BLUE);
t2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t2.setText("Yes You Clicked On Enter");
}
});
t3=new JTextField("Words Entered Already");
add(t3);
setLayout(null);
t3.setBounds(330,30,500,30);
t3.selectAll();
t3.setSelectionColor(Color.BLUE);
t3.setHorizontalAlignment(JTextField.LEFT);
t3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t3.setText("Words Entered Already Thanx For Click Again");
if(t3.getHorizontalAlignment()==JTextField.LEFT)
t3.setHorizontalAlignment(JTextField.CENTER);
else if(t3.getHorizontalAlignment()==JTextField.CENTER)
t3.setHorizontalAlignment(JTextField.RIGHT);
else if(t3.getHorizontalAlignment()==JTextField.RIGHT)
t3.setHorizontalAlignment(JTextField.LEFT);
}
});
t4=new JTextField("When you click on enter Thil text will hide");
add(t4);
setLayout(null);
t4.setBounds(630,90,500,30);
t4.selectAll();
t4.setSelectionColor(Color.RED);
t4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t4.setText("");
}
});
t5=new JTextField("Enter First name");
t6=new JTextField("Enter Last name");
add(t5);
add(t6);
setLayout(null);
t5.setBounds(40,160,500,30);
t6.setBounds(40,200,500,30);
t5.selectAll();
t6.selectAll();
t5.setSelectionColor(Color.cyan);
t6.setSelectionColor(Color.cyan);
t5.addFocusListener(this);
t6.addFocusListener(this);
t7=new JTextField("Click here for type");
add(t7);
setLayout(null);
t7.setBounds(530,330,500,30);
t7.selectAll();
t7.setSelectionColor(Color.RED);
b1=new JButton("Int");
b2=new JButton("Char");
add(b1);
add(b2);
b1.setBounds(530, 380, 100, 30);
b2.setBounds(650, 380, 100, 30);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource()==t5)
{
t6.setText("Lname");
t5.selectAll();
}
else if(arg0.getSource()==t6)
{
t5.setText("Fname");
t6.selectAll();
}
}
@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
t5.setText("Now Type here For Enter First Name");
t6.setText("Now Type here For Enter Last Name");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1)
{
JOptionPane.showMessageDialog(null, "Please Enter numeric values");
}
if(e.getSource()==b2)
{
JOptionPane.showMessageDialog(null, "Please Enter Char Values");
}
}
}
No comments:
Post a Comment