Create a swing applet that has two buttons named alpha and beta. When either of the buttons pressed, it should display “Alpha is pressed” or : "Beta is pressed”.
PROGRAM :
package com.company;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class AlphaBeta
extends JApplet implements ActionListener
{
JButton rb1,rb2;
JLabel l;
public void init()
{
rb1=new JButton("Alpha");
rb2=new JButton("Beta");
l=new JLabel();
setLayout(new FlowLayout());
getContentPane().add(rb1);
getContentPane().add(rb2);
getContentPane().add(l);
rb1.addActionListener(this);
rb2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==rb1)
{
l.setText("Alpha is
pressed");
}
if(e.getSource()==rb2)
{
l.setText("Beta is
pressed");
}
}
}
//<applet
code=AlphaBeta width=500 height=500></applet>
OUTPUT :
Labels: Create a swing applet that has two buttons, it should display “Alpha is pressed” or : Beta is pressed”.


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home