基于Mysql+JavaSwing的超市商品管理系统设计与实现

吾爱主题 阅读:118 2024-04-02 08:06:12 评论:0

前言:

     随着小超市规模的发展不断扩大, 商品数量急剧增加, 有关商品的各种信息量也成倍增长。 超市时时刻刻都需要对商品各种信息进行统计分析。 而大型的超市管理系统功能过于强大而造成操作繁琐降低了小超市的工作效率。 超市管理系统是市场上最流行的超市上常用的系统之一, 由于刚学java知识、所有功能设计的比较简单、只有商品信息的增删改查。实现对商品信息全面、 动态、及时的管理。本文系统的分析了软件开发的背景以过程;首先介绍了软件的开发环境, 其次介绍了本软件的详细设计过程: 数据库的设计、各个模块的设计和实现,以及具体界面的设计和功能。超市库存管理系统是基于 java eclipse 作为开发工具 , mysql 作为后台数据库支持。超市库存管理系统开发主要是界面程序的开发、数据库的建立、数据库的维护。应用程序功能完善,界面人机交互要好,而且操作简单。同时 javaswing语言简单,在较短的时间内能够开发出使用性强、 功能完善, 易于操作的程序, 也能实现与数据库的连接。

主要模块:

商品列表数据展示、商品信息添加、商品信息修改、商品信息删除、按照商品名称查询商品信息

1、功能介绍

功能截图:

查询商品列表信息:

添加商品信息:

修改商品信息:

删除商品信息:

删除之后需要刷新一下列表数据

​编号查询商品信息:

2、关键代码

