import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class NICCode extends JFrame {
NICCode() {
setSize(600, 250);
setResizable(false);
setDefaultCloseOperation(3);
setLocationRelativeTo(null);
// JPanel
JPanel labelPanel = new JPanel(new FlowLayout(1));
JPanel leftBodyPanel = new JPanel(new GridLayout(3, 1));
JPanel bodyPanel = new JPanel(new GridLayout(3, 1));
JPanel buttonPanel = new JPanel(new FlowLayout(2));
JPanel textFieldPanel = new JPanel(new FlowLayout(0));
// JLabel
JLabel titleLabel = new JLabel("Find Your Birthday By NIC");
titleLabel.setFont(new Font("", 1, 25));
JLabel myLabel = new JLabel("CSG");
myLabel.setFont(new Font("", 1, 10));
JLabel enterNicLabel = new JLabel("Enter Your NIC :");
JLabel yourBirthDayLabel = new JLabel("Your Birth Day :");
JLabel yourGenderLabel = new JLabel("Gender :");
JLabel printBirthDayLabel = new JLabel("Your Birth Day");
JLabel printGenderLabel = new JLabel("Your Gender");
// JTextField
JTextField nicText = new JTextField(25);
nicText.setText("920000000V");
// JButton
JButton searchAgainButton = new JButton("Search Again");
JButton exitButton = new JButton("Exit");
// adds
add("North", labelPanel);
add("West", leftBodyPanel);
add("South", buttonPanel);
add(bodyPanel);
labelPanel.add(titleLabel);
leftBodyPanel.add(enterNicLabel);
leftBodyPanel.add(yourBirthDayLabel);
leftBodyPanel.add(yourGenderLabel);
textFieldPanel.add(nicText);
bodyPanel.add(textFieldPanel);
bodyPanel.add(printBirthDayLabel);
bodyPanel.add(printGenderLabel);
buttonPanel.add(myLabel);
buttonPanel.add(searchAgainButton);
buttonPanel.add(exitButton);
setVisible(true);
// pack();
String yearText = nicText.substring(0, 2);
String dateText = nicText.substring(2, 5);
String sex = "";
int year = Integer.parseInt(yearText);
int date = Integer.parseInt(dateText);
int month = 0;
if (date > 500) {
sex = "Feamale";
date -= 500;
} else {
sex = "Male";
}
int datesOfMonths[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
for (int i = 0; i < 12; i++) {
date = date - datesOfMonths[i];
month = i;
if (date < datesOfMonths[i + 1]) {
break;
}
}
if (month > 0) {
month += 1;
}
}
}
我刚刚创建了一个从 nic 查找生日的程序。我无法修复这个编译错误。我创建了一个 JTextField 来获取 Nic,然后我添加了子字符串方法来获取查找 nic 所需的数字。不幸的是,子字符串方法找不到 textField。它显示错误为“找不到符号”。这是一个文本字段。为什么方法找不到那个TextField。?