Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help needed in makin GUI (in netbeans) for a maths program(with lots of loops).

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help needed in makin GUI (in netbeans) for a maths program(with lots of loops).

    hey im new in java. i needto make GUI for my program buh im confused as to what to wirte in GUI codes and wat to write in Main codes etc. could someone plz help me?

    mathprogram.java main class
    public class mathprogram {
        public  static void main (String[] args){
     
             addition add = new addition();
             random ran = new random();
             subtraction sub=new subtraction();
             multiplication mult=new multiplication();
             division divide=new division();
             mathmenu mm=new mathmenu();
             mm.setVisible(true);
     
     
            int grade = 1;
            int equation = 10;
            int equationtype;
            int range1 = 0;
            int range2 = 0;
            int question1;
            int question2;
            int questionAnswer = 0;
            int answer = 0;
            int totalCorrect = 0;
     
             Scanner scanner = new Scanner(System.in);
            boolean menu = true;
     
            while (menu) {
                try {
                    System.out.println("What is your grade: ");
                    grade = scanner.nextInt();
                } catch (Exception ex) {
                    System.out.println("Incorrect grade. Please re-enter.\n");
                    continue;
                }
                if (grade < 1 || grade > 6) {
                    System.out.println("Incorrect grade. Please re-enter.\n");
                } else {
                    menu = false;
                }
                switch (grade) {
                    case 1:
                        range1 = 1;
                        range2 = 20;
                        break;
                    case 2:
                        range1 = 1;
                        range2 = 50;
                        break;
                    case 3:
                        range1 = 10;
                        range2 = 50;
                        break;
                    case 4:
                        range1 = 10;
                        range2 = 100;
                        break;
                    case 5:
                        range1 = 50;
                        range2 = 100;
                        break;
                    case 6:
                        range1 = 100;
                        range2 = 500;
                        break;//is used to break the loop or the block of statemnt
                }
            }
            menu = true;
     
            while (menu) {
                try {
                    System.out.println("How many equations you want to solve? (10, 20, 30 or 50): ");
                    equation = scanner.nextInt();
                } catch (Exception ex) {
                    System.out.println("Incorrect numbers. Please re-enter.\n");
                    continue;
                }
                switch (equation) {
                    case 10:
                    case 20:
                    case 30:
                    case 50:
                        menu = false;
                        break;
                    default:
                        System.out.println("Incorrect numbers. Please re-enter.\n");
                }
            }
             menu = true;
        System.out.println("wat do u want to solve ure equations in?:\n 1.addition\n 2.substraction\n 3.multiplication\n 4.dividion");
      equationtype=scanner.nextInt();
            for (int i = 0; i < equation; i++) {
                System.out.println("Question " + (i + 1));
                question1 = ran.random(range1, range2);
                question2 = ran.random(range1, range2);
     
        if (equationtype==1){
                System.out.println(question1 + " + " + question2);
                questionAnswer = add.addition(question1, question2);
                }
                else if(equationtype==2){
                System.out.println(question1 + " - " + question2);
                questionAnswer = sub.subtraction(question1, question2);
                }
                else if(equationtype==3){
                    System.out.println(question1 + " * " + question2);
                questionAnswer = mult.multiplication(question1, question2);
                }
                else if(equationtype==4){
                    System.out.println(question1 + " / " + question2);
                questionAnswer = divide.division(question1, question2);
                }
                else{
                    System.out.println("Incorect");
        }
                menu = true;
                while (menu) {
                    try {
                        System.out.print("Your answer: ");
                        answer = scanner.nextInt();
                    } catch (Exception ex) {
                        System.out.println("Incorrect answer. Please re-enter.\n");
                        continue;
                    }
                    if (answer == questionAnswer) {
                        System.out.println("Correct!\n");
                        totalCorrect++;
                    } else {
                        System.out.println("Wrong!\n");
                    }
                    menu = false;
                }
                }
            System.out.println("Total Questions: " + equation);
            System.out.println("Total Corrects: " + totalCorrect);
            System.out.println("Total Wrongs: " + (equation-totalCorrec
                }
        }

    random.java class
    import java.util.Random;
    public class random {
        public int random(int ran1, int ran2) {
            Random random = new Random();
            return random.nextInt(ran2-ran1+1) + ran1;
        }
    }

    addition.java class
    public class addition {
        public int addition(int num1, int num2) {
            return num1+num2;
        }
    }

    subtraction.java class
    public class subtraction {
    public int subtraction (int num3, int num4){
    return  num3 -num4;
    }
    }

    multiplication.java class
    public class multiplication {
     public int multiplication(int num5, int num6) {
            return num5*num6;
        }
    }

    division.java class
    public class division {
     public int division(int num7, int num8) {
            return num7/num8;
        }
    }

    mathmenu.java guiclass(i juss started learnin abtgui like literally yesterday, all i know is how to design the GUI and how to let the user key in- m confused how to code in this class, amd i supose to write al the loops here instead of the mathprogram.java(main class). could someone show me how to do it?
    public class mathmenu extends javax.swing.JFrame {
        public mathmenu() {
            initComponents();
        }
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jPanel1 = new javax.swing.JPanel();
            questionlabel1 = new javax.swing.JLabel();
            answer3 = new javax.swing.JTextField();
            questionlabel2 = new javax.swing.JLabel();
            answer2 = new javax.swing.JTextField();
            questionlabel3 = new javax.swing.JLabel();
            answer1 = new javax.swing.JTextField();
            jPanel2 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            questionlabel1.setText("wat grade do u study in?");
     
            answer3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    answer3ActionPerformed(evt);
                }
            });
     
            questionlabel2.setText("how many questions do u wish to solve:10, 20, 30,50?");
     
            answer2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    answer2ActionPerformed(evt);
                }
            });
     
            questionlabel3.setText("watdo u wish to  use while solving equation:+ - * /");
     
            answer1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    answer1ActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(questionlabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(answer3, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addContainerGap(97, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(questionlabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(89, 89, 89))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(answer2, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                            .addGap(89, 89, 89))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(questionlabel3)
                            .addContainerGap(115, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(answer1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                            .addGap(89, 89, 89))))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(questionlabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(answer3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(questionlabel2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(answer2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(questionlabel3)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(answer1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(23, Short.MAX_VALUE))
            );
     
            jTabbedPane1.addTab("tab1", jPanel1);
     
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 477, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 227, Short.MAX_VALUE)
            );
     
            jTabbedPane1.addTab("tab2", jPanel2);
     
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 477, Short.MAX_VALUE)
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 227, Short.MAX_VALUE)
            );
     
            jTabbedPane1.addTab("tab3", jPanel3);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 485, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(400, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(46, 46, 46)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(36, Short.MAX_VALUE))
            );
            pack();
        }
     
        private void answer3ActionPerformed(java.awt.event.ActionEvent evt) {
         try{
            int grade= Integer.parseInt(
                    this.answer3.getText());
        }
       catch(Exception ex){
        JOptionPane.showMessageDialog(this, "error!-wrong option", null,  JOptionPane.ERROR_MESSAGE);
      return;
        }
        }
         private void answer2ActionPerformed(java.awt.event.ActionEvent evt) {
             try{
            int question= Integer.parseInt(
                    this.answer2.getText());
        }
       catch(Exception ex){
        JOptionPane.showMessageDialog(this, "error!-wrong option", null,  JOptionPane.ERROR_MESSAGE);
      return;
        }
         }
     
         private void answer1ActionPerformed(java.awt.event.ActionEvent evt) {
        try{
            int grade= Integer.parseInt(
                    this.answer1.getText());
        }
       catch(Exception ex){
        JOptionPane.showMessageDialog(this, "error!-wrong option", null,  JOptionPane.ERROR_MESSAGE);
      return;
        }
         }
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new mathmenu().setVisible(true);
                }
            });
        }
        private javax.swing.JTextField answer1;
        private javax.swing.JTextField answer2;
        private javax.swing.JTextField answer3;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JLabel questionlabel1;
        private javax.swing.JLabel questionlabel2;
        private javax.swing.JLabel questionlabel3;
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help needed in makin GUI (in netbeans) for a maths program(with lots of loops).

    Cross posted at help needed in makin GUI for a maths program(with lots of loops). - Java

Similar Threads

  1. program loops never ending
    By Ccogh05 in forum Loops & Control Statements
    Replies: 5
    Last Post: February 24th, 2011, 01:42 AM
  2. help needed with netbeans
    By jalkin in forum Java IDEs
    Replies: 1
    Last Post: May 4th, 2010, 09:08 PM
  3. Program without loops and recursion
    By jayaram in forum Algorithms & Recursion
    Replies: 7
    Last Post: April 1st, 2010, 09:02 AM
  4. Program with for loops help
    By ixjaybeexi in forum Loops & Control Statements
    Replies: 23
    Last Post: October 8th, 2009, 10:05 AM
  5. [SOLVED] Fixing of bug in number guessing game
    By big_c in forum Loops & Control Statements
    Replies: 6
    Last Post: April 16th, 2009, 02:15 AM

Tags for this Thread