Thursday, April 3, 2014

Java program on swing package

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class MyJFrame extends JFrame
{

JLabel jl1=new JLabel("Name");
JButton jb1=new JButton("Click Now");
JTextField jt1=new JTextField("Type Here",20);
JPanel pnl=new JPanel();
JPanel pnl2=new JPanel();
Container c;
public MyJFrame(String title)
{
super(title);
c=getContentPane();
setSize(300,200);
pnl.add(jl1);
pnl.add(jt1);
pnl2.add(jb1);
c.add("North",pnl);
c.add("South",pnl2);

jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jb1)
{
jb1.setText("Your Name is :"+jt1.getText());
//jb1.invalidate();
jt1.setText(jb1.getText());
}
}
});
}
public  static void main(String[] args)
{
JFrame j=new MyJFrame(args[0]);
j.show();
j.setVisible(true);
}
}
}

No comments:

Post a Comment