新聞中心
用java寫一個(gè)程序,用變量保存自己的個(gè)人信息,并且輸出
import?java.util.Scanner;
創(chuàng)新互聯(lián)公司專注于瀏陽企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),成都商城網(wǎng)站開發(fā)。瀏陽網(wǎng)站建設(shè)公司,為瀏陽等地區(qū)提供建站服務(wù)。全流程按需定制開發(fā),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
public?class?個(gè)人信息?
{
public?static?void?main(String[]?args)?
{
System.out.println("\n\t\t==========簡單的個(gè)人信息錄入==========\n");
init();
}//初始化!
private?static?void?init()
{
/*int?a1?=?073;
long?b1?=?0xa38f;
System.out.println(a1+"....."+b1);*/
for?(;?;?)
{
System.out.println("請輸入姓名:");
String?a=Input.getName();
System.out.println("請輸入年齡:");
int b=Input.getAge();
System.out.println("請輸入學(xué)歷:");
String?c=Input.getEducation();
System.out.println("你輸入的信息^_^\t名字:"+a+"?????年齡:"+b+"?????學(xué)歷:"+c+"\n");
}
}
}
class?Input
{
private?static?Scanner?sc=new?Scanner(System.in);
private?Input(){}
static?String?getName()
{
String?name=sc.next();
return?name;
}
static?int?getAge()
{
int?age=sc.nextInt();
return?age;
}
static?String?getEducation()
{
String?education=sc.next();
return?education;
}
}
Java實(shí)現(xiàn)簡單個(gè)人信息錄入
數(shù)據(jù)庫就要你自己建了.
import?javax.swing.*;
import?javax.swing.event.*;
import?java.awt.*;
import?java.awt.event.*;
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;//用來顯示輸入的個(gè)人信息
private?JButton?ok;//確定按鈕
private?JPanel?northPanel,centerPanel,bigPanel;
public?PersonInfoRecorder(){
super("個(gè)人信息錄入器");
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("輸入個(gè)人簡要信息",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("輸入個(gè)人簡要信息")){
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為數(shù)據(jù)庫
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();
}
}
簡單個(gè)人簡歷java錄入程序 代碼
我?guī)湍銓懥四切㎎AVA代碼了,效果包你滿意!呵呵……
至于網(wǎng)頁的代碼嘛,這里就不貼了。你要的話HI我吧^_^。
JAVA代碼如下:
import?java.awt.BorderLayout;
import?javax.swing.*;
import?java.awt.Dimension;
import?java.awt.Rectangle;
public?class?MyLuRu?extends?JFrame?{
private?static?final?long?serialVersionUID?=?1L;
private?JPanel?jContentPane?=?null;
private?JLabel?jLabel?=?null;
private?JLabel?jLabel1?=?null;
private?JLabel?jLabel2?=?null;
private?JLabel?jLabel3?=?null;
private?JTextField?jTextField?=?null;
private?JRadioButton?jRadioButton?=?null;
private?JRadioButton?jRadioButton1?=?null;
private?JComboBox?jComboBox?=?null;
private?JComboBox?jComboBox1?=?null;
private?JButton?jButton?=?null;
private?JButton?jButton1?=?null;
private?JTextArea?jTextArea?=?null;
private?ButtonGroup?mybg=new?ButtonGroup();
/**
*?This?is?the?default?constructor
*/
public?MyLuRu()?{
super();
initialize();
}
/**
*?This?method?initializes?this
*
*?@return?void
*/
private?void?initialize()?{
this.setSize(268,?407);
this.setContentPane(getJContentPane());
this.setTitle("錄入");
this.addWindowListener(new?java.awt.event.WindowAdapter()?{
public?void?windowClosing(java.awt.event.WindowEvent?e)?{
System.exit(0);
}
});
this.setVisible(true);
}
/**
*?This?method?initializes?jContentPane
*
*?@return?javax.swing.JPanel
*/
private?JPanel?getJContentPane()?{
if?(jContentPane?==?null)?{
jLabel3?=?new?JLabel();
jLabel3.setBounds(new?Rectangle(16,?150,?65,?18));
jLabel3.setText("文化程度:");
jLabel2?=?new?JLabel();
jLabel2.setBounds(new?Rectangle(16,?108,?39,?18));
jLabel2.setText("專業(yè):");
jLabel1?=?new?JLabel();
jLabel1.setBounds(new?Rectangle(16,?66,?39,?18));
jLabel1.setText("性別:");
jLabel?=?new?JLabel();
jLabel.setBounds(new?Rectangle(16,?24,?39,?18));
jLabel.setText("姓名:");
jContentPane?=?new?JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel,?null);
jContentPane.add(jLabel1,?null);
jContentPane.add(jLabel2,?null);
jContentPane.add(jLabel3,?null);
jContentPane.add(getJTextField(),?null);
jContentPane.add(getJRadioButton(),?null);
jContentPane.add(getJRadioButton1(),?null);
mybg.add(jRadioButton);
mybg.add(jRadioButton1);
jContentPane.add(getJComboBox(),?null);
jContentPane.add(getJComboBox1(),?null);
jContentPane.add(getJButton(),?null);
jContentPane.add(getJButton1(),?null);
jContentPane.add(getJTextArea(),?null);
}
return?jContentPane;
}
/**
*?This?method?initializes?jTextField
*
*?@return?javax.swing.JTextField
*/
private?JTextField?getJTextField()?{
if?(jTextField?==?null)?{
jTextField?=?new?JTextField();
jTextField.setBounds(new?Rectangle(61,?24,?180,?18));
}
return?jTextField;
}
/**
*?This?method?initializes?jRadioButton
*
*?@return?javax.swing.JRadioButton
*/
private?JRadioButton?getJRadioButton()?{
if?(jRadioButton?==?null)?{
jRadioButton?=?new?JRadioButton();
jRadioButton.setBounds(new?Rectangle(61,?62,?38,?26));
jRadioButton.setText("男");
}
return?jRadioButton;
}
/**
*?This?method?initializes?jRadioButton1
*
*?@return?javax.swing.JRadioButton
*/
private?JRadioButton?getJRadioButton1()?{
if?(jRadioButton1?==?null)?{
jRadioButton1?=?new?JRadioButton();
jRadioButton1.setBounds(new?Rectangle(117,?62,?38,?26));
jRadioButton1.setText("女");
}
return?jRadioButton1;
}
/**
*?This?method?initializes?jComboBox
*
*?@return?javax.swing.JComboBox
*/
private?JComboBox?getJComboBox()?{
if?(jComboBox?==?null)?{
String[]?strcb={"計(jì)算機(jī)","電子","工商"};
jComboBox?=?new?JComboBox(strcb);
jComboBox.setBounds(new?Rectangle(62,?108,?93,?18));
}
return?jComboBox;
}
/**
*?This?method?initializes?jComboBox1
*
*?@return?javax.swing.JComboBox
*/
private?JComboBox?getJComboBox1()?{
if?(jComboBox1?==?null)?{
String[]?strcb2={"大專","本科","碩士","博士"};
jComboBox1?=?new?JComboBox(strcb2);
jComboBox1.setBounds(new?Rectangle(92,?150,?125,?18));
}
return?jComboBox1;
}
/**
*?This?method?initializes?jButton
*
*?@return?javax.swing.JButton
*/
private?JButton?getJButton()?{
if?(jButton?==?null)?{
jButton?=?new?JButton();
jButton.setBounds(new?Rectangle(66,?181,?60,?28));
jButton.setText("提交");
jButton.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
String?strname=jTextField.getText();
String?strsex="男";
if(jRadioButton1.isSelected()){
strsex="女";
}
String?strzy=jComboBox.getSelectedItem().toString();
String?strwh=jComboBox1.getSelectedItem().toString();
jTextArea.setText("姓名:"+strname+"\r\n"+"性別:"+strsex+"\r\n"+"專業(yè):"+strzy+"\r\n"+"文化:"+strwh);
}
});
}
return?jButton;
}
/**
*?This?method?initializes?jButton1
*
*?@return?javax.swing.JButton
*/
private?JButton?getJButton1()?{
if?(jButton1?==?null)?{
jButton1?=?new?JButton();
jButton1.setBounds(new?Rectangle(158,?181,?60,?28));
jButton1.setText("取消");
jButton1.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
System.exit(0);
}
});
}
return?jButton1;
}
/**
*?This?method?initializes?jTextArea
*
*?@return?javax.swing.JTextArea
*/
private?JTextArea?getJTextArea()?{
if?(jTextArea?==?null)?{
jTextArea?=?new?JTextArea();
jTextArea.setBounds(new?Rectangle(16,?225,?229,?130));
}
return?jTextArea;
}
public?static?void?main(String?args[]){
new?MyLuRu();
}
}
效果如下圖:
編寫一個(gè)JAVA程序,顯示你的個(gè)人檔案!
/*首先定義一個(gè)方法類*/
class method{
public String name;
public String sex;
public int age;
/*這里還可以定義很多關(guān)于你的檔案信息成員變量*/
/*下面這兩個(gè)是構(gòu)造方法*/
method(){
name="";
sex="";
age=0;
}
method(String name,String sex,int age){
this.name=name;
this.sex=sex;
this.age=age;
}
/*下面寫方法*/
String getName(String name){
return name;
}
String getSex(String sex){
return sex;
}
int getAge(int age){
return age;
}
}
/*寫一個(gè)測試類*/
public class Test{
public static void main(String args[]){
method a=new method("淺淺de夕陽","男",20);
System.out.println("姓名:"+a.getName());
System.out.println("性別:"+a.getSex());
System.out.println("年齡:"+a.getAge());
}
}
我寫的稍微復(fù)雜了點(diǎn),但是也就完善了點(diǎn),寫那幾個(gè)get方法,是為了更完整,那樣就算是你的成員變量改為私有的,在后面通過調(diào)用get方法也能返回變量的值。
編寫一個(gè)簡單的java程序顯示個(gè)人信息:姓名,性別,出生年月,愛好?
public class MyInfo {
public static void main(String []args) {
System.out.println("你好,以下是我的個(gè)人信息:");
System.out.println("姓名:李剛");
System.out.println("性別:女");
System.out.println("出生年月:1998-08");
System.out.println("愛好:上網(wǎng)");}
}
網(wǎng)站標(biāo)題:介紹個(gè)人信息java代碼 Java個(gè)人介紹
網(wǎng)頁URL:http://fisionsoft.com.cn/article/dodcppj.html