文章目录
- 汽车销售管理系统
- **背景**
- **环境**
- **项目结构**
- 项目详情
- **数据库**
- **DBConn.java**
- **Login.java**
- **Data.java**
- **CircleProgressBar.java**
- 运行截图
汽车销售管理系统
背景
Java基础课程设计
环境
- 数据库:MySQL8.0
- 开发环境:JDK1.8
- 开发工具:MyEclipse
项目结构
项目详情
DAO层
- GoodsDao.java
- GoodsDaoImpl.java
- PurchaseDao.java
- PurchaseImpl.java
- SalesDao.java
- SalesDaoImpl.java
- UserDao.java
- UserDaoImpl.java
DBConn层 - DBConn.java
JFrame层 - CircleProgressBar.java
- Data.java
- goodsAdd.java
- goodsDelete.java
- goodsUpdate.java
- HomePage.java
- Login.java
- MyFrame.java
- Purchase.java
- purchaseAdd.java
- purchaseDelete.java
- Sales.java
- salesAdd.java
- salesDelete.java
- userMana.java
MySQL层 - Goods.java
- Purchase.java
- Sales.java
- User.java
数据库
DBConn.java
数据库连接
package DBConn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConn
{//连接到数据库private static String driver;private static String url;private static String username;private static String password;static{ driver = "com.mysql.cj.jdbc.Driver";url = "jdbc:mysql://localhost:3306/salesMS?serverTimezone=UTC&useSSL=false";username = "root";password = "123456";}public static Connection open(){try {Class.forName(driver);return DriverManager.getConnection(url,username,password);} catch (Exception e) {e.printStackTrace();}return null;}public static void close(Connection conn){if(conn!=null)try {conn.close();} catch (SQLException e) {e.printStackTrace();}}
}
Login.java
登录界面
package JFrame;import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;import DAO.UserDaoImpl;
import DBConn.DBConn;
import MySQL.User;public class Login extends JFrame implements ActionListener{private static final long serialVersionUID = -705511349178672604L;JLabel bg;JTextField t1,t2;CheckboxGroup type;Checkbox cb1,cb2;JButton b1;Connection conn;public Login(){ImageIcon bg1 = new ImageIcon(HomePage.class.getResource("userbg2.jpg"));ImageIcon bg2 = new ImageIcon(HomePage.class.getResource("signin.jpg"));bg = new JLabel(bg1);conn = DBConn.open();//e1 = new JLabel("用户名:");//e2 = new JLabel("密码:");t1 = new JTextField(10);t2 = new JTextField(10);t1.setText("");t2.setText("");type = new CheckboxGroup();cb1 = new Checkbox("user",true,type);cb2 = new Checkbox("manager",false,type);b1 = new JButton(bg2);//字体设置Font f = new Font("隶书",Font.BOLD,23);t1.setFont(f);t2.setFont(f);cb1.setFont(f);cb2.setFont(f);b1.setFont(f);//位置设置this.setLayout(null); // 绝对布局t1.setBounds(417, 243,226, 26);t2.setBounds(417, 276,226, 26);cb1.setBounds(420, 309,110,30); cb2.setBounds(535, 309,110,30);b1.setBounds(470, 340,97,48);bg.setBounds(0, 0, 1024, 512);//add(e1); add(e2);add(t1); add(t2);add(cb1); add(cb2);add(b1);this.add(bg);//监听b1.addActionListener(this);//窗体设置this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); //关闭窗口监听this.setBounds(200,100,1024,512);setTitle("用户登录");setVisible(true);//setResizable(false);}@Overridepublic void actionPerformed(ActionEvent e) {User u = new User();UserDaoImpl udi = new UserDaoImpl();try{u = udi.getUserById(t1.getText());if(t2.getText().equals(u.getPassword())){ //这里我没有加入判断用户和管理员的方法this.setVisible(false); //隐藏登录窗口new MyFrame(u);} }catch (Exception e1) {JOptionPane.showMessageDialog(null,"用户名或密码错误","Erro",JOptionPane.ERROR_MESSAGE);t1.requestFocus();}}public static void main(String[] args) {new Login();}
}
Data.java
数据管理界面
package JFrame;import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;import DAO.GoodsDaoImpl;
/** 数据管理界面*/
public class Data extends JPanel {private static final long serialVersionUID = -6038402709001455579L;JButton bt1,bt2,bt3,bt4,home;JLabel lb1,bg;JTextArea ta;public Data() {ImageIcon img1 = new ImageIcon(HomePage.class.getResource("add.png"));ImageIcon img2 = new ImageIcon(HomePage.class.getResource("modify.png"));ImageIcon img3 = new ImageIcon(HomePage.class.getResource("delete.png"));ImageIcon img4 = new ImageIcon(HomePage.class.getResource("update.png"));ImageIcon img5 = new ImageIcon(HomePage.class.getResource("1.png"));ImageIcon home1 = new ImageIcon(HomePage.class.getResource("back.png"));ImageIcon background = new ImageIcon(getClass().getResource("userbg.jpg"));bt1 = new JButton(img1);bt2 = new JButton(img2);bt3 = new JButton(img3);bt4 = new JButton(img4);lb1= new JLabel(img5);ta = new JTextArea();home = new JButton(home1);bg = new JLabel(background);this.setLayout(null); // 绝对布局/*bt1.setBorderPainted(false); // 隐藏边框bt2.setBorderPainted(false);bt3.setBorderPainted(false);*/home.setBounds(1, 1, 64, 64);bt1.setBounds(320, 50, 30, 30);bt2.setBounds(360, 50, 30, 30);bt3.setBounds(400, 50, 30, 30);bt4.setBounds(440, 50, 30, 30);lb1.setBounds(150, 90, 500,300);ta.setBounds(200, 220, 400, 400);bg.setBounds(0, 0, 800, 600);//字体设置Font font = new Font("幼圆", Font.BOLD, 20); // 字体ta.setForeground(Color.black);ta.setFont(font);ta.setText(queryAll());//显示所有商品信息ta.setBackground(null);//隐藏边框this.add(bt1);this.add(bt2);this.add(bt3);this.add(bt4);this.add(lb1);this.add(ta);this.add(home);this.add(bg);home.setOpaque(false);//按钮透明home.setBorderPainted(false); // 按钮无边框//按钮监听bt1.addActionListener(new B1());bt2.addActionListener(new B2());bt3.addActionListener(new B3());bt4.addActionListener(new B4());}public String queryAll(){GoodsDaoImpl gdi = new GoodsDaoImpl();String s;s = gdi.query();return s;}//内部类class B1 implements ActionListener{public void actionPerformed(ActionEvent e){new goodsAdd();}}class B2 implements ActionListener{public void actionPerformed(ActionEvent e){new goodsUpdate();}}class B3 implements ActionListener{public void actionPerformed(ActionEvent e){new goodsDelete();}}class B4 implements ActionListener{public void actionPerformed(ActionEvent e){ta.setText(queryAll());}}
}
CircleProgressBar.java
圆形进度条
package JFrame;import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;import javax.swing.JPanel;/*** 圆形进度条。*/
public class CircleProgressBar extends JPanel {private static final long serialVersionUID = 1L;private int minimumProgress; //最小进度值。private int maximumProgress; //最大进度值。private int progress; //当前进度值。private Color backgroundColor; //背景颜色。private Color foregroundColor; //前景颜色。private Color digitalColor; //数字颜色。//构造函数△△ △public CircleProgressBar() {setMinimumProgress(0);setMaximumProgress(100);setProgress(0);setBackgroundColor(new Color(209, 206, 200));setForegroundColor(new Color(172, 168, 163));setDigitalColor(Color.BLACK);}/***△△ △ 绘制圆形进度条。*/@Overridepublic void paint(Graphics g) {super.paint(g);Graphics2D graphics2d = (Graphics2D) g;// 开启抗锯齿graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);int x = 0;int y = 0;int width = 0;int height = 0;int fontSize = 0;if (getWidth() >= getHeight()) {x = (getWidth() - getHeight()) / 2 + 25;y = 25;width = getHeight() - 50;height = getHeight() - 50;fontSize = getWidth() / 8;} else {x = 25;y = (getHeight() - getWidth()) / 2 + 25;width = getWidth() - 50;height = getWidth() - 50;fontSize = getHeight() / 8;}graphics2d.setStroke(new BasicStroke(20.0f));graphics2d.setColor(backgroundColor);graphics2d.drawArc(x, y, width, height, 0, 360);graphics2d.setColor(foregroundColor);graphics2d.drawArc(x, y, width, height, 90, -(int) (360 * ((progress * 1.0) / (getMaximumProgress() - getMinimumProgress()))));graphics2d.setFont(new Font("黑体", Font.BOLD, fontSize));FontMetrics fontMetrics = graphics2d.getFontMetrics();int digitalWidth = fontMetrics.stringWidth(progress + "%");int digitalAscent = fontMetrics.getAscent();graphics2d.setColor(digitalColor);graphics2d.drawString(progress + "%", getWidth() / 2 - digitalWidth / 2, getHeight() / 2 + digitalAscent / 2);}/*** 返回最小进度值。*/public int getMinimumProgress() {return minimumProgress;}/*** 设置最小进度值。*/public void setMinimumProgress(int minimumProgress) {if (minimumProgress <= getMaximumProgress()) {this.minimumProgress = minimumProgress;}}/*** 返回最大进度值。*/public int getMaximumProgress() {return maximumProgress;}/*** 设置最大进度值。*/public void setMaximumProgress(int maximumProgress) {if (maximumProgress >= getMinimumProgress()) {this.maximumProgress = maximumProgress;}}/*** 返回当前进度值。*/public int getProgress() {return progress;}/*** 设置当前进度值。*/public void setProgress(int progress) {if (progress >= getMinimumProgress() && progress <= getMaximumProgress()) {this.progress = progress;this.repaint();}}/*** 返回背景颜色。*/public Color getBackgroundColor() {return backgroundColor;}/*** 设置背景颜色。*/public void setBackgroundColor(Color backgroundColor) {this.backgroundColor = backgroundColor;this.repaint();}/*** 返回前景颜色。*/public Color getForegroundColor() {return foregroundColor;}/*** 设置前景颜色。*/public void setForegroundColor(Color foregroundColor) {this.foregroundColor = foregroundColor;this.repaint();}/*** 返回数字颜色。*/public Color getDigitalColor() {return digitalColor;}/*** 设置数字颜色。*/public void setDigitalColor(Color digitalColor) {this.digitalColor = digitalColor;this.repaint();}}
运行截图
登录界面
user登录或者manager登录
主界面
库存管理界面
进货单
销售单
用户管理