Programs based on AWT and Swing.

a.Develop AWT application to implement basic arithmetic operation.

CODE:

import java.awt.*;

import java.awt.event.*;

public class calci extends Frame implements ItemListener

{

Label lbl1,lbl2,lblMsg;

TextField txt1,txt2;

Checkbox cbAdd,cbSub,cbMul,cbDiv,cbMod;

CheckboxGroup cbg;

Panel p1,p2;

 

calci(){

 

lbl1 = new Label("Enter First Number:");

txt1 = new TextField(15);

lbl2 = new Label("Enter Second Number:");

txt2 = new TextField(15);

lblMsg = new Label();

p1 = new Panel();

p2 = new Panel();

p1.setLayout(new GridLayout(2,2));

p2.setLayout(new GridLayout(3,3));

cbg = new CheckboxGroup();

cbAdd = new Checkbox("+",cbg,true);

cbSub = new Checkbox("-",cbg,false);

cbMul = new Checkbox("*",cbg,false);

cbDiv = new Checkbox("/",cbg,false);

cbMod = new Checkbox("%",cbg,false);

cbAdd.addItemListener(this);

cbSub.addItemListener(this);

cbMul.addItemListener(this);

cbDiv.addItemListener(this);

cbMod.addItemListener(this);

p1.add(lbl1);

p1.add(txt1);

p1.add(lbl2);

p1.add(txt2);

p2.add(cbAdd);

p2.add(cbSub);

p2.add(cbMul);

p2.add(cbDiv);

p2.add(cbMod);

p2.add(lblMsg);

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent we)

{

System.exit(0);

}

});

setSize(350,200);

setVisible(true);

add(p1,BorderLayout.NORTH);

add(p2,BorderLayout.CENTER);

}

public void itemStateChanged(ItemEvent ie)

{

int a=Integer.parseInt(txt1.getText());

int b=Integer.parseInt(txt2.getText());

lblMsg.setText("");

 

Object obj = ie.getItemSelectable();

Checkbox cb = (Checkbox) obj;

if(cb.getState())

{

if(cb.getLabel().equals("+"))

lblMsg.setText("Result is "+(a+b));

else if(cb.getLabel().equals("-"))

lblMsg.setText("Result is "+(a-b));

else if(cb.getLabel().equals("*"))

lblMsg.setText("Result is "+(a*b));

else if(cb.getLabel().equals("/"))

lblMsg.setText("Result is "+(a/b));

else if(cb.getLabel().equals("%"))

lblMsg.setText("Result is "+(a%b));

}}

    public static void main(String[] args) {

new calci();

}}              

OUTPUT:

Programs based on AWT and Swing.



b.Develop swing application  to take input user from TextField and show in dialogue box.

c.Illustration of TextArea Component. Take input from user in TextField and add it to TextArea.

d.Program on TextArea with copy,cut and paste buttons.

e.Develop swing application login form accept Username and Password , on click show successful or unsuccessful depending on input.

f. Develop swing application to present set of choices for a user to select different colours, on selection of colour the background of application changes its colour respectively.

g. Develop swing application to present set of choices for a user to select stationary product and display the prize of product after selection from list.

h. Program to illustrate the use of JComboBox.

i. Develop swing application to concatenate two strings entered in TextField, on click of the command button, concatenated string should display in third TextField.

j.Develop swing application to display factorial of given number.











Post a Comment

0 Comments