File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import javax .swing .*;
2+ import java .awt .*;
3+ import java .awt .event .*;
4+ public class ButtonColor implements ActionListener {
5+ JFrame f ;
6+ JButton b1 ,b2 ,ans ;
7+ JLabel l ;
8+
9+ ButtonColor ()
10+ {
11+ f =new JFrame ("COLOR CHANGER" );
12+ b1 =new JButton ("Red" );
13+ b2 =new JButton ("Green" );
14+ ans =new JButton ("BUTTON" );
15+ l =new JLabel ("Tap to change color" );
16+ f .add (b1 );f .add (b2 );f .add (ans );f .add (l );
17+ f .setSize (400 ,350 );
18+ f .setLayout (null );
19+ f .setVisible (true );
20+ l .setBounds (100 ,50 ,200 ,20 );
21+ b1 .setBounds (70 ,100 ,100 ,30 );
22+ b2 .setBounds (230 ,100 ,100 ,30 );
23+ ans .setBounds (150 ,200 ,100 ,30 );
24+ b1 .addActionListener (this );
25+ b2 .addActionListener (this );
26+ f .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
27+ }
28+
29+ public void actionPerformed (ActionEvent e )
30+ {
31+ if (e .getSource ()==b1 )
32+ ans .setBackground (Color .red );
33+ else
34+ ans .setBackground (Color .green );
35+ }
36+ public static void main (String [] args ) {
37+ new ButtonColor ();
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments