[实验目的]
1.掌握软件开发的基本流程
2.掌握常用的软件开发方式和工具。
[实验内容]
1.设计一个包含登录界面的计算器软件,该软件可以实现第一次作业中的全部功能,同时可以保存用户的历史计算记录(保存数据最好使用数据库)
[实验技术]
1,使用HBuilderX编写登录注册页面
2,使用Visio绘制相关流程图
3,使用java语言,eclipse连接数据库
流程图的设计

登陆界面前端代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录页面</title>
<link href="./css/new_file.css" rel="stylesheet"/>
</head>
<body id="Body">
<form action="users" method="post" novalidate>
<div id="Background" >
<div id="z">
登录:<input id="names" name="names" type="text" placeholder="请输入用户名"/>
<br />
密码:<input id="pass" name="pass" type="password" placeholder="请输入密码" />
<br />
</div>
<div id="BetweenButton" >
<input type="button" value="登录" onclick="login()" />
<input style="margin-left: 10px;" type="button" value="注册" onclick="register()" />
</div>
</div>
</form>
<script>
function login(){
var username = document.getElementById("names").value;
var password = document.getElementById("pass").value;
var user = {
username: username,
password: password
};
var fakeResponse = {success: false };
setTimeout(function(){
if(fakeResponse.success){
alert("登录成功!");
}
else{
alert("用户名或密码不正确!");
}
}, 1000);
}
function register(){
alert("未注册!请先注册!");
}
</script>
</body>
</html>
#fram{
background-color: greenyellow;
}
#Background{
height: 400px;
width: 500px;
background-color: rgba(176, 196, 222,0.3);
background-repeat: no-repeat;
background-size: 100% auto;
border-radius: 10px;
position: absolute;
left: 20%;
top: 25%;
}
#BetweenButton{
position: absolute;
width: 200px;
left: 40%;
margin-top: 15px;
}
#Body{
background-image: url("../img/a4.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
#names{
margin-top: 30px;
}
#pass{
margin-top: 30px;
}
#z{
margin-left: 25%;
margin-top: 25%;
}
登陆界面效果如下
1,当用户名,密码错误时,提示“用户名,密码不正确”

2,当用户名,密码正确时,提示“登陆成功”

连接数据库
package com.hsp.edu;
import com.mysql.cj.jdbc.Driver;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
//进一步优化,将信息写入到配置文件
public static void connect05() throws IOException, ClassNotFoundException, SQLException {
//通过Properties对象获取配置文件信息
Properties properties = new Properties();
properties.load(new FileInputStream("src\\mysql.properties"));//此时已经将配置文件的信息读取到了Properties中
//获取相关信息
final String user = properties.getProperty("user");//用户
final String password = properties.getProperty("password");//密码
final String url = properties.getProperty("url");//url
final String driver = properties.getProperty("driver");
Class.forName(driver);//注册驱动
final Connection connection = DriverManager.getConnection(url, user, password);//获取连接
System.out.println(connection);
}
package com.hsp;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class Jdbc02 {
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
//前置工作:获取配置文件中的信息
Properties properties = new Properties();
properties.load(new FileInputStream("src\\mysql1.properties"));//读取信息到集合中
final String driver = properties.getProperty("driver");//获取全类名
final String url = properties.getProperty("url");//获取url
final String user = properties.getProperty("user");//获取用户名
final String password = properties.getProperty("password");//获取密码
System.out.println(properties);
//1.注册驱动
Class.forName(driver);
//2.获取连接
final Connection connection = DriverManager.getConnection(url, user, password);
//3.执行 SQL语句
//String sql1 = "CREATE TABLE news(id INT,content VARCHAR(32))";
String sql2="INSERT INTO news VALUES (1,'张三','123456'),(2,'李四','56789'),(3,'刘琴','123456');
final Statement statement = connection.createStatement();
//final int row1 = statement.executeUpdate(sql1);//返回影响的行数
final int row2 = statement.executeUpdate(sql2);//返回影响的行数
final int row3 = statement.executeUpdate(sql3);
//:验证是否执行成功
/*if(row1!=0){
System.out.println("执行成功");
}else {
System.out.println("执行失败");
}*/
if (row2!=0){
System.out.println("执行成功");
}else {
System.out.println("执行失败");
}
if(row3!=0){
System.out.println("执行成功");
}else {
System.out.println("执行失败");
}
//4.关闭资源
statement.close();
connection.close();
}
}