用java Swing做的?給你個代碼,還有運行結果圖
創(chuàng)新互聯(lián)成立以來不斷整合自身及行業(yè)資源、不斷突破觀念以使企業(yè)策略得到完善和成熟,建立了一套“以技術為基點,以客戶需求中心、市場為導向”的快速反應體系。對公司的主營項目,如中高端企業(yè)網站企劃 / 設計、行業(yè) / 企業(yè)門戶設計推廣、行業(yè)門戶平臺運營、成都APP應用開發(fā)、手機網站制作、微信網站制作、軟件開發(fā)、多線BGP機房等實行標準化操作,讓客戶可以直觀的預知到從創(chuàng)新互聯(lián)可以獲得的服務效果。
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("數(shù)量");
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?+?"");
}
});
}
}
}
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數(shù)量/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"繼續(xù)挑選/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"系統(tǒng)提示/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通過JFrame做一個登錄系統(tǒng)的界面完整代碼示例,具有一定借鑒價值,需要的朋友可以參考下。
在java的JFrame內通過創(chuàng)建匿名對象的方式做登錄界面
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) {
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("還要繼續(xù)購物嗎?(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("請輸入購買數(shù)量:");
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;
}
}