JTextFiled problem
I want to get the text from txt1 that was put by keyboard to compare, but i cannot. Please help me to show the problem.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Scanner;
public class BookingFrame extends JFrame implements ActionListener, WindowListener {
private JButton addBtn, clearBtn, closeBtn;
private JLabel label;
private JTextField txt1,txt9;
private String customerName;
public BookingFrame() {
super("Welcome to Perth Festival");
setSize(400,600);
JPanel contentPane = new JPanel(new BorderLayout());
JPanel topP = new JPanel(new GridLayout(19,2));
Choice titleChoice = new Choice();
titleChoice.addItem("Please select one");
titleChoice.addItem("Dr.");
titleChoice.addItem("Mr.");
titleChoice.addItem("Mrs.");
titleChoice.addItem("Ms.");
Choice concessionChoice = new Choice();
concessionChoice.addItem("No");
concessionChoice.addItem("Yes");
Choice memberChoice = new Choice();
memberChoice.addItem("No");
memberChoice.addItem("Yes");
Choice eventTitleChoice = new Choice();
eventTitleChoice.addItem("Please select one");
eventTitleChoice.addItem("Perth Arts Movie");
eventTitleChoice.addItem("Perth Arts Concert");
Choice eventDateChoice = new Choice();
eventDateChoice.addItem("Please select one");
eventDateChoice.addItem("15/05/2007");
eventDateChoice.addItem("16/05/2007");
eventDateChoice.addItem("17/05/2007");
topP.add(new JLabel(""));
topP.add(new JLabel(""));
topP.add(new JLabel("I. Customer Information"));
topP.add(new JLabel(""));
topP.add(new JLabel("-"));
topP.add(new JLabel("-"));
topP.add(new JLabel("Customer Name"));
JTextField txt1 = new JTextField();
topP.add(txt1);
topP.add(new JLabel("Title"));
topP.add(titleChoice);
topP.add(new JLabel("Customer ID"));
JTextField txt3 = new JTextField();
topP.add(txt3);
topP.add(new JLabel("Seat Number"));
JTextField txt4 = new JTextField();
topP.add(txt4);
topP.add(new JLabel("Concession ?"));
topP.add(concessionChoice);
topP.add(new JLabel("Festival Club Member ?"));
topP.add(memberChoice);
topP.add(new JLabel(""));
topP.add(new JLabel(""));
topP.add(new JLabel("II. Festival Event Information"));
topP.add(new JLabel(""));
topP.add(new JLabel("-"));
topP.add(new JLabel("-"));
topP.add(new JLabel("Event Title"));
topP.add(eventTitleChoice);
topP.add(new JLabel("Event Date"));
topP.add(eventDateChoice);
topP.add(new JLabel("Event Coordinator"));
JTextField txt9 = new JTextField();
txt9.setText(customerName);
topP.add(txt9);
topP.add(new JLabel("Number of Seat"));
JTextField txt10 = new JTextField();
topP.add(txt10);
topP.add(new JLabel("Adult and Concession Price"));
JTextField txt11 = new JTextField();
topP.add(txt11);
topP.add(new JLabel("Event Description"));
JTextField txt12 = new JTextField();
topP.add(txt12);
topP.add(new JLabel("Featured Artist"));
JTextField txt13 = new JTextField();
topP.add(txt13);
contentPane.add(topP,BorderLayout.NORTH);
label = new JLabel("PERTH FESTIVAL BOOKING AGENT",JLabel.CENTER);
contentPane.add(label, BorderLayout.CENTER);
//add button at the SOUTH
addBtn = new JButton("Submit");
//add button
clearBtn = new JButton("Clear");
closeBtn = new JButton("Close");
JPanel p2 = new JPanel();
p2.add(addBtn);
p2.add(clearBtn);
p2.add(closeBtn);
addBtn.addActionListener(this);
clearBtn.addActionListener(this);
closeBtn.addActionListener(this);
addWindowListener(this);
contentPane.add(p2, BorderLayout.SOUTH);
setContentPane(contentPane);
}
public static void main(String[] args) {
BookingFrame ui = new BookingFrame();
ui.setVisible(true);
ui.setResizable(false);
}
//method to determine what action to handle
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
customerName = txt1.getText();
if (cmd.equals(addBtn.getText())) {
if (customerName.isEmpty())
label.setText("Please Enter");
else{
label.setText("OK");
System.out.println("Add informatiion");
}
}
if (cmd.equals(clearBtn.getText())) {
label.setText(cmd);
System.out.println("Clear Information");
System.out.println(txt1.getText());
}
if (cmd.equals(closeBtn.getText())) {
System.out.println("Program Exit");
System.exit(0);
}
}
//window listener
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}

