8) Write a JAVA program to design a screen using Awt :


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

public class StringOperation extends Frame implements ActionListener
{
Label lbl1,lbl2,lbl3,lbl4,lbl5;
Button Change,Clear;
TextField text1,text2,text3,text4,text5;
public StringOperation()
{
lbl1=new Label(“Enter the String”,Label.LEFT);
lbl2=new Label(“Upper Case “,Label.LEFT);
lbl3=new Label(“Lower Case ” ,Label.LEFT);
lbl4=new Label(“Bold Case “,Label.LEFT);
lbl5=new Label(“Italic Case “,Label.LEFT);
Change=new Button(“Change Case”);
Clear=new Button(“Clear”);
text1=new TextField(20);
text1.setSize(5,5);
text2=new TextField(20);
text3=new TextField(20);
text4=new TextField(20);
text5=new TextField(20);
setLayout(new BorderLayout());
Panel p=new Panel();
p.add(lbl1);
p.add(text1);
p.add(lbl2);
p.add(text2);
p.add(lbl3);
p.add(text3);
p.add(lbl4);
p.add(text4);
p.add(lbl5);
p.add(text5);
p.add(Change);
p.add(Clear);
add(p,BorderLayout.CENTER);
Change.addActionListener(this);
Clear.addActionListener(this);
setTitle(“String Demo…”);
setVisible(true);
setResizable(false);
setSize(300,400);
}

public void actionPerformed (ActionEvent ae)
{
Button btn=(Button)ae.getSource();
String str=text1.getText();

if(btn==Change)
{
text2.setText(str.toUpperCase());
text3.setText(str.toLowerCase());
Font f=new Font(“Arial”,Font.BOLD,13);
text4.setFont(f);
text4.setText(str);
Font f1=new Font(“Arial”,Font.ITALIC,13);
text5.setFont(f1);
text5.setText(str);
}
if(btn==Clear)
{
text1.setText(“”);
text2.setText(“”);
text3.setText(“”);
text4.setText(“”);
text5.setText(“”);
}
}
public static void main(String args[])
{
StringOperation sn=new StringOperation();
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s