java姓名注册表源代码 java的注册表

如何向一个定义好的java数组中添加姓名,求代码

代码如下:

成都创新互联公司是一家专业提供汨罗企业网站建设,专注与成都网站设计、成都网站制作、HTML5建站、小程序制作等业务。10年已为汨罗众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

public class Test {

public static void main(String[] args) {

String[] nameArr = new String[5];

// 赋值4个

nameArr[0] = "name0";

nameArr[1] = "name1";

nameArr[2] = "name2";

nameArr[3] = "name3";

// 再添加一个

nameArr[4] = "最后添加的";

// 遍历数组,分别取到数组中的元素

for (int i = 0; i  nameArr.length; i++) {

System.out.print(nameArr[i] + " ");

}

}

}

运行效果:

求JAVA程序:用AWT组件设计一个填写用户注册信息的程序,它要包含用户ID、姓名、性别、学历、爱好等基本信

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.border.Border;

public class Test {

private JFrame frame;

private JTextField jid,jname,jsex,jedu,jlike;

private JLabel lid,lname,lsex,ledu,llike;

private JButton ok;

private JButton quit;

public Test(){//用户ID、姓名、性别、学历、爱好

frame=new JFrame("用户注册");

jid=new JTextField(10);

jname=new JTextField(10);

jsex=new JTextField(10);

jedu=new JTextField(10);

jlike=new JTextField(10);

lid=new JLabel("用户id:");

lname=new JLabel("用户名:");

lsex=new JLabel("性别:");

ledu=new JLabel("学历:");

llike=new JLabel("爱好:");

ok=new JButton("注册");

quit=new JButton("取消");

init();

showMe();

addEventHandler();

}

private void addEventHandler() {

quit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

}

public void init(){

frame.setLayout(new BorderLayout(2,2));

Border titled = BorderFactory.createTitledBorder(BorderFactory

.createMatteBorder(5, 5, 5, 5, Color.CYAN));

JPanel center = new JPanel();

center.setBorder(titled);

center.setLayout(new GridLayout(5,2,9,10));

JPanel south=new JPanel();

south.setLayout(new FlowLayout());

center.add(lid);

center.add(jid);

center.add(lname);

center.add(jname);

center.add(lsex);

center.add(jsex);

center.add(ledu);

center.add(jedu);

center.add(llike);

center.add(jlike);

south.add(ok);

south.add(quit);

frame.add(center,BorderLayout.CENTER);

frame.add(south,BorderLayout.SOUTH);

}

public void showMe(){

frame.setLocation(500, 300);

frame.setSize(210,280);

frame.setResizable(false);//不能拖动大小

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new Test().showMe();

}

}

java 读取注册表

我不知道你是怎样写得,我给你一段自己看下

package CenTo;

/**

* 本程序将在HKEY_CURRENT_USER\Software\JavaSoft\Prefs设置目录设置相应的操作。

* 本程序实现对注册表:

* 增加目录、增加键及相应的值、删除、保存为XML文件

*/

import java.io.*;

import java.util.prefs.*;

public class Prefs {

public static void main(String args[]) {

String denominations[] = {"One", "Two", "Five", "Ten", "Twenty"};

String pictures[] = {"Washington", "Jefferson", "Lincoln", "Hamilton", "Jackson"};

NodeChangeListener nodeChangeListener = new NodeChangeListener() {

public void childAdded(NodeChangeEvent event) {

Preferences parent = event.getParent();

Preferences child = event.getChild();

System.out.println(parent.name() + " has a new child " +child.name());

}

public void childRemoved(NodeChangeEvent event) {

Preferences parent = event.getParent();

Preferences child = event.getChild();

System.out.println(parent.name() + " lost a child " +child.name());

}

};

PreferenceChangeListener preferenceChangeListener = new PreferenceChangeListener() {

public void preferenceChange(PreferenceChangeEvent event) {

String key = event.getKey();

String value = event.getNewValue();

Preferences node = event.getNode();

System.out.println(node.name() + " now has a value of " + value + " for " + key);

}

};

// 设定需要根目录

Preferences prefs = Preferences.userRoot().node("/net/fubin/ibm");

// 添加监听

prefs.addNodeChangeListener(nodeChangeListener);

prefs.addPreferenceChangeListener(preferenceChangeListener);

//保存一个束的键名和相应的值

for (int i=0, n=denominations.length; i n; i++) {

prefs.put(denominations[i], pictures[i]);

}

// 显示所有的键名字及值

try {

String keys[] = prefs.keys();

for (int i=0, n=keys.length; i n; i++) {

System.out.println(keys[i] + ": " + prefs.get(keys[i], "Unknown"));

}

} catch (BackingStoreException e) {

System.err.println("Unable to read backing store: " + e);

}

// 建立 子目录

Preferences child = Preferences.userRoot().node("/net/fubin/ibm/foo");

//保存为XML文件

try {

FileOutputStream fos = new FileOutputStream("prefs.xml");

prefs.exportNode(fos);

} catch (Exception e) {

System.err.println("Unable to export nodes: " + e);

}

//删除新生成的接点

try {

prefs.removeNode();

} catch (BackingStoreException e) {

System.err.println("Unable to access backing store: " + e);

}

}

}


新闻标题:java姓名注册表源代码 java的注册表
分享网址:http://ybzwz.com/article/ddgchcc.html