Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package multiplicationgui;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- /**
- *
- * @author c310
- */
- public class MultiplicationGUI {
- public static void main(String[] args) {
- // create an instance of MultiplyFrame
- MultiplyFrame frame = new MultiplyFrame();
- frame.setTitle("Multiplication Flash Card");
- frame.setSize(500, 250);
- frame.setLocation(400, 200);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- /*
- userAnswer = JOptionPane.showInputDialog("What is " + numOne + " * " + numTwo + " ?");
- answer = Integer.parseInt(userAnswer);
- if (answer == multiply(numOne, numTwo)) {
- JOptionPane.showMessageDialog(null, "You are correct sir! \n" + numOne + " * " + numTwo + " = " + multiply(numOne, numTwo));
- } else {
- JOptionPane.showMessageDialog(null, "WRONG, SIR, WRONG! GOOD DAY \n" + numOne + " * " + numTwo + " = " + multiply(numOne, numTwo));
- }
- */
- } // end main *************************************************
- } // end MultiplicationGUI class
- class MultiplyFrame extends JFrame implements ActionListener {
- JLabel description = new JLabel("Please perform the multiplication \n");
- JTextField input = new JTextField(20);
- MultiplyFrame() {
- // give the TextFieldFrame a FlowLayout
- setLayout(new FlowLayout(FlowLayout.CENTER));
- // add the components to TextFieldFrame
- add(description);
- add(input);
- // register TextFieldFrame (this method) as the listener for jtfName
- input.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- int numOne;
- int numTwo;
- String userAnswer;
- int answer;
- numOne = 0 + (int) (Math.random() * 10);
- numTwo = 0 + (int) (Math.random() * 10);
- }
- /* ----- Method for multiplication -------- */
- public static int multiply(int a, int b) {
- return a * b;
- } // end multiply method
- } // end multiplyFrame class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement