重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
package?jdbcproj;
公司主營(yíng)業(yè)務(wù):網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)建站推出丘北免費(fèi)做網(wǎng)站回饋大家。
import?java.sql.*;
import?java.awt.BorderLayout;
import?java.awt.EventQueue;
import?javax.swing.JFrame;
import?javax.swing.JPanel;
import?javax.swing.border.EmptyBorder;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JTextField;
import?javax.swing.JButton;
import?java.awt.event.ActionListener;
import?java.sql.Connection;
import?java.sql.PreparedStatement;
import?java.sql.SQLException;
import?java.awt.event.ActionEvent;
public?class?MainFrame?extends?JFrame?{
private?JPanel?contentPane;
private?JTextField?txtname;
private?JTextField?txtpassword;
/**
?*?Launch?the?application.
?*/
public?static?void?main(String[]?args)?{
EventQueue.invokeLater(new?Runnable()?{
public?void?run()?{
try?{
MainFrame?frame?=?new?MainFrame();
frame.setVisible(true);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
});
}
/**
?*?Create?the?frame.
?*/
public?MainFrame()?{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,?100,?661,?399);
contentPane?=?new?JPanel();
contentPane.setBorder(new?EmptyBorder(5,?5,?5,?5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel?lblNewLabel?=?new?JLabel("\u7528\u6237\u540D");
lblNewLabel.setBounds(114,?51,?72,?18);
contentPane.add(lblNewLabel);
JLabel?lblNewLabel_1?=?new?JLabel("\u5BC6\u7801");
lblNewLabel_1.setBounds(114,?106,?72,?18);
contentPane.add(lblNewLabel_1);
txtname?=?new?JTextField();
txtname.setBounds(261,?48,?86,?24);
contentPane.add(txtname);
txtname.setColumns(10);
txtpassword?=?new?JTextField();
txtpassword.setBounds(261,?103,?86,?24);
contentPane.add(txtpassword);
txtpassword.setColumns(10);
JButton?btnadd?=?new?JButton("\u589E\u52A0");
btnadd.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名和密碼不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users?u=new?Users();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAO?usdo=new?UserDAO();
usdo.addUser(u);
}
}
});
btnadd.setBounds(45,?205,?113,?27);
contentPane.add(btnadd);
JButton?btndelete?=?new?JButton("\u5220\u9664");
btndelete.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?arg0)?{
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
UserDAO?usdo=new?UserDAO();
usdo.delUser(txtname.getText())
}
}
});
btndelete.setBounds(172,?205,?113,?27);
contentPane.add(btndelete);
JButton?btnupdate?=?new?JButton("\u4FEE\u6539");
btnupdate.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名和密碼不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users?u=new?Users();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAO?usdo=new?UserDAO();
usdo.updateUser(u)
}
}
});
btnupdate.setBounds(300,?205,?113,?27);
contentPane.add(btnupdate);
JButton?btnfind?=?new?JButton("\u67E5\u8BE2");
btnfind.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users?u=new?Users();
UserDAO?usdo=new?UserDAO();
u=usdo.findUser(txtname.getText(),?txtpassword.getText());
if(u!=null){
JOptionPane.showMessageDialog(getContentPane(),?"該用戶存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
JOptionPane.showMessageDialog(getContentPane(),?"該用戶不存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
}
}
});
btnfind.setBounds(427,?205,?113,?27);
contentPane.add(btnfind);
//記得要寫(xiě)這個(gè)
setVisible(true);
}
}
java編寫(xiě)這個(gè)通訊錄管理系統(tǒng)
java編寫(xiě)這個(gè)通訊錄管理系統(tǒng)_Java如何實(shí)現(xiàn)通訊錄管理系統(tǒng)
咕嚕嚕在芬蘭
原創(chuàng)
關(guān)注
3點(diǎn)贊·2305人閱讀
Java如何實(shí)現(xiàn)通訊錄管理系統(tǒng)
發(fā)布時(shí)間:2020-07-28 09:39:42
來(lái)源:億速云
閱讀:65
作者:Leah
這篇文章將為大家詳細(xì)講解有關(guān)Java如何實(shí)現(xiàn)通訊錄管理系統(tǒng),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
本文實(shí)例為大家分享了java實(shí)現(xiàn)通訊錄管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
完成項(xiàng)目的流程:
1.根據(jù)需求,確定大體方向
2.功能模塊分析
3.界面實(shí)現(xiàn)
4.功能模塊設(shè)計(jì)
5.coding
6.代碼測(cè)試
下面是源代碼:import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.text.html.HTMLDocument.Iterator;
class Infro{
public String id;
public String name;
public String sex;
public String address;
public String e_mail;
public String phoneNumber;
static int index = 0;
static ArrayList list = new ArrayList();
static int len = list.size();
//構(gòu)造函數(shù)
public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){
this.id = id;
this.name = name;
this.sex = sex;
this.address = address;
this.e_mail = e_mail;
this.phoneNumber = phoneNumber;
}
public String toString(){
return "編號(hào):"+id+" 姓名:"+name+" 性別:"+sex+" 通訊地址:"+address+" 郵箱地址:"+e_mail+" 電話:"+phoneNumber;
}
/**
* 添加功能
**/
public static void addFunction(){//添加功能
Infro infro = new Infro("","","","","","");
System.out.println("請(qǐng)輸入添加的數(shù)據(jù):");
Scanner in = new Scanner(System.in);
System.out.println("輸入編號(hào):");
infro.id = in.next();
System.out.println("輸入姓名:");
infro.name = in.next();
System.out.println("輸入性別:");
infro.sex = in.next();
System.out.println("輸入通訊地址:");
infro.address = in.next();
System.
out.println("輸入郵箱地址:");
infro.e_mail = in.next();
System.out.println("輸入電話:");
infro.phoneNumber = in.next();
list.add(index,infro);
index++;
if(list.isEmpty()){
System.out.println("數(shù)據(jù)添加失敗啦");
}else{
System.out.println("數(shù)據(jù)添加成功啦");
len++;//list集合長(zhǎng)度加一
// System.out.println(list.get(0).toString());
}
}
// public static void deleteFunction(){//刪除功能
// System.out.println("輸入要?jiǎng)h除的聯(lián)系人的編號(hào)");
// Scanner in_2 = new Scanner(System.in);
// String d1 = in_2.nextLine();
// for(int a= 0; a
// if(d1.equals(list.get(a).id)){
// list.remove(list.get(a));
// len --;
// }
// }
// }
/**
* 刪除功能
**/
public static void deleteFunction(){
System.out.println("輸入要?jiǎng)h除的聯(lián)系人的編號(hào)");
Scanner in_2 = new Scanner(System.in);
String d1 = in_2.nextLine();
java.util.Iterator it = list.iterator();
while (it.hasNext()){
Infro infro = it.next();
if (infro.id.equals(d1)){
it.remove();
--index;//一定要加這個(gè),否則當(dāng)做了刪除操作再做添加操作的時(shí)候會(huì)出現(xiàn)異常(類(lèi)似于指針,棧)
System.out.println("刪除完畢"+"此時(shí)通訊錄記錄條數(shù)為:" + --len);
}
}
}
/**
* 修改功能
**/
public static void reditFunction(){
System.out.println("輸入要修改的通訊錄的Id");
Scanner in_r = new Scanner(System.in);
String r1 = in_r.nextLine();
for(int a = 0; a len;a++){
if(r1.equals(list.get(a).id)){
System.out.println("輸入修改后的姓名:");
String name_1 = in_r.next();
list.get(a).name = name_1;
System.out.println("輸入修改后的性別:");
String sex_1 = in_r.next();
list.get(a).sex = sex_1;
System.out.println("輸入修改后的通訊地址:");
String address_1 = in_r.next();
list.get(a).address = address_1;
System.out.println("輸入修改后的郵箱地址:");
String e_mail_1 = in_r.next();
list.get(a).e_mail = e_mail_1;
System.out.println("輸入修改后的電話:");
String phoneNumber_1 = in_r.next();
list.get(a).phoneNumber = phoneNumber_1;
System.out.println("數(shù)據(jù)修改完畢");
}
}
}
/**
* 查詢功能
**/
public static void searchFunction() throws Exception{//查詢功能
System.out.println("請(qǐng)輸入要查詢的姓名:");
Scanner in_1 = new Scanner(System.in);
String s1=in_1.nextLine();
for(int a= 0; a
if(s1.equals(list.get(a).name)){
System.out.println(list.get(a).toString());
}
}
}
/**
* 顯示功能
**/
public static void showFunction(){
for(int i = 0 ;i
System.out.println(list.get(i).toString());
}
}
/**
* 保存功能
**/
public static void writeFunction() throws IOException{
FileWriter writer = new FileWriter("通訊錄管理.txt");
for(int i = 0 ;i
String []strwriter = new String[len];
strwriter[i]=list.get(i).toString();
writer.write(strwriter[i]);
writer.write("\r\n");
System.out.println("成功寫(xiě)入一行數(shù)據(jù)到 通訊錄管理.txt 中");
}
writer.close();//關(guān)閉寫(xiě)入流,釋放資源
}
/**
* 讀取功能
**/
public static void readFunction() throws IOException{
FileReader reader = new FileReader("通訊錄管理.txt");
BufferedReader br = new BufferedReader(reader);
String str;
while((str = br.readLine()) != null){//每次讀取一行文本,判斷是否到達(dá)文件尾
System.out.println(str);
}
br.close();
}
}
public class Demo extends JFrame {
/**
* 界面設(shè)計(jì)
**/
public Demo(){
Container c = getContentPane(); //定義一個(gè)頂級(jí)容器c
JPanel jp = new JPanel(); //新建JPanel面板--jp
JButton button1 = new JButton("新建聯(lián)系人");
JButton button2 = new JButton("刪除聯(lián)系人");
JButton button3 = new JButton("編輯聯(lián)系人");
JButton button4 = new JButton("查找聯(lián)系人");
JButton button5 = new JButton("顯示所有聯(lián)系人");
JButton button6 = new JButton("保存聯(lián)系人到本地");
JButton button7 = new JButton("讀取本地聯(lián)系人");
jp.setLayout(new GridLayout(2,4,5,5));//新建網(wǎng)格布局管理器(行數(shù),列數(shù),組件間的水平垂直間距)
jp.add(button1);
jp.add(button2);
jp.add(button3);
jp.add(button4);
jp.add(button5);
jp.add(button6);
jp.add(button7);
c.add(jp);//將JPanel面板jp添加到頂級(jí)容器c中
setSize(600,500);
setTitle("*通 訊 錄 管 理 系 統(tǒng)*");
setVisible(true);
setResizable(false);//窗體大小由程序員決定,用戶不能自由改變大小
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
/**
*按鍵響應(yīng)
*
**/
button1.addActionListener(new ActionListener(){//添加功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.addFunction();
}
});
button2.addActionListener(new ActionListener(){//刪除功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.deleteFunction();
}
});
button3.addActionListener(new ActionListener(){//修改功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.reditFunction();
}
});
button4.addActionListener(new ActionListener(){//查詢功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
try {
Infro.searchFunction();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
button5.addActionListener(new ActionListener(){//顯示功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
Infro.showFunction();
}
});
button6.addActionListener(new ActionListener(){//保存功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
try {
Infro.writeFunction();
} catch (IOException e) {
e.printStackTrace();
}
}
});
button7.addActionListener(new ActionListener(){//讀取功能實(shí)現(xiàn)
public void actionPerformed(ActionEvent arg0){
try {
Infro.readFunction();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Demo();
Infro a = new Infro("", "", "", "", "", "");
}
}
關(guān)于Java如何實(shí)現(xiàn)通訊錄管理系統(tǒng)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
我給講概思路:1:第步:設(shè)計(jì)數(shù)據(jù)庫(kù)般像種型宿舍管理系統(tǒng)選用mysql作數(shù)據(jù)庫(kù)設(shè)計(jì)表包括表字段名字段及表間關(guān)系2:第二布:確認(rèn)使用技術(shù)作java選用Springmvc作mvc框架畢竟比較靈簡(jiǎn)單Spring必須用管理事務(wù)Hibernate作臺(tái)數(shù)據(jù)庫(kù)管理框架jsp作頁(yè)面表現(xiàn)層程序比較健壯擴(kuò)展起比較便3:第二步基礎(chǔ)接建立Bean類(lèi)比類(lèi)、宿舍類(lèi)等等映射數(shù)據(jù)庫(kù)表字段編寫(xiě)Service層、Dao層等等建立數(shù)據(jù)處理邏輯4:實(shí)現(xiàn)表現(xiàn)層寫(xiě)jsp頁(yè)面想前臺(tái)展示內(nèi)容寫(xiě)jsp面選用技術(shù)juqery,js考慮用戶體驗(yàn)用ajax實(shí)現(xiàn)異步刷新交互5:前臺(tái)相互通信用juint進(jìn)行集測(cè)試看看數(shù)據(jù)否按照邏輯準(zhǔn)確顯示期測(cè)試等等嫌麻煩采用ssh框架直接用jsp+servlet寫(xiě)比較簡(jiǎn)單原理概差層沒(méi)清晰明
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
/*********************************
* 停車(chē)場(chǎng)管理
* author zhang
*2013-12-13
********************************/
public class CarStopManager {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("請(qǐng)入車(chē)牌號(hào):");
String carno = sc.next();
CarStopManager carStopManager = new CarStopManager();
carStopManager.setCarNo(carno);//設(shè)置車(chē)牌號(hào)
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sdate = format.format(new Date());
System.out.println("當(dāng)前時(shí)間(入場(chǎng)時(shí)間)是: "+sdate);
System.out.println("需要開(kāi)出車(chē)場(chǎng)嗎?yes/no:");
String yesno = sc.next();
if(yesno.equals("yes")){
String edate = format.format(new Date());
System.out.println("出場(chǎng)時(shí)間是: "+edate);
//計(jì)算方法
carManager(2, sdate, edate,carStopManager);
}
}
/**
* 計(jì)算方法
*/
public static void carManager(int type,String starTime,
String endTime,CarStopManager carStopManager){
if(type==1){//按月收費(fèi)
System.out.println("如若沒(méi)有繳納月費(fèi)請(qǐng)繳納800元,如若繳納將不再提示!");
}else{
/**
* 一般不會(huì)有停車(chē)幾個(gè)月的吧?先不考慮停車(chē)幾年或者幾個(gè)月的
*/
String sDay = starTime.substring(8,10);//入場(chǎng)日期(天)
String sHour = starTime.substring(11, 13);//入場(chǎng)小時(shí)
String sMM = starTime.substring(14,16);//入場(chǎng)分鐘
String eDay = starTime.substring(8,10);//出場(chǎng)日期(天)
String eHour = endTime.substring(11, 13);//出廠小時(shí)
String eMM = endTime.substring(14,16);//出廠分鐘
float money = 0;//需繳納的費(fèi)用
int shour = Integer.parseInt(sHour);
int ehour = Integer.parseInt(eHour);
int smm = Integer.parseInt(sMM);
int emm = Integer.parseInt(eMM);
int rehour = 0;//停車(chē)幾個(gè)小時(shí)
if(sDay.equals(eDay)){//同一天
//當(dāng)天6點(diǎn)到20點(diǎn)之間
if((shour=6 shour=20)){
if(ehour - shour=6){//6個(gè)小時(shí)之內(nèi)
rehour = (ehour - shour)*60+(emm - smm);//停車(chē)多少分鐘
//需要繳納的費(fèi)用 前15分鐘免費(fèi) 以后每15分鐘1.5元
money = (rehour/15-15)*1.5f;
}else{
int hour = ehour - shour -6;//6小時(shí)除外剩余小時(shí)數(shù)
rehour = 6*60+(emm - smm);//停車(chē)多少分鐘
//前15分鐘免費(fèi) 以后每15分鐘1.5元 超過(guò)6小時(shí)15分鐘2元
money = ((rehour/15-15)*1.5f)+(hour*60/2);
}
}
}else{//跨天 20點(diǎn)到 6點(diǎn)之間
//todo
}
System.out.println("您的車(chē)牌號(hào)是:"+carStopManager.getCarNo()+";\n" +
"您此次停車(chē)花費(fèi)的費(fèi)用是: "+money+"元");
}
}
/**
* bean屬性
*/
private String carNo;//車(chē)牌號(hào)
private String startTime;//入場(chǎng)時(shí)間
private String endTime;//出場(chǎng)時(shí)間
/**
* 無(wú)參構(gòu)造
*/
public CarStopManager(){
super();
}
/**
* 有參數(shù)構(gòu)造
* @param carNo
* @param startTime
* @param endTime
*/
public CarStopManager(String carNo, String startTime, String endTime) {
super();
this.carNo = carNo;
this.startTime = startTime;
this.endTime = endTime;
}
/**
* 設(shè)置get方法
* @return
*/
public String getCarNo() {
return carNo;
}
/**
* 設(shè)置set方法
* @param carNo
*/
public void setCarNo(String carNo) {
this.carNo = carNo;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}