2.1 主页功能

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 public class goodsmanage extends jframe {   private jtextfield textfield;   select select = new select();   updata updata = new updata();   object[] header= { "商品编号" , "商品名称" , "数量" , "单价" };   string sql = "select goodsid,goodsname,num,price from goods" ;   object[][] data= select.getgoods(sql);   defaulttablemodel df = new defaulttablemodel(data, header);   int v=scrollpaneconstants.vertical_scrollbar_as_needed;   int h=scrollpaneconstants.horizontal_scrollbar_as_needed;     public goodsmanage() {    super ( "商品管理系统" );    this .setbounds( 0 , 0 , 700 , 450 );    this .setlocationrelativeto( null ); //让窗口在屏幕中间显示    this .setresizable( false ); //让窗口大小不可改变    getcontentpane().setlayout( null );       jtable jtable = new jtable(df);    jscrollpane jsp= new jscrollpane(jtable,v,h);    jsp.setbounds( 10 , 10 , 515 , 320 );    getcontentpane().add(jsp);       jbutton button_1 = new jbutton( "显示所有商品" );    button_1.addactionlistener( new actionlistener() {     @override     public void actionperformed(actionevent e) {      string sql = "select goodsid,goodsname,num,price from goods" ;      object[][] data = select.getgoods(sql);      df.setdatavector(data, header);     }    });      button_1.setbounds( 535 , 80 , 127 , 30 );    getcontentpane().add(button_1);       jbutton button_2 = new jbutton( "修改商品" );    button_2.setbounds( 535 , 140 , 127 , 30 );    getcontentpane().add(button_2);    button_2.addactionlistener( new actionlistener() {     @override     public void actionperformed(actionevent e) {      if (jtable.getselectedcolumn()< 0 ) {       joptionpane.showmessagedialog( null , "请选择要修改的数据!" );      } else {       int goodsid = integer.parseint(jtable.getvalueat(jtable.getselectedrow(), 0 ).tostring());       string name = jtable.getvalueat(jtable.getselectedrow(), 1 ).tostring();       int num = integer.parseint(jtable.getvalueat(jtable.getselectedrow(), 2 ).tostring());       string price = jtable.getvalueat(jtable.getselectedrow(), 3 ).tostring();       goods goods = new goods(goodsid,name,num,price);       goodsxg goodsxg = new goodsxg(goods);       goodsxg.setvisible( true );      }          }    });       jbutton button_3 = new jbutton( "删除商品" );    button_3.setbounds( 535 , 200 , 127 , 30 );    getcontentpane().add(button_3);    button_3.addactionlistener( new actionlistener() {     @override     public void actionperformed(actionevent e) {      if (jtable.getselectedcolumn()< 0 ) {       joptionpane.showmessagedialog( null , "请选中要删除的数据!" );      } else {       int goodsid = integer.parseint(jtable.getvalueat(jtable.getselectedrow(), 0 ).tostring());       string sql= "delete from goods where goodsid=" +goodsid;       int result = updata.adddata(sql);       if (result> 0 ) {        joptionpane.showmessagedialog( null , "删除成功!" );        joptionpane.showmessagedialog( null , "记得刷新一下哦!" );       } else {        joptionpane.showmessagedialog( null , "删除失败!" );       }      }     }    });       jbutton button_4 = new jbutton( "添加商品" );    button_4.setbounds( 535 , 258 , 127 , 30 );    getcontentpane().add(button_4);    button_4.addactionlistener( new actionlistener() {     public void actionperformed(actionevent arg0) {      goodsadd goodsadd = new goodsadd();      goodsadd.setvisible( true );     }    });       jlabel label = new jlabel( "商品编号:" );    label.setbounds( 40 , 354 , 112 , 32 );    getcontentpane().add(label);       textfield = new jtextfield();    textfield.setbounds( 154 , 358 , 127 , 26 );    getcontentpane().add(textfield);    textfield.setcolumns( 10 );       jbutton button = new jbutton( "按编号查询" );    button.addactionlistener( new actionlistener() {     public void actionperformed(actionevent arg0) {      string sql = "select goodsid,goodsname,num,price from goods where goodsid like '%" +textfield.gettext()+ "%'" ;      object[][] data = select.getgoods(sql);      df.setdatavector(data, header);     }    });    button.setbounds( 305 , 355 , 112 , 30 );    getcontentpane().add(button);       this .addwindowlistener( new windowadapter() {          public void windowclosing(windowevent e) {      super .windowclosing(e);      //加入动作      goodsmanagement m = new goodsmanagement();      m.setvisible( true );      }    });   }     public static void main(string[] args) {    goodsmanage t = new goodsmanage();    t.setvisible( true );   } }

2.2 添加商品信息

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 public class goodsadd extends jframe {   private jtextfield id,name,num,price;   private jbutton button;   private jbutton button_1;     public goodsadd() {    super ( "商品管理系统" );    this .setbounds( 0 , 0 , 400 , 450 );    this .setlocationrelativeto( null ); //让窗口在屏幕中间显示    this .setresizable( false ); //让窗口大小不可改变    getcontentpane().setlayout( null );       jlabel label = new jlabel( "商品编号:" );    label.setbounds( 85 , 89 , 87 , 22 );    getcontentpane().add(label);       id = new jtextfield();    id.setbounds( 147 , 90 , 142 , 21 );    getcontentpane().add(id);    id.setcolumns( 10 );       jlabel label_1 = new jlabel( "商品名称" );    label_1.setbounds( 85 , 139 , 87 , 22 );    getcontentpane().add(label_1);       name = new jtextfield();    name.setcolumns( 10 );    name.setbounds( 147 , 140 , 142 , 21 );    getcontentpane().add(name);       jlabel label_2 = new jlabel( "数量:" );    label_2.setbounds( 85 , 193 , 87 , 22 );    getcontentpane().add(label_2);       num = new jtextfield();    num.setcolumns( 10 );    num.setbounds( 147 , 194 , 142 , 21 );    getcontentpane().add(num);       jlabel label_3 = new jlabel( "单价:" );    label_3.setbounds( 85 , 241 , 87 , 22 );    getcontentpane().add(label_3);       price = new jtextfield();    price.setcolumns( 10 );    price.setbounds( 147 , 242 , 142 , 21 );    getcontentpane().add(price);       button = new jbutton( "确定" );    button.setbounds( 78 , 317 , 93 , 23 );    getcontentpane().add(button);    button.addactionlistener( new actionlistener() {     public void actionperformed(actionevent arg0) {      string addid = id.gettext();      string addname = name.gettext();      string addnum = num.gettext();      string addprice = num.gettext();      if (addname.equals( "" )||addname.equals( "" )||addnum.equals( "" )||addprice.equals( "" )) {       joptionpane.showmessagedialog( null , "请完整输入要添加的数据" );      } else {       string sql= "insert into goods values(" +addid+ ",'" +addname+ "','" +addnum+ "','" +addprice+ "')" ;       int result = updata.adddata(sql);       if (result> 0 ) {        joptionpane.showmessagedialog( null , "添加成功!" );                    joptionpane.showmessagedialog( null , "记得刷新一下哦!" );        dispose(); //      goodsmanage i = new goodsmanage(); //      i.setvisible(true);       } else {        joptionpane.showmessagedialog( null , "添加失败!" );       }      }       }    });       button_1 = new jbutton( "取消" );    button_1.setbounds( 208 , 317 , 93 , 23 );    getcontentpane().add(button_1);    button_1.addactionlistener( new actionlistener() {     public void actionperformed(actionevent arg0) {      dispose();     }    });      } }

2.3 数据库设计

商品表

?
1 2 3 4 5 6 7 8 9 10 11 create table `newtable` ( `goodsid`  int ( 11 ) not null , `goodsname`  varchar( 10 ) character set utf8 collate utf8_general_ci not null , `num`  int ( 11 ) not null , `price`  decimal( 10 , 4 ) not null , primary key (`goodsid`) ) engine=innodb default character set=utf8 collate=utf8_general_ci row_format=compact ;

到此这篇关于基于mysql+javaswing的超市商品管理系统设计与实现的文章就介绍到这了,更多相关mysql+javaswing的超市商品管理系统设计与实现内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://juejin.cn/post/7012021268597702664

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容