hi guys
this is my program .. If there is anyone could help me before 11:50 I will be so happy
the last time to submit it tonight
the program working fine .. the cancel button doesn't work
I want the program to show message when I click ( cancel ) such as ( cancel button is working )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Program3 { public static void main(String[] args) { // declare variables int sum = 0; int max=0, min= 0; // initialize it one time. boolean firstIteration = true; // the for loop for ( int i=1; i<=4; i++) { //each inputted number will stores here String userInput = JOptionPane .showInputDialog("Enter an integer"); // to converse the string to int int value = Integer.parseInt(userInput); if(firstIteration) { // the variables sum = value; max = value; min = value; firstIteration = false; } else { //add to sum sum += value; } //conditional statement //if inputted number is smaller than our min then exchange it. if(value < min) { min = value; } //conditional statement //if inputted number is bigger than our max then exchange it. if(value > max) { max = value; } } // calculating the averege by extracted the sum by 4 double averge = sum / 4.0; JOptionPane.showMessageDialog(null," Max is " + max + " \nMin is " + min + "\nSum is " + sum + " \nAverage is " + averge , "Program 3", JOptionPane.PLAIN_MESSAGE); JButton button = new JButton("cancel"); button.addActionListener(new ActionListener(){ JButton button = new JButton(); button.setVisible(true); button.setSize(250,250); button.setDefaultCloseOperation(JButton.EXIT_ON_CLOSE); JPanel p = new JPanel(); JButton b1 = new JButton ("Action Listener"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "cancel button clicked") }); p.add(b1); button.add(p); } }); System.exit(0); // program end } }