From c20650fb711566290b89ce4e0deac4280ed640c9 Mon Sep 17 00:00:00 2001 From: Vanitha K <59090053+vkrishnan0507@users.noreply.github.com> Date: Sun, 4 Oct 2020 23:36:33 +0530 Subject: [PATCH] Update ButtonColor.java --- ButtonColor.java | 83 +++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/ButtonColor.java b/ButtonColor.java index ac8d25a..6049734 100644 --- a/ButtonColor.java +++ b/ButtonColor.java @@ -1,44 +1,55 @@ - import java.awt.*; import java.awt.event.*; -public class ButtonColor extends Frame implements ActionListener +public class awtButton extends Frame implements ActionListener { - Button redb, blueb; -public ButtonColor() - { -FlowLayout fl = new FlowLayout(); -setLayout(fl); - -redb = new Button("Red"); -blueb = new Button("Blue"); - -redb.addActionListener(this); -blueb.addActionListener(this); + Button b1,b2; + public awtButton() + { + setLayout(new FlowLayout()); + b1=new Button("Red"); + b2=new Button("Blue"); + b1.addActionListener(this); + b2.addActionListener(this); + addWindowListener(new MyWindowAdapter6(this)); + add(b1); + add(b2); + + setTitle("Button"); + setSize(400,400); + setVisible(true); -add(redb); -add(blueb); + } + + public void actionPerformed(ActionEvent e) + { + String str=e.getActionCommand(); + if(str.equals("Red")) + { + setBackground(Color.red); + } + if(str.equals("Blue")) + { + setBackground(Color.blue); + } + } -setTitle("Button in Action"); -setSize(300, 350); -setVisible(true); - } - -public void actionPerformed(ActionEvent e) { - String str = e.getActionCommand(); -System.out.println("You clicked " + str + " button"); + public static void main(String[] args) { + // TODO Auto-generated method stub + awtButton a=new awtButton(); + + } -if(str.equals("Red")) - { -setBackground(Color.red); - } -else if(str.equals("Blue")) - { -setBackground(Color.blue); - } - } -public static void main(String args[]) - { -new ButtonColor(); - } +} +class MyWindowAdapter6 extends WindowAdapter +{ + awtButton a; + MyWindowAdapter6(awtButton a) + { + this.a=a; + } + public void windowClosing(WindowEvent ae) + { + a.setVisible(false); + } }