I want to know how to make my program only accept (1101101) as the only correct input on JTextField txtCode. At the moment, I can enter any code in the textfield and it will display the same output.
Here's the code:
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class GUI extends JFrame {
JLabel coffeeProgram;
JButton button;
JTextField txtCode;
JTextField price;
JTextField description;
JLabel outputPrice;
public GUI() {
setLayout(new FlowLayout());
coffeeProgram = new JLabel("Enter Code Here:");
add(coffeeProgram);
txtCode = new JTextField(15);
add(txtCode);
button = new JButton("Submit Code");
add(button);
outputPrice = new JLabel(" Price: ");
add(outputPrice);
JTextField price;
CoffeeReturn objCoffee = new CoffeeReturn();
double myPrice = objCoffee.CoffeeCode(txtCode.getText());
price = new JTextField(15);
add(price);
price.setText("Price is"+myPrice);
}
}
I'm sorry if this code seems a little inexperienced. I'm 15 and started to try and learn java 2 days ago. Here's a screenshot of my program: http://gyazo.com/afe2abf5fcffa3822bd41eaea8581597