重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java商城项目示例代码 java商城开发

求JAVA小项目的完整代码

给你个做好了的Java的源程序的记事本,自己看看就行了的,不怎么难的···

成都创新互联秉承实现全网价值营销的理念,以专业定制企业官网,成都做网站、网站设计、外贸营销网站建设成都微信小程序,网页设计制作,移动网站建设营销型网站建设帮助传统企业实现“互联网+”转型升级专业定制企业官网,公司注重人才、技术和管理,汇聚了一批优秀的互联网技术人才,对客户都以感恩的心态奉献自己的专业和所长。

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

public class MyNotepad implements ActionListener{

private JFrame frame=new JFrame("新记事本");

private JTextArea jta=new JTextArea();

private String result="";

private boolean flag=true;

private File f;

private JButton jb=new JButton("开始");

private JTextField jtf=new JTextField(15);

private JTextField jt=new JTextField(15);

private JButton jbt=new JButton("替换为");

private JButton jba=new JButton("全部替换");

private Icon ic=new ImageIcon("D:\\java课堂笔记\\GUI\\11.gif");

private String value;

private int start=0;

private JFrame jf=new JFrame("查找");

private JFrame jfc=new JFrame("替换");

@Override

public void actionPerformed(ActionEvent e) {

String comm=e.getActionCommand();

if("新建".equals(comm)){

if(!(frame.getTitle().equals("新记事本"))){

if(!flag){

write();

newNew();

}else{

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

int returnVal = jfc.showDialog(null,"保存为");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

flag=false;

write();

}

}

}else if(!(jta.getText().isEmpty())){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

int returnVal = jfc.showDialog(null,"保存为");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

flag=false;

write();

newNew();

}

}else{

newNew();

}

}else if("打开".equals(comm)){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

jfc.setDialogType(JFileChooser.OPEN_DIALOG);

int returnVal = jfc.showOpenDialog(null);

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

frame.setTitle(f.getName());

result=read();

flag=false;

value=result;

jta.setText(result);

}

}else if("保存".equals(comm)){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

if(flag){

int returnVal = jfc.showDialog(null,"保存为");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

flag=false;

write();

}

}else{

write();

}

}else if("另存".equals(comm)){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

int returnVal = jfc.showDialog(null,"另存");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

write();

}

}else if("退出".equals(comm)){

System.exit(0);

}else if("撤销".equals(comm)){

jta.setText(value);

}else if("剪切".equals(comm)){

value=jta.getText();

jta.cut();

}else if("复制".equals(comm)){

jta.copy();

}else if("粘贴".equals(comm)){

value=jta.getText();

jta.paste();

}else if("删除".equals(comm)){

value=jta.getText();

jta.replaceSelection(null);

}else if("全选".equals(comm)){

jta.selectAll();

}else if("查找".equals(comm)){

value=jta.getText();

jf.add(jtf,BorderLayout.CENTER);

jf.add(jb,BorderLayout.SOUTH);

jf.setLocation(300,300);

jf.pack();

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}else if("替换".equals(comm)){

value=jta.getText();

GridLayout gl=new GridLayout(3,3);

JLabel jl1=new JLabel("查找内容:");

JLabel jl2=new JLabel("替换为:");

jfc.setLayout(gl);

jfc.add(jl1);

jfc.add(jtf);

jfc.add(jb);

jfc.add(jl2);

jfc.add(jt);

jfc.add(jbt);

JLabel jl3=new JLabel();

JLabel jl4=new JLabel();

jfc.add(jl3);

jfc.add(jl4);

jfc.add(jba);

jfc.setLocation(300,300);

jfc.pack();

jfc.setVisible(true);

jfc.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}else if("版本".equals(comm)){

JDialog jd=new JDialog(frame,"关于对话框");

jd.setSize(200,200);

JLabel l=new JLabel("哈哈哈哈哈哈哈哈哈哈呵呵呵呵呵呵呵呵呵呵呵呵呵");

jd.add(l,BorderLayout.CENTER);

jd.setLocation(100,200);

jd.setSize(300,300);

jd.setVisible(true);

// jd.pack();

jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

}else if("开始".equals(comm)||"下一个".equals(comm)){

String temp=jtf.getText();

int s=value.indexOf(temp,start);

if(value.indexOf(temp,start)!=-1){

jta.setSelectionStart(s);

jta.setSelectionEnd(s+temp.length());

jta.setSelectedTextColor(Color.GREEN);

start=s+1;

jb.setText("下一个");

// value=value.substring(s+temp.length());//不能截取字串

}else {

JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);

jf.dispose();

}

}else if("替换为".equals(comm)){

String temp=jtf.getText();

int s=value.indexOf(temp,start);

if(value.indexOf(temp,start)!=-1){

jta.setSelectionStart(s);

jta.setSelectionEnd(s+temp.length());

jta.setSelectedTextColor(Color.GREEN);

start=s+1;

jta.replaceSelection(jt.getText());

}else {

JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);

jf.dispose();

}

}else if("全部替换".equals(comm)){

String temp=jta.getText();

temp=temp.replaceAll(jtf.getText(), jt.getText());

jta.setText(temp);

}

}

