网站建设资讯

NEWS

网站建设资讯

java学友书店代码 网上书店java代码

求一个java图书管理系统代码,不需要图形化,命令行就可以,只要求实现导入图书,查询,删除

import java.io.BufferedReader;

专注于为中小企业提供成都网站建设、成都网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业绥宁免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

import java.io.File;

import java.io.FileReader;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class BookWork {

static ListBook data;

private static Scanner input;

public static void main(String[] args) {

if (!initBook("d:/book.txt")) {

System.out.println("初始图书列表失败 ..");

return;

}

input = new Scanner(System.in);

while (true) {

try {

System.out.println("请输入操作:");

System.out.println("1.找书  2.删除图书 3.退出");

int number = Integer.parseInt(input.next());

if (number == 1) {

findBook();

} else if (number == 2) {

delBook();

} else if (number == 3) {

System.out.println("退出");

break;

} else {

System.out.println("这个不是我要的...重来...");

System.out.println();

}

} catch (Exception e) {

e.printStackTrace();

System.out.println("这个不是我要的...重来...");

System.out.println();

}

}

}

private static void delBook() {

System.out.println("请输入要删除的书名或编号:");

String key = input.next();

if (key != null  !key.equals("")) {

for (Book book : data) {

if (book.number.equals(key) || book.name.contains(key)) {

data.remove(book);

System.out.println(" 图书 " + book.toString() + " 已删除");

return;

}

}

}

System.out.println("没有您要删除的");

}

private static void findBook() {

System.out.println("请输入要查找的书名或编号:");

String key = input.next();

if (key != null  !key.equals("")) {

for (Book book : data) {

if (book.number.equals(key) || book.name.contains(key)) {

System.out.println("找到了 图书 " + book.toString());

return;

}

}

}

System.out.println("没有您要找的");

}

private static boolean initBook(String string) {

try {

System.out.println("图书导入中...");

System.out.println("列表文件 -- " + string);

File file = new File(string);

if (!file.exists()) {

return false;

}

data = new ArrayListBook();

BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

String line = "";

while ((line = bufferedReader.readLine()) != null) {

String[] strings = line.split(",");

Book b = new Book(strings[0], strings[1]);

data.add(b);

System.out.println("导入" + b.toString());

}

} catch (Exception e) {

e.printStackTrace();

return false;

}

return true;

}

public static class Book {

String number;

String name;

public Book(String number, String name) {

super();

this.number = number;

this.name = name;

}

@Override

public String toString() {

return "Book [编码:" + number + ", 名称:" + name + "]";

}

}

}

001,金瓶梅

002,杂事秘辛

003,飞燕外传

004,控鹤监秘记

005,汉宫春色

用java定义一个图书类,要求包含作者,书名,书号,价格等信息并要求从主函数输出一本书的信息。

package cn.book;

