Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 186013
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T14:21:26+00:00 2022-06-10T14:21:26+00:00

Why is the && operator not working in the if statement within (ActionEvent e) in this Java Program?

  • 0

[ad_1]

Why is the && operator not working in the if statement within (ActionEvent e) in this Java Program?

Hi. I am creating a Java program intended for displaying each of the forms of the Polish adjective “szczęśliwy” in a dialog box using JOptionPane. The problem is that && operator is not working as expected in (ActionEvent e). For instance, I have entered the following code

if (e.getSource() == radioButton[0] && (e.getSource() ==
radioButton1) && (e.getSource() == radioButton[9])) {
JOptionPane.showMessageDialog(null, “szczęśliwy”);

in order to display a JOptionPane message with the form “szczęśliwy”, which is the singular nominative animate masculine form of the Polish adjective, under the circumstances that the three corresponding JRadioButtons are checked when running the program. The corresponding Polish words are “liczba pojedyncza”(singular), “mianownik”(nominative) and “rodzaj męskoosobowy”(animate masculine). However, when I run the program and check the three corresponding JRadioButtons, no dialog box will appear, just like in the first image.
enter image description here

When I run the program and check only one JRadioButton listed below the first instance, a dialog box with the corresponding form of the Polish adjective will appear. All the other conditional statements have been created without the && operator and will work just fine, just like in the second image.

enter image description here
I wonder why the && operator is not working in this particular program. I would appreciate it if you could provide any solution to this problem. Thank you!

For reference purpose, the following image is the declension table for all the forms of the Polish adjective “szczęśliwy”.

enter image description here

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class MyFrame extends JFrame implements ActionListener {
  private static final long serialVersionUID = 1 L;

  ButtonGroup buttonGroup[];
  JPanel panel[];
  JRadioButton radioButton[];

  MyFrame() {
    buttonGroup = new ButtonGroup[3];
    panel = new JPanel[3];
    for (int i = 0; i < 3; i++) {
      panel[i] = new JPanel();
    }
    radioButton = new JRadioButton[15];

    radioButton[0] = new JRadioButton("liczba pojedyncza");
    radioButton[1] = new JRadioButton("liczba mnoga");
    for (int i = 0; i < 3; i++) {
      buttonGroup[i] = new ButtonGroup();
    }

    for (int i = 0; i < 2; i++) {
      buttonGroup[0].add(radioButton[i]);
      panel[0].add(radioButton[i]);
    }

    radioButton[2] = new JRadioButton("mianownik");
    radioButton[3] = new JRadioButton("dopełniacz");
    radioButton[4] = new JRadioButton("celownik");
    radioButton[5] = new JRadioButton("biernik");
    radioButton[6] = new JRadioButton("narzędnik");
    radioButton[7] = new JRadioButton("miejscownik");
    radioButton[8] = new JRadioButton("wołacz");
    for (int i = 2; i < 9; i++) {
      buttonGroup[1].add(radioButton[i]);
      panel[1].add(radioButton[i]);
    }

    radioButton[9] = new JRadioButton("rodzaj męskoosobowy");
    radioButton[10] = new JRadioButton("rodzaj męskorzeczowy");
    radioButton[11] = new JRadioButton("rodzaj żeński");
    radioButton[12] = new JRadioButton("rodzaj nijaki");
    radioButton[13] = new JRadioButton("rodzaj niemęskoosobowy");
    for (int i = 9; i < 14; i++) {
      buttonGroup[2].add(radioButton[i]);
      panel[2].add(radioButton[i]);
    }

    for (int i = 0; i < 14; i++) {
      radioButton[i].addActionListener(this);
    }

    for (int i = 0; i < 3; i++) {
      this.add(panel[i]);
    }
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new GridLayout(0, 1));
    this.setSize(520, 520);
    this.setTitle("odmiana przymiotnika 'szczęśliwy'");
    this.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == radioButton[0] && (e.getSource() == radioButton[2]) && (e.getSource() == radioButton[9])) {
      JOptionPane.showMessageDialog(null, "szczęśliwy");
    } else if (e.getSource() == radioButton[3]) {
      JOptionPane.showMessageDialog(null, "szczęśliwego");
    } else if (e.getSource() == radioButton[4]) {
      JOptionPane.showMessageDialog(null, "szczęśliwemu");
    } else if (e.getSource() == radioButton[5]) {
      JOptionPane.showMessageDialog(null, "szczęśliwego");
    } else if (e.getSource() == radioButton[6]) {
      JOptionPane.showMessageDialog(null, "szczęśliwym");
    } else if (e.getSource() == radioButton[7]) {
      JOptionPane.showMessageDialog(null, "szczęśliwym");
    } else if (e.getSource() == radioButton[8]) {
      JOptionPane.showMessageDialog(null, "szczęśliwy");
    }
  }
}

[ad_2]

  • 0 0 Answers
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 318 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 291 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 285 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.