成都创新互联网站制作重庆分公司

java各种功能实现代码,java实用代码

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

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

创新互联公司致力于互联网品牌建设与网络营销,包括网站设计制作、成都网站设计、SEO优化、网络推广、整站优化营销策划推广、电子商务、移动互联网营销等。创新互联公司为不同类型的客户提供良好的互联网应用定制及解决方案,创新互联公司核心团队十载专注互联网开发,积累了丰富的网站经验,为广大企业客户提供一站式企业网站建设服务,在网站建设行业内树立了良好口碑。

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

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编写代码实现如下功能,需要全部代码

很简单的应用,为了节省字数,代码注释我就不加了

首先是显示层,LoinWindow:

import java.awt.FlowLayout;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.border.EmptyBorder;

public class LoinWindow extends JFrame implements ActionListener, FocusListener {

private JPanel mainPanel, namePanel, btnPanel;

private JTextField tfName, tfPsd;

private JButton btnLogin, btnCancel;

private static final int WIDTH = 300;

private static final int HEIGHT = 200;

private LoginService service = new LoginService();

public LoinWindow() {

super("登录窗体");

}

public void launch() {

setSize(WIDTH, HEIGHT);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

GridLayout mainLayout = new GridLayout(2, 1);

mainLayout.setVgap(10);

mainPanel = new JPanel(mainLayout);

GridBagLayout nameLayout = new GridBagLayout();

namePanel = new JPanel(nameLayout);

namePanel.setBorder(new EmptyBorder(10, 10, 10, 10));

JLabel nameLabel = new JLabel("姓名:");

tfName = new JTextField();

JLabel psdLabel = new JLabel("密码:");

tfPsd = new JTextField();

JLabel blank = new JLabel(" ");

namePanel.add(nameLabel);

namePanel.add(tfName);

namePanel.add(blank);

namePanel.add(psdLabel);

namePanel.add(tfPsd);

GridBagConstraints s = new GridBagConstraints();

s.fill = GridBagConstraints.BOTH;

s.gridwidth = 1;

s.weightx = 0;

s.weighty = 0;

nameLayout.setConstraints(nameLabel, s);

s.gridwidth = 0;

s.weightx = 1;

s.weighty = 0;

nameLayout.setConstraints(tfName, s);

s.gridwidth = 0;

s.weightx = 4;

s.weighty = 0;

nameLayout.setConstraints(blank, s);

s.gridwidth = 1;

s.weightx = 0;

s.weighty = 0;

nameLayout.setConstraints(psdLabel, s);

s.gridwidth = 3;

s.weightx = 1;

s.weighty = 0;

nameLayout.setConstraints(tfPsd, s);

FlowLayout btnLayout = new FlowLayout();

btnLayout.setAlignment(FlowLayout.CENTER);

btnPanel = new JPanel(btnLayout);

btnLogin = new JButton("确定");

btnCancel = new JButton("取消");

btnPanel.add(btnLogin);

btnPanel.add(btnCancel);

btnCancel.addActionListener(this);

btnLogin.addActionListener(this);

mainPanel.add(namePanel);

mainPanel.add(btnPanel);

setContentPane(mainPanel);

tfName.addFocusListener(this);

tfPsd.addFocusListener(this);

pack();

setSize(WIDTH, HEIGHT);

setLocationRelativeTo(null);

}

@Override

public void actionPerformed(ActionEvent e) {

Object source = e.getSource();

if(source == btnCancel) {

System.exit(0);

} else if(source == btnLogin) {

String username = tfName.getText();

String password = tfPsd.getText();

boolean success = service.login(username, password);

if(success) {

warn("成功", "登录成功!");

} else {

warn("失败", "您输入的用户名或密码错误 !");

}

}

}

@Override

public void focusGained(FocusEvent arg0) {

}

@Override

public void focusLost(FocusEvent e) {

Object source = e.getSource();

if(source == tfName) {

String username = tfName.getText();

try {

service.matchUsername(username);

} catch (LoginException e1) {

warn("验证错误", e1.getMessage());

}

} else if(source == tfPsd) {

String password = tfPsd.getText();

try {

service.matchPassword(password);

} catch (LoginException e1) {

warn("验证错误", e1.getMessage());

}

}

}

private void warn(String title, String msg) {

JOptionPane.showMessageDialog(null, msg, title, JOptionPane.INFORMATION_MESSAGE);

}

public static void main(String[] args) {

new LoinWindow().launch();

}

}

然后是模型层:LoginDao

public class LoginDao {

public boolean login(String username, String password) {

if(username.equals("admin")  password.equals("12345")) {

return true;

}

return false;

}

}

