只寫個(gè)demo級(jí)的例程做襪很好寫,但用到州仿生產(chǎn)環(huán)境中還得具體分析設(shè)計(jì)再編碼。這種代碼網(wǎng)上太多了冊胡纖內(nèi),你隨便搜下就有了。
囊謙網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),囊謙網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為囊謙上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個(gè)售后服務(wù)好的囊謙做網(wǎng)站的公司定做!
package?entity;
public?class?Market?{
private?int?id;//id
private?int?num;//數(shù)量
private?String?goods;//商品
private?double?price;//價(jià)格
public?Market(int?id,?int?搭好num,?String?goods,?double?price)?{
super();
this.id?=?id;
this.num?=?num;
this.goods?=?goods;
this.price?=?price;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?int?getNum()?{
return?num;
}
public?void?setNum(int?num)?{
this.num?=?num;
}
public?String?getGoods()?{
return?goods;
}
public?void?setGoods(String?goods)?{
this.goods?=?goods;
}
public?double?getPrice()?{
return?price;
}
public?void?setPrice(double?price)?{
this.price?=?price;
}
public?double?calc(?){
double?sum=price*num;
System.out.println("您消費(fèi)共計(jì):"+sum+"¥");
return?sum;
}
}
package?test;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.Scanner;
import?entity.Market;
public?class?Test?{
private?static?MapInteger,Market知嘩鉛?goods=new?HashMapInteger,?Market();
public?static?void?main(String[]?args)?{
System.out.println("-------超市計(jì)價(jià)系統(tǒng)-------");
String?goods1="可口可樂";
String?goods2="爆米花";
String?goods3="益達(dá)";
printTable("編號(hào)","商品","價(jià)格");
printTable("1",goods1,"3.0¥");
printTable("2",goods2,"5.0¥");
printTable("3",goods3,"10.0¥");
goods.put(1,?new?Market(1,?1,?goods1,?3.0));
goods.put(2,?new?Market(2,?1,??goods2,?5.0));
goods.put(3,?new?Market(3,?1,?goods3,?10.0));
Scanner?input?=?new?Scanner(System.in);
System.out.println("請輸入商品的編號(hào):");
int?num?=?input.nextInt();
System.out.println("請輸入商品的數(shù)量");
int?amount?=?input.nextInt();
Market?market?=?goods.get(num);
market.setNum(amount);
market.calc();
}
private?static?void?printTable(String?row1,String?row2,String?row3?)?{
System.out.print(row1);
int?times=12;
if?(row2!="商蘆尺品")?{
times=5;
}
for?(int?i?=?0;?i??times;?i++)?{
System.out.print("?");
}
System.out.print(row2);
for?(int?i?=?0;?i??10;?i++)?{
System.out.print("?");
}
System.out.print(row3);
System.out.println("\n");
}
}
//測試結(jié)果:
-------超市計(jì)價(jià)系統(tǒng)-------
編號(hào)????????????商品??????????價(jià)格
1?????可口可樂??????????3.0¥
2?????爆米花??????????5.0¥
3?????益達(dá)??????????10.0¥
請輸入商品的編號(hào):
3
請輸入商品的數(shù)量
5
您消費(fèi)共計(jì):50.0¥
package untitled5;
import java.io.*;
import java點(diǎn)虐 .*;
import java.sql.*;
import java.lang.*;
import javax.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class delbook extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField jTextField3 = new JTextField();
JLabel jLabel6 = new JLabel();
JTextField jTextField4 = new JTextField();
JButton jButton1 = new JButton();
//Construct the frame
public delbook() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel1.setForeground(Color.red);
jLabel1.setText("超市管理系統(tǒng)");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(500,400));
this.setTitle("超搜枯源市管理系統(tǒng)");
jLabel2.setFont(new java.awt.Font("SansSerif", 0, 30));
jLabel2.setText("業(yè)務(wù)單位信息");
jLabel3.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel3.setText("產(chǎn)品編世態(tài)號(hào)");
jTextField1.setText("敗叢");
jLabel4.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel4.setText("公司名稱");
jTextField2.setText("");
jLabel5.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel5.setText("訂單號(hào)碼");
jTextField3.setText("");
jLabel6.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel6.setText("電 話");
jTextField4.setText("");
jButton1.setFont(new java.awt.Font("SansSerif", 0, 25));
jButton1.setText("提交");
jButton1.addActionListener(new delbook_jButton1_actionAdapter(this));
contentPane.add(jLabel1, new XYConstraints(179, 1, 153, 32));
contentPane.add(jLabel2, new XYConstraints(162, 33, -1, -1));
contentPane.add(jLabel3, new XYConstraints(83, 89, -1, -1));
contentPane.add(jTextField1, new XYConstraints(189, 88, 141, 36));
contentPane.add(jTextField2, new XYConstraints(189, 149, 142, 36));
contentPane.add(jLabel4, new XYConstraints(84, 148, -1, -1));
contentPane.add(jTextField3, new XYConstraints(188, 206, 143, 33));
contentPane.add(jLabel5, new XYConstraints(84, 204, -1, -1));
contentPane.add(jLabel6, new XYConstraints(84, 253, -1, -1));
contentPane.add(jTextField4, new XYConstraints(189, 260, 143, 36));
contentPane.add(jButton1, new XYConstraints(197, 318, -1, -1));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void update() {
try {
//定義顯示的字符串
String str1;
String str2;
String str3;
String str4;
str1 = jTextField1.getText();
str2 = jTextField2.getText();
str3 = jTextField3.getText();
str4 = jTextField4.getText();
//裝載jdbc驅(qū)動(dòng)程序
String driverName = "oracle.jdbc.OracleDriver";
Driver driver = (Driver) Class.forName(driverName).newInstance();
//連接數(shù)據(jù)庫
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@thsspc0791:1521:liuyong", "hr", "tongfang");
PreparedStatement pstmt = con.prepareStatement(
" insert Customer1('goodID','Name','PID','tel')values(?,?,?,?)");
pstmt.setString(1, str1);
pstmt.setString(2, str2);
pstmt.setString(1, str3);
pstmt.setString(4, str4);
ResultSet res = pstmt.executeQuery();
pstmt.close();
con.close();
}catch (InstantiationException e) {
System.out.println(e.getMessage());
}catch (IllegalAccessException e) {
System.out.println(e.getMessage());
}catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}catch (SQLException edd) {
edd.printStackTrace() ;
System.out.println(edd.getMessage());
}
}
void jButton1_actionPerformed(ActionEvent e) {
update();
}
}
class delbook_jButton1_actionAdapter implements java.awt.event.ActionListener {
delbook adaptee;
delbook_jButton1_actionAdapter(delbook adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
package untitled5;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
/**
* pTitle: /p
* pDescription: /p
* pCopyright: Copyright ? 2003/p
* pCompany: /p
* @author not attributable
* @version 1.0
*/
public class retur extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
//Construct the frame
public retur() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel1.setForeground(Color.red);
jLabel1.setText("超市管理系統(tǒng)");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("超市管理系統(tǒng)");
contentPane.add(jLabel1, new XYConstraints(139, 1, 126, 33));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
package untitled5;
import java.io.*;
import java點(diǎn)虐 .*;
import java.sql.*;
import java.lang.*;
import javax.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import com.borland.dbswing.*;
//貨品信息登記
public class Frame2 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout2 = new XYLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JLabel jLabel5 = new JLabel();
JTextField jTextField3 = new JTextField();
//Construct the frame
public Frame2() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(600, 500));
this.setTitle("超市管理系統(tǒng)");
this.addHierarchyBoundsListener(new Frame2_this_hierarchyBoundsAdapter(this));
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel1.setForeground(Color.red);
jLabel1.setText("超市管理系統(tǒng)");
contentPane.setForeground(Color.black);
jLabel2.setFont(new java.awt.Font("SansSerif", 0, 30));
jLabel2.setText("產(chǎn) 品 信 息 展 示");
// statusBar.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel3.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel3.setText("產(chǎn)品名稱");
jTextField1.setText("");
jLabel4.setEnabled(true);
jLabel4.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel4.setText("產(chǎn)品ID號(hào)");
jTextField2.setText("");
jTextField2.addActionListener(new Frame2_jTextField2_actionAdapter(this));
jPanel1.setLayout(xYLayout2);
jLabel5.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel5.setForeground(Color.red);
jLabel5.setText("該產(chǎn)品詳細(xì)信息");
jTextField3.setText("");
contentPane.add(jLabel1, new XYConstraints(237, 0, 153, 40));
contentPane.add(jLabel2, new XYConstraints(200, 47, 231, 58));
contentPane.add(jLabel3, new XYConstraints(47, 102, 101, 42));
contentPane.add(jTextField1, new XYConstraints(128, 108, 112, 34));
contentPane.add(jTextField2, new XYConstraints(361, 107, 109, 36));
contentPane.add(jPanel1, new XYConstraints(75, 166, 453, 277));
jPanel1.add(jScrollPane1, new XYConstraints(14, 8, 433, 221));
jScrollPane1.getViewport().add(jTextField3, null);
jPanel1.add(jLabel5, new XYConstraints(112, 240, -1, -1));
contentPane.add(jLabel4, new XYConstraints(278, 111, -1, -1));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void Select() {
try {
String str1, str2;
str1 = jTextField1.getText();
str2 = jTextField2.getText();
import java.util.Vector; class Supermarket{ Vector market = null; Supermarket(){ market = new Vector(); } public void append(Goods g){ market.addElement(g); } public void delete(Goods g){ market.removeElement(g); } public void query(Goods g){ for(int i = 0;imarket.size();i++){ if((market.elementAt(i)).equals(g) == true){ g.showMe(); } } } } class Goods{ private String name; private double price; private int num; public Goods(String name,double price,int num){ this.name=name; this.price = price; this.num = num; } public void sale(double buyprice){ if(num==0){ System.out.println("購買商品已售空"); return; } if(buypricethis.price){ System.out.println("余額不足"); }else{ num--; } } public void add(int quantity){ num+=quantity; } public void showMe(){ System.out.println("商品名稱:"+this.name+" 商品價(jià)格前掘:"+this.price+"$ "+"商品個(gè)數(shù):"+this.num); } } //很多地方給的不是很詳細(xì),只能這么慧基核憑理解寫,測試鋒顫main方法自己寫。