public class student
在網(wǎng)站制作、成都做網(wǎng)站中從網(wǎng)站色彩、結(jié)構(gòu)布局、欄目設(shè)置、關(guān)鍵詞群組等細(xì)微處著手,突出企業(yè)的產(chǎn)品/服務(wù)/品牌,幫助企業(yè)鎖定精準(zhǔn)用戶,提高在線咨詢和轉(zhuǎn)化,使成都網(wǎng)站營(yíng)銷成為有效果、有回報(bào)的無(wú)錫營(yíng)銷推廣。創(chuàng)新互聯(lián)專業(yè)成都網(wǎng)站建設(shè)10余年了,客戶滿意度97.8%,歡迎成都創(chuàng)新互聯(lián)客戶聯(lián)系。
{public static void main(String args[])
{
int iB=20;
String iA="姓名"; //這行如果是字符串要定義為String類型,而且賦值時(shí)要加上雙引號(hào)。
System.out.println("姓名是:"+iA+"年齡"+iB); //這行里的逗號(hào)改為加號(hào),否則報(bào)錯(cuò)。
}
}
一看就是新手入門,建議別著急寫代碼,現(xiàn)看看java的語(yǔ)法,java不是很難,慢慢來(lái):)
我?guī)湍銓懥四切㎎AVA代碼了,效果包你滿意!呵呵……
至于網(wǎng)頁(yè)的代碼嘛,這里就不貼了。你要的話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();
}
}
效果如下圖:
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("愛(ài)好:上網(wǎng)");}
}
/*首先定義一個(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è)測(cè)試類*/
public class Test{
public static void main(String args[]){
method a=new method("淺淺de夕陽(yáng)","男",20);
System.out.println("姓名:"+a.getName());
System.out.println("性別:"+a.getSex());
System.out.println("年齡:"+a.getAge());
}
}
我寫的稍微復(fù)雜了點(diǎn),但是也就完善了點(diǎn),寫那幾個(gè)get方法,是為了更完整,那樣就算是你的成員變量改為私有的,在后面通過(guò)調(diào)用get方法也能返回變量的值。
首先在任一目錄保存以下代碼
編譯代碼:javac PersonInfo.class
執(zhí)行代碼:java PersonInfo
代碼輸出效果如下:
id = 001, name = 張三, sex = 男, 年齡 = 12, 身份證 = 140421198809021102
id = 002, name = 李四, sex = 女, 年齡 = 25, 身份證 = 280421198809022103
id = 003, name = 王五, sex = 男, 年齡 = 33, 身份證 = 355421198809021104
id = 004, name = 趙六, sex = 女, 年齡 = 17, 身份證 = 472421198809021105
import java.util.ArrayList;
import java.util.List;
public class PersonInfo{
private String id; //id
private String name; //姓名
private int sex; //性別
private int age; //年齡
private String idCard; //身份證
@Override
public String toString() {
return "id = " + getId() + ", name = "
+ getName() + ", sex = " + (getSex()==0?"男":"女")
+ ", 年齡 = " + getAge() + ", 身份證 = " + getIdCard();
}
public PersonInfo(String id, String name, int sex, int age, String idCard) {
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
this.idCard = idCard;
}
public static void main(String[] args) {
PersonInfo p1 = new PersonInfo("001", "張三", 0, 12, "140421198809021102");
PersonInfo p2 = new PersonInfo("002", "李四", 1, 25, "280421198809022103");
PersonInfo p3 = new PersonInfo("003", "王五", 0, 33, "355421198809021104");
PersonInfo p4 = new PersonInfo("004", "趙六", 1, 17, "472421198809021105");
ListPersonInfo personList = new ArrayListPersonInfo();
personList.add(p1);
personList.add(p2);
personList.add(p3);
personList.add(p4);
for(PersonInfo p : personList){
System.out.println(p);
}
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getIdCard() {
return idCard;
}
public void setIdCard(String idCard) {
this.idCard = idCard;
}
}