java买东西界面代码,java内部购物券代码
使用JAVA 编写一个程序,显示5中商品价格,用户可以选择多种商品并在其后的文本框输入购买的数量。
用java Swing做的?给你个代码,还有运行结果图
创新互联成立以来不断整合自身及行业资源、不断突破观念以使企业策略得到完善和成熟,建立了一套“以技术为基点,以客户需求中心、市场为导向”的快速反应体系。对公司的主营项目,如中高端企业网站企划 / 设计、行业 / 企业门户设计推广、行业门户平台运营、成都APP应用开发、手机网站制作、微信网站制作、软件开发、多线BGP机房等实行标准化操作,让客户可以直观的预知到从创新互联可以获得的服务效果。
package my.test.main;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Purchase extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JLabel label_9;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Purchase frame = new Purchase();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Purchase() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("\u5546\u54C11");
label.setBounds(56, 40, 54, 15);
contentPane.add(label);
JLabel label_1 = new JLabel("\u5546\u54C12");
label_1.setBounds(56, 70, 54, 15);
contentPane.add(label_1);
JLabel label_2 = new JLabel("\u5546\u54C13");
label_2.setBounds(56, 100, 54, 15);
contentPane.add(label_2);
JLabel label_3 = new JLabel("\u5546\u54C14");
label_3.setBounds(56, 130, 54, 15);
contentPane.add(label_3);
JLabel label_4 = new JLabel("\u5546\u54C15");
label_4.setBounds(56, 160, 54, 15);
contentPane.add(label_4);
JLabel label_5 = new JLabel("\u5546\u54C1\u540D\u79F0");
label_5.setBounds(56, 7, 54, 15);
contentPane.add(label_5);
JLabel label_6 = new JLabel("单价");
label_6.setBounds(179, 7, 54, 15);
contentPane.add(label_6);
JLabel label_7 = new JLabel("数量");
label_7.setBounds(307, 7, 54, 15);
contentPane.add(label_7);
JLabel label_8 = new JLabel("总价");
label_8.setBounds(145, 224, 54, 15);
contentPane.add(label_8);
label_9 = new JLabel("0");
label_9.setBounds(209, 224, 54, 15);
contentPane.add(label_9);
JLabel label_10 = new JLabel("10");
label_10.setBounds(185, 40, 54, 15);
contentPane.add(label_10);
JLabel label_11 = new JLabel("20");
label_11.setBounds(185, 70, 54, 15);
contentPane.add(label_11);
JLabel label_12 = new JLabel("30");
label_12.setBounds(185, 100, 54, 15);
contentPane.add(label_12);
JLabel label_13 = new JLabel("40");
label_13.setBounds(185, 130, 54, 15);
contentPane.add(label_13);
JLabel label_14 = new JLabel("50");
label_14.setBounds(185, 160, 54, 15);
contentPane.add(label_14);
textField = new JTextField();
textField.setBounds(295, 37, 66, 21);
contentPane.add(textField);
textField.setColumns(10);
textField.addKeyListener(new CalcTotle());
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(295, 67, 66, 21);
contentPane.add(textField_1);
textField_1.addKeyListener(new CalcTotle());
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(295, 97, 66, 21);
contentPane.add(textField_2);
textField_2.addKeyListener(new CalcTotle());
textField_3 = new JTextField();
textField_3.setColumns(10);
textField_3.setBounds(295, 127, 66, 21);
contentPane.add(textField_3);
textField_3.addKeyListener(new CalcTotle());
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(295, 157, 66, 21);
contentPane.add(textField_4);
textField_4.addKeyListener(new CalcTotle());
}
class CalcTotle extends KeyAdapter {
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
int count1, count2, count3, count4, count5;
if (!textField.getText().isEmpty()) {
count1 = Integer.parseInt(textField.getText()) * 10;
} else {
count1 = 0;
}
if (!textField_1.getText().isEmpty()) {
count2 = Integer.parseInt(textField_1.getText()) * 20;
} else {
count2 = 0;
}
if (!textField_2.getText().isEmpty()) {
count3 = Integer.parseInt(textField_2.getText()) * 30;
} else {
count3 = 0;
}
if (!textField_3.getText().isEmpty()) {
count4 = Integer.parseInt(textField_3.getText()) * 40;
} else {
count4 = 0;
}
if (!textField_4.getText().isEmpty()) {
count5 = Integer.parseInt(textField_4.getText()) * 50;
} else {
count5 = 0;
}
final int totle = count1 + count2 + count3 + count4 + count5;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
label_9.setText(totle + "");
}
});
}
}
}
java编写一个网上支付系统界面
html
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8"
title购物与结算/title
style type="text/css"
/style
link rel="stylesheet" href="
script src="
script src="
script src="
script src="
(beta4)/IE9.js"/script
script src="
script type="text/javascript"
function pay()
{
var link = document.getElementById("a1");
link.click();
var a = new Array();
a[0]="html教程";
a[1]=12;
a[2]=1;
a[3]=a[1]*a[2];
var a1 = new Array();
a1[0]="java详解";
a1[1]=25;
a1[2]=2;
a1[3]=a1[1]*a1[2];
var b = new Array();
b[0]=a;
b[1]=a1;
var amount =0;
for(var i=0;ib.length;i++)
{
var c = new Array();
c=b[i];
amount = amount+c[3];
var tr ="tr";
for(var j=0;jc.length;j++)
{
tr+="td"+c[j]+"/td";
}
tr+="/tr";
$("#list").append(tr);
$("#all").html("b总计:/bfont color=\"red\""+amount+"/font")
}
}
function goon()
{
var link = document.getElementById("a2");
link.click();
$("#news").html("支付成功!!");
}
/script
/head
body
input type="button" class="btn btn-danger" value="点击结算" onclick="pay()"
a href="#myModaltishi" role="button" class="btn" data-toggle="modal" id="a1" style="display: none"/a
div id="myModaltishi" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
div class="modal-header"
button type="button" class="close" data-dismiss="modal" aria-hidden="true"×/button
h3 id="myModalLabel"购物车/h3
/div
div class="modal-body"
div
table id="list" style="width: 95%;" class="table"
th商品名称/th
th单价/th
th数量/th
th金额/th
/table
/div
div align="right" id="all"/div
/div
div class="modal-footer"
button class="btn" data-dismiss="modal" aria-hidden="true"继续挑选/button
button class="btn btn-primary" data-dismiss="modal" onclick="goon()"支付/button
/div
/div
a href="#myModaltishi1" role="button" class="btn" data-toggle="modal" id="a2" style="display: none"/a
div id="myModaltishi1" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
div class="modal-header"
button type="button" class="close" data-dismiss="modal" aria-hidden="true"×/button
h3 id="myModalLabel"系统提示/h3
/div
div class="modal-body"
h3 id="news" align="center"/h3
/div
div class="modal-footer"
button class="btn btn-primary" data-dismiss="modal"知道了/button
/div
/div
/body
!-- 浏览器打开可查看效果,
另外由于页面使用了bootstrap框架建议使用渲染较高的浏览器,例如:火狐 --
/html
用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简单的购物车代码
package Test;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
init();//初始化
MapString,String map = new LinkedHashMap();
while(true){
Scanner in= new Scanner(System.in);
map = buy(in,map);//选择
System.out.println();
System.out.println("还要继续购物吗?(Y/N)");
String jx = in.nextLine();
if(jx.equals("N")){
break;
}
}
print(map);
}
public static void print(MapString, String m){
System.out.println("\n\n\n******************");
System.out.println(" 购物车清单");
Integer hj = 0;
for (EntryString, String entry : m.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if(key.equals("1")){
hj += Integer.parseInt(value)*3;
System.out.println("哇哈哈纯净水: "+value+"件,合计:¥"+Integer.parseInt(value)*3);
}else if(key.equals("2")){
hj += Integer.parseInt(value)*5;
System.out.println("康师傅方便面: "+value+"件,合计:¥"+Integer.parseInt(value)*5);
}else if(key.equals("3")){
hj += Integer.parseInt(value)*4;
System.out.println("可口可乐: "+value+"件,合计:¥"+Integer.parseInt(value)*4);
}
}
System.out.println("合计金额:¥"+hj);
}
public static void init(){
System.out.println("******************");
System.out.println("\t商品列表\n");
System.out.println(" 商品名称 价格");
System.out.println("1. 哇哈哈纯净水 ¥3");
System.out.println("2. 康师傅方便面 ¥5");
System.out.println("3. 可口可乐 ¥4");
System.out.println("******************");
}
public static MapString,String buy(Scanner scan,MapString,String m){
System.out.print("请输入编号:");
String bh = scan.nextLine();
System.out.print("请输入购买数量:");
String num = scan.nextLine();
if(m.size()0 m.keySet().contains(bh)){
m.put(bh,(Integer.parseInt(bh)+Integer.parseInt(num))+"");
}else{
m.put(bh, num);
}
return m;
}
}
分享题目:java买东西界面代码,java内部购物券代码
文章来源:http://azwzsj.com/article/hcojeo.html