public String read(){

String temp="";

try {

FileInputStream fis = new FileInputStream(f.getAbsolutePath());

byte[] b=new byte[1024];

while(true){

int num=fis.read(b);

if(num==-1)break;

temp=temp+new String(b,0,num);

}

fis.close();

} catch (Exception e1) {

e1.printStackTrace();

}

return temp;

}

public void write(){

try {

FileOutputStream fos=new FileOutputStream(f);

fos.write(jta.getText().getBytes());

fos.close();

} catch (Exception e) {

e.printStackTrace();

}

}

public void newNew(){

frame.dispose();

new MyNotepad();

flag=true;

}

public MyNotepad(){

JMenuBar jmb=new JMenuBar();

String[] menuLab={"文件","编辑","帮助"};

String[][] menuItemLab={{"新建","打开","保存","另存","退出"},

{"撤销","剪切","复制","粘贴","删除","全选","查找","替换"},

{"版本"}};

for(int i=0;imenuLab.length;i++){

JMenu menu=new JMenu(menuLab[i]);

jmb.add(menu);

for(int j=0;jmenuItemLab[i].length;j++){

JMenuItem jmi=new JMenuItem(menuItemLab[i][j]);

menu.add(jmi);

jmi.addActionListener(this);

}

}

frame.setJMenuBar(jmb);

jta.setLineWrap(true);//自动换行

JScrollPane jsp=new JScrollPane(jta);//滚动窗口面板

frame.add(jsp);

jb.addActionListener(this);

jbt.addActionListener(this);

jba.addActionListener(this);

frame.setLocation(200,50);

frame.setSize(620,660);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new MyNotepad();

}

}

JAVA 购物车示例代码

import java.awt.*;

import java.awt.event.*;

class ShopFrame extends Frame implements ActionListener

{ Label label1,label2,label3,label4;

Button button1,button2,button3,button4,button5;

TextArea text;

Panel panel1,panel2;

static float sum=0.0f;

ShopFrame(String s)

{ super(s);

setLayout(new BorderLayout());

label1=new Label("面纸:3元",Label.LEFT);

label2=new Label("钢笔:5元",Label.LEFT);

label3=new Label("书:10元",Label.LEFT);

label4=new Label("袜子:8元",Label.LEFT);

button1=new Button("加入购物车");

button2=new Button("加入购物车");

button3=new Button("加入购物车");

button4=new Button("加入购物车");

button5=new Button("查看购物车");

text=new TextArea("商品有:"+"\n",5,10);

text.setEditable(false);

addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{ System.exit(0);

}

}

);

button1.addActionListener(this);

button2.addActionListener(this);

button3.addActionListener(this);

button4.addActionListener(this);

button5.addActionListener(this);

panel1=new Panel();

panel2=new Panel();

panel1.add(label1);

panel1.add(button1);

panel1.add(label2);

panel1.add(button2);

panel1.add(label3);

panel1.add(button3);

panel1.add(label4);

panel1.add(button4);

panel2.setLayout(new BorderLayout());

panel2.add(button5,BorderLayout.NORTH);

panel2.add(text,BorderLayout.SOUTH);

this.add(panel1,BorderLayout.CENTER);

this.add(panel2,BorderLayout.SOUTH);

setBounds(100,100,350,250);

setVisible(true);

validate();

}

public void actionPerformed(ActionEvent e)

{ if(e.getSource()==button1)

{ text.append("一个面纸、");

sum=sum+3;

}

else if(e.getSource()==button2)

{ text.append("一只钢笔、");

sum=sum+5;

}

else if(e.getSource()==button3)

{ text.append("一本书、");

sum=sum+10;

}

else if(e.getSource()==button4)

{ text.append("一双袜子、");

sum=sum+8;

}

else if(e.getSource()==button5)

{

text.append("\n"+"总价为:"+"\n"+sum);

}

}

}

public class Shopping {

public static void main(String[] args) {

new ShopFrame("购物车");

}

}

我没用Swing可能显示不出来你的效果。不满意得话我在给你编一个。

求简单实现网上商城功能的java代码

平时在线10k人大概是让你创建一个数据库连接池,大小设置10k。

下面是一个图书商城的数据库表部分,供你参考

set utf8

DROP TABLE IF EXISTS d_product;

