Search code examples
javajoptionpane

OptionPane showmessage


I have made an Optionpane using the showmessage method now I can't seem to find out how to assign the "Ok" button and the exit button. So I only want to close the JOptionPane and leave the frame untouched. This is also my first time posting so if not everything is alright. I have also researched and cannot find the same question and/or answer anywhere. I hope you guys can help me!

        public void actionPerformed(ActionEvent event){
            while((field1.getText().equals("")) || (field2.getText().equals("")) || (field3.getText().equals("")) || (field4.getText().equals("")) || (field5.getText().equals("")) || (field6.getText().equals("")) ){
                JOptionPane.showMessageDialog(frame, "I find your lack of input disturbing.", "Input alert", JOptionPane.INFORMATION_MESSAGE);

Solution

  • public void actionPerformed(ActionEvent event){
            if(field1.getText().equals("") && field2.getText().equals("") ...... N){
            JOptionpane......
            }
    }
    

    You should try this. instead of while loop.