十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
package?jdbcproj;
成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的新區(qū)網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
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);
//記得要寫這個(gè)
setVisible(true);
}
}
package student;
import java.util.Scanner;
public class teststudent {
public static void main(String args[]){
System.out.println("************************學(xué)生成績管理系統(tǒng)*********************");
System.out.println("請輸入要管理的學(xué)生人數(shù):");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
studentMassage stum = new studentMassage(n);
int flag = 1;
while(flag == 1){
System.out.println("1.輸入學(xué)生信息");
System.out.println("2.通過姓名查找學(xué)生信息");
System.out.println("3.顯示全部學(xué)生信息");
System.out.println("4.退出系統(tǒng)");
int op = sc.nextInt();
switch(op){
case 1:stum.addStudent(n);
new Scanner(System.in).nextLine();
break;
case 2:
System.out.println("輸入學(xué)生姓名:");
String name = sc.next();
stum.FindStudent(name);
new Scanner(System.in).nextLine();
break;
case 3:
stum.showallStudent();
new Scanner(System.in).nextLine();
break;
case 4:
flag = 0;
System.out.println("已退出系統(tǒng)!");
break;
default:
System.out.println("輸入有誤!");
new Scanner(System.in).nextLine();
}
}
}
}
class Date{
int year;
int month;
int day;
/*public Date(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
public Date(){}*/
public String showDate(){
return year + "/"+ month+"/"+day;
}
}
class student{
int id;
String name;
Date date;
float score;
public student(){
id = 0;
name = null;
date = null;
score = 0f;
}
public void showStudent(){
System.out.println( id + " " + name + " "+ " " + date.showDate()+" "+score);
}
}
class studentMassage{
private student[] stu;
private int flag;
public studentMassage(int n){
flag = 0;
if(stu == null){
stu = new student[n];
for(int i =0;in;++i){
stu[i] = new student();
}
}
}
public void addStudent(int n){
flag = 1;
Scanner sc = new Scanner(System.in);
System.out.println("請輸入"+n+"個(gè)學(xué)生信息");
for(int i = 0 ;istu.length;++i){
stu[i].date = new Date();
System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生學(xué)號:");
stu[i].id = sc.nextInt();
System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生姓名:");
stu[i].name = sc.next();
System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生出生年份:");
stu[i].date.year = sc.nextInt();
System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生出生月份:");
stu[i].date.month = sc.nextInt();
System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生出生日期:");
stu[i].date.day = sc.nextInt();
//stu[i].date = new Date(year,month,day);
System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生分?jǐn)?shù):");
stu[i].score = sc.nextFloat();
}
}
public void FindStudent(String sname){
student find = null;
if(flag != 0){
for(int i = 0;istu.length;++i){
if(sname.equals(stu[i].name))
find = stu[i];
}
if(find == null)
System.out.println("查無此人!");
else
find.showStudent();
}else
System.out.println("沒有輸入學(xué)生信息!");
}
public void showallStudent(){
System.out.println("所有學(xué)生的信息如下:");
System.out.println("學(xué)號 姓名 生日 分?jǐn)?shù)");
for(int i = 0;istu.length;++i){
stu[i].showStudent();
}
}
}
Java學(xué)生成績管理系統(tǒng)源代碼:
import Java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
/*
* Created on 2005-1-11
*/
/**
* @author 讓煒
* @since 1.0
*
* TODO 學(xué)生成績治理系統(tǒng)
* 通過學(xué)號查找,修改,刪除數(shù)據(jù)
*
*/
public class LittleProgram
{
static boolean isDelete = true;
static boolean isFind = true;
public static void main(String [] args)//主方法,程序從這里開始運(yùn)行
throws IOException,NumberNotFoundException
{
int choice=-1;
do{
LittleProgram lp = new LittleProgram();
System.out.println();
System.out.println("\t####################################");
System.out.println();
System.out.println("\t\t Java學(xué)生成績治理系統(tǒng)1.1");
System.out.println("\t\t請用學(xué)號查找,修改,刪除數(shù)據(jù)");
System.out.println();
System.out.println("\t####################################\n");
System.out.print("1.增加數(shù)據(jù):\n"+
"2.查找數(shù)據(jù):\n"+
"3.刪除數(shù)據(jù):\n"+
"4.清除所有數(shù)據(jù):\n"+
"5.把數(shù)據(jù)全部打印到屏幕\n"+
"6.把成績按學(xué)號排序\n"+
"7.修改數(shù)據(jù)\n"+
"8.統(tǒng)計(jì)已記錄成績學(xué)生數(shù)\n"+
"9.關(guān)于作者\(yùn)n"+
"0.退出程序.\n" +
"輸入:");
BufferedReader in = //從終
new BufferedReader( //端接
new InputStreamReader(System.in));//收數(shù)
String inputLine = in.readLine(); //字選
choice= Integer.valueOf(inputLine).intValue();//項(xiàng);
switch(choice)
{
case 1: {//1.增加數(shù)據(jù)
String str = lp.inputData();
lp.addData(str);
System.out.println("增加數(shù)據(jù)成功.");
timeOut(1);
}break;
case 2: {//2.查找數(shù)據(jù)
long find = 0;
資料引用: