Java Pgm14

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Ex No.

24
Date:
Text Formating
Aim:
To write a java program to perform the text formatting operations in app
let.
Source Code:
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class textformat extends Applet implements ActionListener
{
Label text,result;
TextField res,resp;
Button b,i,r;
String s;
Font fb,fi,fr;
public void init( )
{
setBackground(Color.pink);
text=new Label("Enter the text");
add(text);
res=new TextField(12);
add(res);
b=new Button("BOLD");
add(b);
i=new Button("ITALIC");
add(i);
r=new Button("REGULAR");
add(r);
result=new Label("RESULT");
add(result);
resp=new TextField(12);
add(resp);
fb=new Font("",Font.BOLD,12);
fi=new Font("",Font.ITALIC,12);
fr=new Font("",Font.PLAIN,12);
b.addActionListener(this);
i.addActionListener(this);
r.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand( );
s=res.getText( );
resp.setText(s);
if(str.equals("BOLD"))
resp.setFont(fb);
else if(str.equals("ITALIC"))
resp.setFont(fi);
else if(str.equals("REGULAR"))
resp.setFont(fr);
repaint( );
}
}
/*<applet code="textformat.class" width=300 height=400> </applet> */
Output:
Javac textformat.java
Appletviewer textformat.java

Result:
Thus a java program has been written to perform text formatting operatio
ns.

You might also like