import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class eventdemo
{
JButton b1;
JLabel l1;
eventdemo()
{
JFrame j=new JFrame("Swingdemo");
j.setSize(300,300);
j.setLayout(new FlowLayout());
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1=new JButton("click me");
JButton b2=new JButton("MCA");
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
l1.setText("button clicked");
}
});
j.add(b1);
l1=new JLabel("pls click");
j.add(l1);
j.setVisible(true);
}
public static void main(String args[])
{
SwingUtilities.invokeLater(new Runnable(){
public void run()
{
new eventdemo();
}
});
}
}
Output:
import java.awt.*;
import java.awt.event.*;
class eventdemo
{
JButton b1;
JLabel l1;
eventdemo()
{
JFrame j=new JFrame("Swingdemo");
j.setSize(300,300);
j.setLayout(new FlowLayout());
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1=new JButton("click me");
JButton b2=new JButton("MCA");
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
l1.setText("button clicked");
}
});
j.add(b1);
l1=new JLabel("pls click");
j.add(l1);
j.setVisible(true);
}
public static void main(String args[])
{
SwingUtilities.invokeLater(new Runnable(){
public void run()
{
new eventdemo();
}
});
}
}
Output:
No comments:
Post a Comment