LoginService

import java.util.regex.Pattern;

public class LoginService {

private static final Pattern LOGIN_PATTERN = Pattern.compile("[a-zA-Z]+");

private static final Pattern PASSWORD_PATTERN = Pattern.compile("[1-9]+");

private LoginDao dao = new LoginDao();

public boolean matchUsername(String username) throws LoginException {

if(null == username || username.isEmpty()) {

return false;

}

if(!LOGIN_PATTERN.matcher(username).matches()) {

throw new LoginException("您输入的用户名不合法,请输入英文!");

}

return true;

}

public boolean matchPassword(String password) throws LoginException {

if(null == password || password.isEmpty()) {

return false;

}

if(!PASSWORD_PATTERN.matcher(password).matches()) {

throw new LoginException("您输入的密码不合法,请输入数字!");

}

return true;

}

public boolean login(String username, String password) {

if(null == username || username.isEmpty()) {

return false;

}

if(null == password || password.isEmpty()) {

return false;

}

if(!dao.login(username, password)) {

return false;

}

return true;

}

}

LoginException

public class LoginException extends Exception {

public LoginException(String arg0) {

super(arg0);

}

}

不知道分层设计思想是不是我想的这样

java代码功能

Java 是一种编程语言,它本身的作用是通过编写应用程序,帮助人们解决日常工作、生活和学习遇到的问题。

一些常见的java功能代码。如复制文件夹及文件到指定目录,遍历指定盘符所有文件,检索字符串是否符合指定要求。

关于java中计算机的功能实现代码求大神指导

import java.util.Scanner;

import java.awt.*;

import java.awt.event.*;

public class Test extends WindowAdapter {

Panel p1 = new Panel();

Panel p2 = new Panel();

Panel p3 = new Panel();

TextField txt;

private Button[] b = new Button[17];

private String ss[] = { "7", "8", "9", "+", "4", "5", "6", "-", "1", "2",

"3", "*", "clear", "0", "=", "/", "close" };

static double a;

static String s, str;// 定义变量 创建对像

public static void main(String args[]) {

(new Test()).frame();

}

public void frame() {

Frame fm = new Frame("简单计算器");

for (int i = 0; i = 16; i++) {

b[i] = new Button(ss[i]);

}

for (int i = 0; i = 15; i++) {

p2.add(b[i]);

} // 创建按钮 并添加到P2

b[16].setBackground(Color.yellow);

txt = new TextField(15);

txt.setEditable(false);

for (int i = 0; i = 16; i++) {

b[i].addActionListener(new buttonlistener());// 添加监听器

}

b[16].addActionListener(new close());

fm.addWindowListener(this);

fm.setBackground(Color.red);

p1.setLayout(new BorderLayout());

p1.add(txt, "North");

p2.setLayout(new GridLayout(4, 4));

p3.setLayout(new BorderLayout());

p3.add(b[16]);

fm.add(p1, "North");

fm.add(p2, "Center");

fm.add(p3, "South");

fm.pack();

fm.setVisible(true);// 都是些窗中设置 添加相关组件和监听器

}

public void windowClosing(WindowEvent e) {

System.exit(0);// 退出系统

}

class buttonlistener implements ActionListener {// 编写监听器事件 通过按键得出给果

public void actionPerformed(ActionEvent e) {

Button btn = (Button) e.getSource();

if (btn.getLabel() == "=") {

jisuan();

str = String.valueOf(a);

txt.setText(str);

s = "";

} else if (btn.getLabel() == "+") {

jisuan();

txt.setText("");

s = "+";

} else if (btn.getLabel() == "-") {

jisuan();

txt.setText("");

s = "-";

} else if (btn.getLabel() == "/") {

jisuan();

txt.setText("");

s = "/";

} else if (btn.getLabel() == "*") {

jisuan();

txt.setText("");

s = "*";

} else {

txt.setText(txt.getText() + btn.getLabel());

if (btn.getLabel() == "clear")

txt.setText("");

}

}

public void jisuan() {// 编写具体计算方法

if (s == "+")

a += Double.parseDouble(txt.getText());

else if (s == "-")

a -= Double.parseDouble(txt.getText());

else if (s == "*")

a *= Double.parseDouble(txt.getText());

else if (s == "/")

a /= Double.parseDouble(txt.getText());

else

a = Double.parseDouble(txt.getText());

}

}

}

class close implements ActionListener {// 退出

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

}


文章题目:java各种功能实现代码,java实用代码
路径分享:http://cxhlcq.com/article/phjojp.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部