import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener.*; import java.awt.event.ActionListener; import java.awt.event.*; import java.lang.*; import javax.swing.Action; import java.awt.event.*; public class Main { public static void main(String[] args) { GUI appGUI = new GUI (); appActions Actions = new appActions(); } } import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener.*; import java.awt.event.ActionListener; import java.awt.event.*; import java.lang.*; import javax.swing.Action; import java.awt.event.*; public class appActions implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println(e.getClass()); } } import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener.*; import java.awt.event.ActionListener; import java.awt.event.*; import java.lang.*; import javax.swing.Action; import java.awt.event.*; public class GUI extends JFrame { JPanel panel0; JButton rollDie; JButton flipCoin; JFrame frame; public GUI (){ panel0 = new JPanel(); rollDie = new JButton("Roll A Die"); flipCoin = new JButton("Flip A Coin"); rollDie.setBackground(Color.red); rollDie.setOpaque(true); rollDie.setBorderPainted(false); flipCoin.setBackground(Color.yellow); flipCoin.setOpaque(true); flipCoin.setBorderPainted(false); panel0.add(rollDie); panel0.add(flipCoin); setVisible(true); setSize(900,900); setLayout(new GridLayout(4,0)); setAction(); JFrame frame; add(panel0); } public void setAction() { rollDie.addActionListener(new appActions(){public void actionPerformed(ActionEvent e) { int SIDES = 6; int roll = (int) (Math.random() * SIDES) + 1; System.out.println(roll); }}); // Lines 31-33 found here: https://introcs.cs.princeton.edu/java/13flow/RollDie.java.html flipCoin.addActionListener(new appActions(){public void actionPerformed(ActionEvent e) { if (Math.random() < 0.5){ System.out.println("It Landed On Heads!"); }else{ System.out.println("It Landed On Tails!"); }}}); // Lines 36-39 found here: https://www.w3schools.in/java/examples/coin-toss } }