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

CODE:

package swing_practicals;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Swing_Practicals extends JFrame implements ActionListener{

    JLabel lblname;

    JTextField txtname;

    JButton btnok;

    JPanel pnl;

    Swing_Practicals(){

        setVisible(true);

        setSize(500,500);

        setTitle("Kiran");

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

       lblname = new JLabel("Enter your name:");

        txtname = new JTextField(15);

     

        btnok = new JButton("OK");

 

        pnl = new JPanel();

        pnl.add(lblname);

        pnl.add(txtname);

        pnl.add(btnok);

        btnok.addActionListener(this);

        getContentPane().add(pnl,BorderLayout.NORTH);

        

    }

    

    public void actionPerformed(ActionEvent ae){

        String str = txtname.getText();

        JOptionPane.showMessageDialog(this,"Hi welcome "+str);

        txtname.setText("");

    }

    

    public static void main(String[] args) {

        new Swing_Practicals();

      

    }

    

}

 

OUTPUT:


Programs based on AWT and Swing.



Post a Comment

0 Comments