Menu

**The user need to select the wash pet button else it will ask the user to enter the button **Need to use java Exception handling in GUI Format ** Need it urgently  **The code run smoothly package pr…

Question

Answered step-by-step

**The user need to select the wash pet button else it will ask the…

**The user need to select the wash pet button else it will ask the user to enter the button

**Need to use java Exception handling in GUI Format

** Need it urgently 

**The code run smoothly

Image transcription text

Pet Care Booking 0 X Buyer Name: efsd Pet Name: edvr Pet Category: rib Booking How Many Day: 3 Wash
Pet? O Yes O No e Another Careful Instruction? ymjyghml Fee: 1 day RM 40 it Total : Day :
Show more

package project;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.text.DecimalFormat;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;

public class pet_care_Booking extends JFrame implements ActionListener
{   
   private JRadioButton rb1, rb2;
   private JButton btn;
   private JLabel label1, label2, label3, label4, label5, label6, label7, label8, label9, label10;
   private JTextField textfield1, textfield2, textfield3, textfield4, textfield5, textfield6, textfield7, textfield8;
   private JPanel p1, p2,p3,sp2,ssp2;
   ImageIcon icons = new ImageIcon((new ImageIcon(this.getClass().getResource(“dog.jpg”)).getImage().getScaledInstance(150, 150, java.awt.Image.SCALE_SMOOTH)));

    public static void main(String []args)
   {
       pet_care_Booking fr = new pet_care_Booking();
       fr.setTitle(“Pet Care Booking”);
       fr.pack(); 
       //fr.setSize(1200,900);
       fr.setVisible(true);
       fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       //error
       //ImageIcon image = new ImageIcon(“dog2.jpg”);
       //fr.setIconImage(image.getImage());
       //fr.getContentPane().setBackground(new Color(255, 250, 205));
   }

   public pet_care_Booking()
   {
       Font font1 = new Font(“Arial”, Font.BOLD,15);
       Font font2 = new Font(“Arial”, Font.BOLD,20);
       
       label1 = new JLabel(icons);
       label2 = new JLabel(“Fee: 1 day RM 40”,SwingConstants.CENTER);
       label3 = new JLabel(“Buyer Name:”,SwingConstants.RIGHT);
       label3.setFont(font1);
       label4 = new JLabel(“Pet Name:”,SwingConstants.RIGHT);
       label4.setFont(font1);
       label5 = new JLabel(“Pet Category:”,SwingConstants.RIGHT);
       label5.setFont(font1);
       label6 = new JLabel(“How Many Day: “,SwingConstants.RIGHT);
       label6.setFont(font1);
       label7 = new JLabel(“Wash Pet?”,SwingConstants.RIGHT);
       label7.setFont(font1);
       label8 = new JLabel(“Another Careful Instruction?”,SwingConstants.RIGHT);
       label8.setFont(font1);
       
       label9 = new JLabel(“Total : “,SwingConstants.CENTER);
       label9.setFont(font2);
       label10 = new JLabel(“Day : “,SwingConstants.CENTER);
       label10.setFont(font2);

       textfield1 = new JTextField(10);
       textfield2 = new JTextField(10);
       textfield3 = new JTextField(10);
       textfield4 = new JTextField(10);
       textfield5 = new JTextField(10);
       textfield6 = new JTextField(10);
       
       textfield7 = new JTextField(10);
       textfield7.setEditable(false);
       textfield7.setFont(font2);
       textfield7.setBackground(Color.getHSBColor(180, 100, 100));
       
       textfield8 = new JTextField(10);
       textfield8.setEditable(false);
       textfield8.setFont(font2);
       textfield8.setBackground(Color.getHSBColor(180, 100, 100));
       
       btn =new JButton(“Booking”);
       
       rb1 = new JRadioButton(“Yes”);
       rb1.setBackground(Color.white);
       rb2 = new JRadioButton(“No”);
       rb2.setBackground(Color.white);

       ButtonGroup bg = new ButtonGroup(); //This is for?
       bg.add(rb1);bg.add(rb2);
       
       p1 = new JPanel();
       p1.setLayout(new GridLayout(2,1));
       p1.add(label1);
       p1.add(label2);

       
       p2 = new JPanel();
           sp2 = new JPanel();
           sp2.setLayout(new GridLayout(6,2));
           sp2.add(label3);
           sp2.add(textfield1);
           sp2.add(label4);
           sp2.add(textfield2);
           sp2.add(label5);
           sp2.add(textfield3);
           sp2.add(label6);
           sp2.add(textfield4);
           sp2.add(label7);
               ssp2 = new JPanel();
               ssp2.setBorder(BorderFactory.createLineBorder(Color.gray));
               ssp2.setBackground(Color.white);
               ssp2.add(rb1);
               ssp2.add(rb2);
           sp2.add(ssp2);
           sp2.add(label8);
           sp2.add(textfield6);
       p2.add(sp2);
       p2.add(btn);

       p3 = new JPanel();
       p3.setLayout(new GridLayout(1, 4));
       p3.add(label9);
       p3.add(textfield7);
       p3.add(label10);
       p3.add(textfield8);
       
       setLayout(new BorderLayout());
       add(p1, BorderLayout.WEST);
       add(p2, BorderLayout.CENTER);
       add(p3, BorderLayout.SOUTH);

       btn.addActionListener(this);

   }

    public void actionPerformed(ActionEvent e)
  {

int day =0;

      if (textfield1.getText().isEmpty() || textfield2.getText().isEmpty() || textfield3.getText().isEmpty() || textfield4.getText().isEmpty() ) {
          JOptionPane.showMessageDialog(null, “Make Sure All Input fields Are Filled “);
          return;
      }
else {

      //**Buyer name, pet name and pet category must enter alphabet else display invalid input

   boolean result1 = textfield1.getText().matches(“[a-zA-Z]+”);
      boolean result2 =  textfield2.getText().matches(“[a-zA-Z]+”);
      boolean result3 =  textfield3.getText().matches(“[a-zA-Z]+”);

      if(result1 == false || result1== false|| result1== false ){
  JOptionPane.showMessageDialog(null, “Invalid input,must enter alphabet  “);
  return;
    }else{
//How many day must enter in numeric format else display invalid input
  try{
            DecimalFormat df = new DecimalFormat(“RM 0.00”);

             day = Integer.parseInt(textfield4.getText());

           double total = day * 40.00;

           if(rb1.isSelected())
           {
               total += 15;
           }

           textfield8.setText(String.valueOf(day));
           textfield7.setText(String.valueOf(df.format(total)));
}catch(Exception ex){
JOptionPane.showMessageDialog(null, “Invalid input , day number invalid, please in put number”);

}
     }

 

 } // end if

  }

}
   
 

OR

Leave a Reply

Your email address will not be published. Required fields are marked *