CREATE TABLE d_product (//用来存放总商品,入图书种类

id int(12) NOT NULL auto_increment,

product_name varchar(100) NOT NULL,

description varchar(100) default NULL,

add_time bigint(20) default NULL,

fixed_price double NOT NULL,

dang_price double NOT NULL,

keywords varchar(200) default NULL,

has_deleted int(1) NOT NULL default '0',

product_pic varchar(200) default NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO d_product VALUES (23,'上课睡觉的故事','上课睡觉的故事',1237873000234,200,180,'key',0,'15.jpg');

DROP TABLE IF EXISTS d_book;

CREATE TABLE d_book (//用来存放图书的具体内容

id int(12) NOT NULL,

author varchar(200) NOT NULL,

publishing varchar(200) NOT NULL,

publish_time bigint(20) NOT NULL,

word_number varchar(15) default NULL,

which_edtion varchar(15) default NULL,

total_page varchar(15) default NULL,

print_time int(20) default NULL,

print_number varchar(15) default NULL,

isbn varchar(25) default NULL,

author_summary text NOT NULL,

catalogue text NOT NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO d_book VALUES (24,'阿斗,'地球出版社',1237873000234,'1万','1','100',1,NULL,'12345678','无描述,'好书!');

DROP TABLE IF EXISTS d_category;

CREATE TABLE d_category (//商城图书目录

id int(12) NOT NULL auto_increment,

turn int(10) NOT NULL,

en_name varchar(200) NOT NULL,

name varchar(200) NOT NULL,

description varchar(200),

parent_id int(10),

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO d_category VALUES (1,1,'Book','图书',NULL,0);

DROP TABLE IF EXISTS d_category_product;

CREATE TABLE d_category_product (//这个是连接目录和书籍具体信息的表

id int(12) NOT NULL auto_increment,

product_id int(10) NOT NULL,

cat_id int(10) NOT NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO d_category_product VALUES (72,24,1);

DROP TABLE IF EXISTS d_item;

CREATE TABLE d_item (//这个订单条目表

id int(12) NOT NULL auto_increment,

order_id int(10) NOT NULL,

product_id int(10) NOT NULL,

product_name varchar(100) NOT NULL,

dang_price double NOT NULL,

product_num int(10) NOT NULL,

amount double NOT NULL,

PRIMARY KEY (id)

)

DROP TABLE IF EXISTS d_order;

CREATE TABLE d_order (//订单表

id int(10) NOT NULL auto_increment,

user_id int(10) NOT NULL,

status int(10) NOT NULL,

order_time bigint(20) NOT NULL,

order_desc varchar(100) default NULL,

total_price double NOT NULL,

receive_name varchar(100) default NULL,

full_address varchar(200) default NULL,

postal_code varchar(8) default NULL,

mobile varchar(20) default NULL,

phone varchar(20) default NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB;

DROP TABLE IF EXISTS d_receive_address;

CREATE TABLE d_receive_address (//收件人信息表

id int(12) NOT NULL auto_increment,

user_id int(11) NOT NULL,

receive_name varchar(20) NOT NULL,

full_address varchar(200) NOT NULL,

postal_code varchar(8) NOT NULL,

mobile varchar(15) default NULL,

phone varchar(20) default NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB;

insert into d_receive_address values(1, 6,'Java','sun.cn','10000800','12345','67890');

insert into d_receive_address values(2, 6,'JavaJavaJava','ibm.cn','10000600','12345','67890');

DROP TABLE IF EXISTS d_user;

CREATE TABLE d_user (//用户表,用户信息

id int(12) NOT NULL auto_increment,

email varchar(50) NOT NULL,

nickname varchar(50) default NULL,

password varchar(50) NOT NULL,

user_integral int(12) NOT NULL default '0',

is_email_verify char(3),

email_verify_code varchar(50) default NULL,

last_login_time bigint default NULL,

last_login_ip varchar(15) default NULL,

PRIMARY KEY (id),

UNIQUE KEY email (email)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

用java写一个手机商城注册界面代码

这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。

在java的JFrame内通过创建匿名对象的方式做登录界面

package com.sxt;

import java.awt.Container;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class LoginFrame extends JFrame{

JTextField txtname=new JTextField();

JPasswordField txtpass=new JPasswordField();

JButton bl=new JButton("登录");

JButton bg=new JButton("关闭");

//构造无参构造器把主要的方法放在构造器里,然后在main方法里面调

public LoginFrame(){

setBounds(25,25,250,250);

Container c = getContentPane();

c.setLayout(new GridLayout(4,2,10,10));

c.add(new JLabel("用户名"));

c.add(txtname);

c.add(new JLabel("密码"));

c.add(txtpass);

c.add(bl);

c.add(bg);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

//注意:此处是匿名内部类

bg.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

System.exit(0);

}

}

);

//注意:此处是匿名内部类

bl.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {


当前标题:java商城项目示例代码 java商城开发
网址分享:http://cqcxhl.com/article/hgdcsj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP