Currently working on a simple system. Where the if else statement does not affect anything. Here's the code :
tollRate()
{
JFrame a = new JFrame();
setTitle("Highway Toll Rates System");
setSize(600, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(5, 2));
p1.setLayout(new GridLayout(1, 2));
p1.add(L1);
p1.add(t1);
p2.setLayout(new GridLayout(1, 2));
p2.add(L2);
p2.add(t2);
p3.setLayout(new GridLayout(1, 2));
p3.add(L3);
p3.add(t3);
p4.setLayout(new FlowLayout());
p4.add(b1);
p4.add(b2);
p5.setLayout(new FlowLayout());
p5.add(L4);
add(p1); add(p2); add(p3); add(p4); add(p5);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent a)
{
Object source = a.getSource();
if(source == b2)
{
this.dispose();
}
else if(source == b1)
{
i = t1.getText();
j = t2.getText();
k = t3.getText();
if (i!=SUNGAI BULOH)
{
JOptionPane.showMessageDialog(null, "Invalid Location" );
}
}
}
public static void main(String[] args)
{
tollRate a = new tollRate();
}
}
Can anyone assist me with the if else statement in this code? I want the system to display "invalid location" if the user keys in anything other than "SUNGAI BULOH" in i. Thank you in advance.