java中个人信息的代码 java中个人信息的代码有哪些( 二 )


import java.sql.*;
public class PersonInfoRecorder extends JFrame implements ActionListener{
private JLabel nameLabel,sexLabel,ageLabel,tipLabel;//用来显示姓名、性别、年龄和提示栏
private JTextField nameTextField,ageTextField;//用来输入姓名和年龄
private JComboBox sex;//用来选择性别
private JTextArea info;//用来显示输入java中个人信息的代码的个人信息
private JButton ok;//确定按钮
private JPanel northPanel,centerPanel,bigPanel;
public PersonInfoRecorder(){
super("个人信息录入器");
nameLabel = new JLabel("姓名");
sexLabel = new JLabel("性别");
ageLabel = new JLabel("年龄");
nameTextField = new JTextField(6);
ageTextField = new JTextField(6);
String sexs[] = {"男","女" };
sex = new JComboBox(sexs);
/*sex.addItemListener(
new ItemListener(){
public void itemStateChanged(ItemEvent event){
if(event.getStateChange() == ItemEvent.SELECTED){
String fsex = (String)sex.getSelectedItem();
info.setText(fsex);
}
}
});*/
ok = new JButton("确定");
ok.addActionListener(this);
northPanel = new JPanel();
northPanel.add(nameLabel);
northPanel.add(nameTextField);
northPanel.add(sexLabel);
northPanel.add(sex);
northPanel.add(ageLabel);
northPanel.add(ageTextField);
northPanel.add(ok);
info = new JTextArea("输入个人简要信息",5,30);
info.setLineWrap(true);
centerPanel = new JPanel();
JScrollPane scroll = new JScrollPane(info);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
centerPanel.add(scroll);
bigPanel = new JPanel();
bigPanel.add(northPanel);
bigPanel.add(centerPanel);
getContentPane().add(bigPanel);
setSize(400,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(nameTextField.getText().equals("")){
JOptionPane.showMessageDialog(null, "姓名不能为空!请输入姓名.");
}else{
String inform = info.getText();
if(inform.equals("输入个人简要信息")){
inform = "";
}
info.setText("姓名:" + nameTextField.getText()
+ "\n性别:" + (String)sex.getSelectedItem()
+ "\n年龄:" +
"\n简介:\n" + inform);
try{ //这里的异常处理语句是必需的.否则不能通过编译!
String sqlStr = "insert into Person values(nameTextField.getText(),"+
"(String)sex.getSelectedItem(),ageTextField.getText(),inform)";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Person";
//Person为数据库
String user="sa";
String password="";
Connection con = DriverManager.getConnection(url,user,password);
Statement st = con.createStatement();
st.executeUpdate( sqlStr );
st.close();
con.close();
} catch(ClassNotFoundException exception) {
exception.printStackTrace(System.out);
}
catch(Exception err) {
err.printStackTrace(System.out);
}
}
}
public static void main(String[] args) {
PersonInfoRecorder application = new PersonInfoRecorder();
}
}
java里性别代码怎么写1、单独创建一个客户类Customerjava中个人信息的代码 , 里面分别定义属性:客户姓名、客户年龄、客户是否会员,创建一个用来操作Customer客户类java中个人信息的代码的CustomerBiz客户操作类,接下来的代码编写,都是在CutomerBiz客户操作类中进行 。
1、在CustomerBiz客户操作类中,创建一个用来存储Customer类型的对象数据的数组,定义添加客户信息的有参方法 , 该有参方法的形参,是Customer客户类的数据类型 , 定义显示客户信息的方法,定义main方法,在main方法中编写对Customer类对象的操作的代码 。

推荐阅读