Advertisement
Guest User

hi

a guest
Nov 28th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package multiplicationgui;
  8. import javax.swing.*;
  9. import java.awt.*;
  10. import java.awt.event.*;
  11.  
  12. /**
  13.  *
  14.  * @author c310
  15.  */
  16. public class MultiplicationGUI {
  17.  
  18.     public static void main(String[] args) {
  19.        
  20.          // create an instance of MultiplyFrame
  21.         MultiplyFrame frame = new MultiplyFrame();  
  22.        
  23.         frame.setTitle("Multiplication Flash Card");
  24.         frame.setSize(500, 250);
  25.         frame.setLocation(400, 200);
  26.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27.         frame.setVisible(true);
  28.        
  29.        
  30.    
  31.        
  32.    
  33.        
  34.      /*  
  35.         userAnswer = JOptionPane.showInputDialog("What is " + numOne + " * " + numTwo + " ?");
  36.  
  37.        
  38.         answer = Integer.parseInt(userAnswer);
  39.        
  40.         if (answer == multiply(numOne, numTwo)) {
  41.             JOptionPane.showMessageDialog(null, "You are correct sir! \n" + numOne + " * " + numTwo + " = " + multiply(numOne, numTwo));
  42.         } else {
  43.             JOptionPane.showMessageDialog(null, "WRONG, SIR, WRONG! GOOD DAY \n" + numOne + " * " + numTwo + " = " + multiply(numOne, numTwo));
  44.         }
  45.        */
  46.        
  47.    
  48.        
  49.        
  50.        
  51.        
  52.     } // end main *************************************************
  53.    
  54.    
  55.    
  56.  
  57. } // end MultiplicationGUI class
  58.  
  59. class MultiplyFrame extends JFrame implements ActionListener {
  60.    
  61.     JLabel description = new JLabel("Please perform the multiplication \n");
  62.    
  63.     JTextField input = new JTextField(20);
  64.    
  65.        
  66.    
  67.     MultiplyFrame() {
  68.         // give the TextFieldFrame a FlowLayout
  69.         setLayout(new FlowLayout(FlowLayout.CENTER));
  70.  
  71.         // add the components to TextFieldFrame
  72.         add(description);
  73.         add(input);
  74.  
  75.         // register TextFieldFrame (this method) as the listener for jtfName
  76.         input.addActionListener(this);
  77.     }
  78.    
  79.     public void actionPerformed(ActionEvent e) {
  80.            
  81.        int numOne;
  82.        int numTwo;
  83.        String userAnswer;
  84.        int answer;
  85.        
  86.         numOne = 0 + (int) (Math.random() * 10);
  87.         numTwo = 0 + (int) (Math.random() * 10);
  88.     }
  89.    
  90.  
  91.      /* ----- Method for multiplication -------- */
  92.     public static int multiply(int a, int b) {
  93.         return a * b;
  94.        
  95.     } // end multiply method
  96.    
  97. } // end multiplyFrame class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement