Closed Thread
Results 1 to 3 of 3

Thread: need help about jradiobutton + submit buttons

  1. #1
    jnewbie is offline Newbie
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Smile need help about jradiobutton + submit buttons

    hello im a java newbie and i really need your help mates

    i need a code that uses jradiobutton that will be use for selecting mathematical operations

    -multiplication
    -addition
    -subtraction
    -division

    when i click addition , a JOptionPane will appear to add INputBox for inputing 1st Integer and another input box to input 2nd integer to be solved please can you modify this code regarding to my request!



    Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    
    public class justabasic extends JFrame{
            double equals = 0.0;
            JLabel selectoperationLabel = new JLabel("Select Operation:");
            JLabel firstdigitLabel = new JLabel("FIRST DIGIT:");
            JLabel seconddigitLabel = new JLabel("SECOND DIGIT:");
            JLabel outputLabel = new JLabel("Display Output");
            JTextField firstDigit = new JTextField(5);
            JTextField secondDigit = new JTextField(5);
            JButton buttonOutput = new JButton("CLICK HERE");
            JRadioButton rbMultiply = new JRadioButton("Multiply");
            JRadioButton rbAddition = new JRadioButton("Addition");
            JRadioButton rbSubtract = new JRadioButton("Subtraction");
            JRadioButton rbDivision = new JRadioButton("Division");
            public justabasic(){
            super("I <3 EraserHead");
            setSize(200,300);
            setVisible(true);
            ButtonGroup g = new ButtonGroup();
            g.add(rbMultiply);
            g.add(rbAddition);
            g.add(rbSubtract);
            g.add(rbDivision);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container bigcon = getContentPane();
            bigcon.setLayout(new GridLayout(3,3));
            JPanel smallcon1 = new JPanel();
            smallcon1.add(firstdigitLabel);
            smallcon1.add(firstDigit);
            smallcon1.add(seconddigitLabel);
            smallcon1.add(secondDigit);
            JPanel smallcon2 = new JPanel();
            smallcon2.add(selectoperationLabel);
            smallcon2.add(rbMultiply);
            smallcon2.add(rbAddition);
            smallcon2.add(rbSubtract);
            smallcon2.add(rbDivision);
            smallcon2.add(buttonOutput);
            smallcon2.add(buttonOutput);
            smallcon2.add(outputLabel);
            bigcon.add(smallcon1);
            bigcon.add(smallcon2);
            Aksyon a = new Aksyon();
            rbMultiply.addActionListener(a);
            rbAddition.addActionListener(a);
            rbSubtract.addActionListener(a);
            rbDivision.addActionListener(a); 
            buttonOutput.addActionListener(a);
            }
    private class Aksyon implements ActionListener{
            public void actionPerformed(ActionEvent evt){
                    if(evt.getSource()== rbMultiply){
                    double first = (double) (Double.parseDouble(firstDigit.getText()));
                    double second = (double) (Double.parseDouble(secondDigit.getText()));
                    equals = first * second;
                    }
                    else if(evt.getSource()== rbAddition){
                    double first = (double) (Double.parseDouble(firstDigit.getText()));
                    double second = (double) (Double.parseDouble(secondDigit.getText()));
                    equals = first + second;
                    }
                    else if(evt.getSource()== rbSubtract){
                    double first = (double) (Double.parseDouble(firstDigit.getText()));
                    double second = (double) (Double.parseDouble(secondDigit.getText()));
                    equals = first - second;
                    }
                    else if(evt.getSource()== rbDivision){
                    double first = (double) (Double.parseDouble(firstDigit.getText()));
                    double second = (double) (Double.parseDouble(secondDigit.getText()));
                    equals = first / second;
                    }
                    if(evt.getSource()== buttonOutput){
                            outputLabel.setText("WEEE!!" + equals);
                    }
            }
    }
    private class ligaya implements ItemListener{
            public void itemStateChanged(ItemEvent e){
    }
    }
            public static void main(String [] args){
                    justabasic frame = new justabasic();
            }
    }
    i can still wait brothers
    Last edited by ZekeDragon; 03-04-2010 at 11:02 PM. Reason: Do Not Double Post

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: need help about jradiobutton + submit buttons

    Quote Originally Posted by jnewbie View Post
    when i click addition , a JOptionPane will appear to add INputBox for inputing 1st Integer and another input box to input 2nd integer to be solved please can you modify this code regarding to my request!
    The people here won't do your work for you, however most people here will help you learn how to do it yourself. The first thing I'd do in the situation of your class is reformat it, for example in this situation:
    Code:
            JRadioButton rbDivision = new JRadioButton("Division");
            public justabasic(){
            super("I <3 EraserHead");
            setSize(200,300);
    It is very unclear that the constructor started here. If I weren't really looking for it I'd never notice that it's there. You should reformat the class in such a manner that it's very easy to tell how control flow works and where methods are vs where data members are. In fact, how it's formatted, your document looks like 3 separate classes with the first one having no method at all.

    The second thing I'd do is look at how a JOptionPane works and start applying that to the ActionListener's ActionPerformed method. That's where you'd want to generate the two JOptionPanes to take in user input and where you'd want to perform the calculation.

    Side Note: It's not considered kosher to double-post, especially after less than 2 hours from your original post. Just edit your post with anything additional you want, and be patient. There aren't many people on at this time of night (in the USA), so if it takes some time for a response don't be discouraged.
    Wow I changed my sig!

  4. #3
    jnewbie is offline Newbie
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Re: need help about jradiobutton + submit buttons

    thank you sir!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Alex G. CSS "Sexy Buttons" - what about "submit on 'ENTER'" ?
    By shackrock in forum JavaScript and CSS
    Replies: 7
    Last Post: 12-05-2010, 04:57 PM
  2. Submit forum via URL
    By ki4jgt in forum Visual Basic Programming
    Replies: 1
    Last Post: 10-07-2010, 02:28 AM
  3. Need some help with submit buttons - catbutton?
    By Panarchy in forum HTML Programming
    Replies: 5
    Last Post: 12-07-2008, 02:23 AM
  4. Looking for multiple submit
    By samit in forum JavaScript and CSS
    Replies: 1
    Last Post: 09-11-2008, 09:57 AM
  5. make swing JRadioButton unchangeable
    By acwclassic in forum Java Help
    Replies: 10
    Last Post: 09-07-2008, 10:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts