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

CODE:

package swing_practicals;

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

class con1 extends JFrame implements ActionListener

{

    JLabel lb1;

    JLabel lb2;

    JLabel lb3;

    JTextField j1;

    JTextField j2;

    JTextField j3;

    JButton btn;

    JButton btnc;

    JPanel jf;

    con1 ()

    {

        setDefaultCloseOperation(3);

        pack();

        setSize(300,200);

        setVisible(true);

        lb1 = new JLabel("Enter First String ");

        j1 = new JTextField(15);

        lb2 = new JLabel("Enter second String ");

        lb3 = new JLabel("Concated String ");

        j2 = new JTextField(15);

        j3 = new JTextField(30);

        j3.setEditable(false);

        btn = new JButton("concat");

        jf = new JPanel();

        jf.add(lb1);

        jf.add(j1);

        jf.add(lb2);

        jf.add(j2);

        jf.add(btn);

        jf.add(lb3);

        jf.add(j3);

        btn.addActionListener(this);

        getContentPane().add(jf,BorderLayout.CENTER);

    }

    public void actionPerformed(ActionEvent e)

    {

        String str1 = j1.getText();

        String str2 = j2.getText();

        String str3 = str1+str2;

            

        if(e.getSource()==btn)

        {

            j3.setText(str3);

        }

    }

    public static void main(String[] args) {

        con1 c = new con1();

    }

}

 

OUTPUT:


Programs based on AWT and Swing.

Programs based on AWT and Swing.

Post a Comment

0 Comments