source file name: ButtonLabelDemo.java
import java.awt.event.*;
import javax.swing.*;
class ButtonLabelDemo extends JFrame implements ActionListener
{
JLabel txtlb;
public ButtonLabelDemo()
{
setLayout(null);
JButton bt=new JButton("Click");
txtlb=new JLabel();
bt.setBounds(50,50, 100,30);
txtlb.setBounds(50,100,250,30);
add(bt);add(txtlb);
bt.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
txtlb.setText("Welcome to Java Programming");
}
public static void main(String[] args)
{
ButtonLabelDemo f=new ButtonLabelDemo();
f.setTitle(" Swing Label & Button program");
f.setSize(400,400);
f.setVisible(true);
}
}
output:
0 Comments
Post a Comment