Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help With a Run Time Error

    When I run it and click the "execute" button, I feel like the System.out.println should show up but it's not. Here's my code. I bolded the line that's not working.

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;

    public class CalcLike implements ActionListener
    {

    //DECLARE VARIABLES
    JRadioButton choiceOne, choiceTwo, choiceThree, choiceFour, choiceFive, choiceSix, choiceSeven, choiceEight, choiceNine, choiceZero;
    JPanel North, South, Center;
    JTextField numberLineOne = new JTextField(16);
    JTextField numberLineTwo = new JTextField(16);
    JTextField numberLineAnswer = new JTextField(16);
    JTextArea choiceList = new JTextArea("0. Exit "
    + "1.The sum (+) "
    + "2.The difference (-) "
    + "3.The product (*) "
    + "4.The modular (%) "
    + "5.The average "
    + "6.The distance "
    + "7.1st number^2nd_number "
    + "8.Maximum "
    + "9.Minimum ", 10, 15);
    JButton equals = new JButton("Execute");

    //CONSTRUCTOR
    public CalcLike(){

    JFrame calculator = new JFrame("Calculatorish");
    JFrame.setDefaultLookAndFeelDecorated(true);
    calculator.setLocation(300,300);
    calculator.setSize(400,300);
    calculator.setDefaultCloseOperation(calculator.EXIT_ON_CLOSE);

    choiceList.setLineWrap(true);
    choiceList.setWrapStyleWord(true);

    North = new JPanel();
    South = new JPanel();
    Center = new JPanel();

    Container content = calculator.getContentPane();
    content.setLayout(new BorderLayout());

    choiceZero = new JRadioButton("0");
    choiceOne = new JRadioButton("1");
    choiceTwo = new JRadioButton("2");
    choiceThree = new JRadioButton("3");
    choiceFour = new JRadioButton("4");
    choiceFive = new JRadioButton("5");
    choiceSix = new JRadioButton("6");
    choiceSeven = new JRadioButton("7");
    choiceEight = new JRadioButton("8");
    choiceNine = new JRadioButton("9");

    ButtonGroup group = new ButtonGroup();
    group.add(choiceZero);
    group.add(choiceOne);
    group.add(choiceTwo);
    group.add(choiceThree);
    group.add(choiceFour);
    group.add(choiceFive);
    group.add(choiceSix);
    group.add(choiceSeven);
    group.add(choiceEight);
    group.add(choiceNine);

    North.add(choiceZero);
    North.add(choiceOne);
    North.add(choiceTwo);
    North.add(choiceThree);
    North.add(choiceFour);
    North.add(choiceFive);
    North.add(choiceSix);
    North.add(choiceSeven);
    North.add(choiceEight);
    North.add(choiceNine);

    Center.add(numberLineOne);
    Center.add(numberLineTwo);
    Center.add(choiceList);

    South.add(equals);
    South.add(numberLineAnswer);

    numberLineAnswer.setEditable(false);
    choiceOne.setSelected(true);

    content.add(North, BorderLayout.NORTH);
    content.add(South, BorderLayout.SOUTH);
    content.add(Center, BorderLayout.CENTER);

    calculator.setVisible(true);
    }
    //METHODS
    public static boolean isSelected(JRadioButton btn) {
    DefaultButtonModel model = (DefaultButtonModel)btn.getModel();
    return model.getGroup().isSelected(model);
    }

    public void executeMethod(){
    if (isSelected(choiceZero)==true){
    }
    methodZero();

    }

    public void actionPerformed(ActionEvent e){
    if(e.getSource() == equals){
    System.out.println("why wont this show up? once this shows up, methodZero (below) will replace it");
    }}

    public void methodZero(){
    System.exit(0);}




    //MAIN METHOD
    public static void main(String[] args){

    new CalcLike();
    }
    }
    Last edited by rewazi; 10-05-2010 at 12:23 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Where has the performed action been added to the button?
    Somewhere you need to have an equals.addActionPerformed(this); available.

    In the future can you please wrap your code in [code][/code] or [php][/php] tags for easier readability?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ah thanks! I figured it was something simple that I forgot. And yeah, next time i'll be sure to do that.


  •  

    Posting Permissions

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