public class Book {

private String auther="吴承恩";

private String name="西游记";

private String number="1";

private double price=100;

public String getAuther() {

return auther;

}

public void setAuther(String auther) {

this.auther = auther;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getNumber() {

return number;

}

public void setNumber(String number) {

this.number = number;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

@Override

public String toString() {

return " 作者:" + auther + ", 书名:" + name + ", 书号:" + number + ", 价格:" + price ;

}

//可以从这调用get set 方法 设置属性

public static void main(String[] args) {

Book book = new Book();

System.out.println(book.toString());

}

}

求一个java图书管管理软件登陆界面系统代码

package pack_view;

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.GridLayout;

import java.awt.Image;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.FocusEvent;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.WindowEvent;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import javax.swing.plaf.multi.MultiLookAndFeel;

import pack_DB.DB;

public class Login extends JFrame{

/**

* 登陆界面

*/

private static final long serialVersionUID = 1L;

JFrame jf = new JFrame();

private JPanel panel_all ;

private JPanel panel1 = new JPanel();

private JPanel panel2= new JPanel();

private JPanel panel3 = new JPanel();

private JPanel panel4 = new JPanel();

private JLabel jLabel_title;

private JLabel jLabel_name = new JLabel();

private JLabel jLabel_password = new JLabel();

private JTextField jTextField_name = new JTextField(15);

private JPasswordField jPasswordField = new JPasswordField(15);

private JButton jb1 = new JButton();

private JButton jb2 = new JButton();

private Font font;

String cid="";

String passwd ="";

//加载背景图片

// private ImageIcon imageicon;

// private Image image;

public Login() {

jf.setTitle("客户端登陆");

jf.setSize(350, 300);

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//把用户的显示器屏幕的尺寸(长和宽)赋值给变量screenSize

Dimension frameSize = jf.getSize();

if (frameSize.height screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width screenSize.width) {

frameSize.width = screenSize.width;

}

//把弹出的对话框窗口放置在屏幕中间

jf.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

// imageicon = new ImageIcon(ClassLoader

// .getSystemResource("res/backgound.jpg".toString()));

panel_all = new JPanel(){

public void paintComponent(Graphics g){

super.paintComponents(g);

// image = imageicon.getImage();

// if(image != null)

// g.drawImage(image,0,0,getWidth(),getHeight(),this);

}

};

font=new Font("宋体正文", 0,20);

jLabel_title = new JLabel(new ImageIcon(ClassLoader

.getSystemResource("res/Login.jpg".toString())));

jLabel_title.setFont(font);

jLabel_title.setText("用户登陆");

jLabel_name.setFont(new java.awt.Font("Dialog", 0, 14));

jLabel_name.setText("用户名:");

jLabel_password.setFont(new java.awt.Font("Dialog", 0, 14));

jLabel_password.setText("密 码:");

jb1.setFont(new java.awt.Font("Dialog", 0, 18));

jb1.setText("确 认");

jb2.setText("取 消");

jb2.setFont(new java.awt.Font("Dialog", 0, 18));

jTextField_name.addKeyListener(new KeyAdapter()

{

public void keyPressed(KeyEvent e)

{

if(e.getKeyCode()==KeyEvent.VK_ENTER)

{

jb1.doClick();

}

}});

jPasswordField.addKeyListener(new KeyAdapter()

{

public void keyPressed(KeyEvent e)

{

if(e.getKeyCode()==KeyEvent.VK_ENTER)

{

jb1.doClick();

}

}});

panel1.add(jLabel_name);

panel1.add(jTextField_name);

panel2.add(jLabel_password);

panel2.add(jPasswordField);

panel3.add(jb1);

panel3.add(jb2);

panel4.add(jLabel_title);

panel_all.setLayout(new GridLayout(4,1));

panel_all.add(panel4);

panel_all.add(panel1);

panel_all.add(panel2);

panel_all.add(panel3);

panel_all.setOpaque(false);

jf.setLayout(new BorderLayout());

jf.add(panel_all);

jb1.addMouseListener(new MouseAdapter(){

public void mouseClicked(MouseEvent me){

// if(lc.validate(jTextField_name.getText().trim(),new String(jPasswordField.getPassword()).trim())){

// doLogin();

// new MainFrame();

// }

// else

// JOptionPane.showMessageDialog(null, "Password doesn't match account,please try again!");

}

});

jb2.addMouseListener(new MouseAdapter(){

public void mouseClicked(MouseEvent me){

System.exit(0);

}

});

jf.setVisible(true);

jf.repaint();

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

/* public void doLogin(){

cid=jTextField_name.getText().trim();

passwd=jPasswordField.getText().trim();

String sql = "select *from customer where "+"cid='"+cid+"' and password='"+passwd+"'";

if (DB.connectDB()) {

if (DB.query(sql)){

System.out.print("登陆成功");

jf.dispose();

new MainFrame(cid);

return;

} else {

System.out.print("登陆失败");

return;

}

}

}

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

new Login();

}

}


网站名称:java学友书店代码 网上书店java代码
网页网址:http://njwzjz.com/article/hheogh.html