diff --git a/bin/SecondGUI$1.class b/bin/SecondGUI$1.class new file mode 100644 index 0000000..0cad793 --- /dev/null +++ b/bin/SecondGUI$1.class Binary files differ diff --git a/bin/SecondGUI.class b/bin/SecondGUI.class index e8e65e3..1d37b22 100644 --- a/bin/SecondGUI.class +++ b/bin/SecondGUI.class Binary files differ diff --git a/src/SecondGUI.java b/src/SecondGUI.java index 635cadb..d291589 100644 --- a/src/SecondGUI.java +++ b/src/SecondGUI.java @@ -1,7 +1,10 @@ import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JOptionPane; public class SecondGUI extends JFrame { public static void main(String[] args) { @@ -10,10 +13,18 @@ } public SecondGUI(){ super("SecondGUI"); + JButton b1,b2,b3; getContentPane().setLayout(new FlowLayout()); - getContentPane().add(new JButton("B1")); - getContentPane().add(new JButton("B2")); - getContentPane().add(new JButton("B3")); + getContentPane().add(b1 = new JButton("B1")); + getContentPane().add(b2 = new JButton("B2")); + getContentPane().add(b3 = new JButton("B3")); + b1.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JOptionPane.showMessageDialog(b1, "B1"); + } + }); + b2.addActionListener( e -> JOptionPane.showMessageDialog(b1, e.getActionCommand()) ); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true);