import java.awt.Container;

創(chuàng)新互聯公司主營石鼓網站建設的網絡公司,主營網站建設方案,重慶APP軟件開發(fā),石鼓h5重慶小程序開發(fā)搭建,石鼓網站營銷推廣歡迎石鼓等地區(qū)企業(yè)咨詢
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class CopyContentToAnother extends JFrame implements ActionListener{
JButton button;
JTextArea jtx,jtx2;
Container c;
JPanel p;
public CopyContentToAnother(){
c=this.getContentPane();
p= new JPanel();
jtx = new JTextArea(12,12);
jtx2 = new JTextArea(12,12);
button = new JButton("確定");
button.addActionListener(this);
p.add(jtx);
p.add(jtx2);
p.add(button);
this.add(p);
this.setSize(500, 400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button){
jtx2.setText(jtx.getText());
jtx.setText("");
}
}
public static void main(String args[]){
CopyContentToAnother m =new CopyContentToAnother();
}
}
上面已經回答了
編譯已經通過,運行正確,如果還有問題,請留言ITjob
/**
* 得到一個新的訂單代碼
* 說明,此函數還沒有進行過多線程測試,更新數據庫時未加鎖
* @return 新的訂單代碼
*/
public String getOrderCode(){
//getParameter這個方法就是從數據庫取2個參數的值 ORDER_CODE_DATE 和
//ORDER_CODE_NO是數據庫字段名
BasParameters orderCodeDate = getParameter(ORDER_CODE_DATE);
BasParameters orderCodeNo = getParameter(ORDER_CODE_NO);
//當前日期
String currDate=new SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()));
//每天的起始數
int orderNo = 100;
//表里存的日期和當前日期相同,順序號累加
if (currDate.equals(orderCodeDate.getValue())){
orderCodeNo.setValue(""+(Integer.parseInt(orderCodeNo.getValue())+1));
orderNo = (Integer.parseInt(orderCodeNo.getValue()));
//save 就是保存ORDER_CODE_DATE 和 ORDER_CODE_NO當前值到數據庫
save(orderCodeNo);
} else {
//表里存的日期和當前日期不同,順序號重新開始,更新參數表的日期
orderCodeDate.setValue(currDate);
save(orderCodeDate);
orderCodeNo.setValue(orderNo);
save(orderCodeNo);
}
return currDate + new DecimalFormat("000000").format(orderNo);
}
為了30分:
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static final String PREFIX = "DD";
private static long code;
public static void main(String[] args) {
System.out.println(Test.nextCode());
System.out.println(Test.nextCode());
System.out.println(Test.nextCode());
}
public static synchronized String nextCode() {
code++;
String str = new SimpleDateFormat("yyyyMM").format(new Date());
long m = Long.parseLong((str)) * 10000;
m += code;
return PREFIX + m;
}
}
JAVA類庫中可以使用UUID方法,來生成唯一的數字的一串數字編號,也就是訂單號。
UUID.randomUUID().toString().replaceAll("-", "");通過上述方法就可以返回一串數字字符串。
這個需要配合查數據庫才行,具體方案:
Date date=new Date();
DateFormat format=new SimpleDateFormat("yyyyMMdd");
String timeStr=format.format(date);
//使用以上代碼先獲取當天日期串
String ckbh = “”;
int count = 這個值你需要通過當天時間去查 庫存表中有多少條數據;
String strcount = count + ""; //這里是把查出來的int值轉成string用于判斷count的長度
//開始拼接
if(strcount.length == 1 ){
int aa = count +1; //這個是按順序遞增1
String straa = aa+"";//int轉string
strcount += "000"+straa ;
}
if(strcount.length == 2 ){
int bb= count +1; //這個是按順序遞增1
String strbb = bb+"";//int轉string
strcount += "00"+strbb ;
}
if(strcount.length == 3 ){
int cc= count +1; //這個是按順序遞增1
String strcc = cc+"";//int轉string
strcount += "0"+strcc;
}
if(strcount.length == 4 ){
int dd= count +1; //這個是按順序遞增1
String strdd = dd+"";//int轉string
strcount += strdd;
}
ckbh = “CK”+ timeStr+strcount ;
return ckbh;
差不多就是這樣,純手動,有點累,方法雖然麻煩,但是能解決你的問題。把上面的代碼寫成一個返回string的方法,返回這個ckbh就行
當前標題:java生成訂單號代碼,java訂單編號生成算法
分享地址:http://chinadenli.net/article0/dsgcoio.html
成都網站建設公司_創(chuàng)新互聯,為您提供網站營銷、標簽優(yōu)化、網站策劃、自適應網站、電子商務、營銷型網站建設
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