import java.util.*;
十載的固原網(wǎng)站建設經(jīng)驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。營銷型網(wǎng)站建設的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調(diào)整固原建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“固原網(wǎng)站設計”,“固原網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
class 商品 extends Panel
{String 代號,名稱;int 庫存;float 單價;
商品(String 代號,String 名稱,int 庫存,float 單價)
{this.代號=代號;this.名稱=名稱;this.庫存=庫存;this.單價=單價;
}
}
class ShowWin extends JFrame implements ActionListener
{ Hashtable hashtable=null;
JTextField 代號文本框=new JTextField(),
名稱文本框=new JTextField(),
庫存文本框=new JTextField(),
單價文本框=new JTextField(),
查詢文本框=new JTextField(),
查詢信息文本框=new JTextField(),
刪除文本框=new JTextField();
JButton b_add=new JButton("添加商品"),
b_del=new JButton("刪除商品"),
b_xun=new JButton("查詢商品"),
b_xiu=new JButton("修改商品"),
b_show=new JButton("顯示商品清單");
JTextArea 顯示區(qū)=new JTextArea(25,10);
ShowWin()
{super("倉庫管理窗口");
hashtable=new Hashtable();
Container con=getContentPane();
JScrollPane pane=new JScrollPane(顯示區(qū));
顯示區(qū).setEditable(false);
JPanel save=new JPanel();
save.setLayout(new GridLayout(8,2));
save.add(new Label("輸入代號:"));
save.add(代號文本框);
save.add(new Label("輸入名稱:"));
save.add(名稱文本框);
save.add(new Label("輸入庫存:"));
save.add(庫存文本框);
save.add(new Label("輸入單價:"));
save.add(單價文本框);
save.add(new Label("單擊添加:"));
save.add(b_add);
save.add(new Label("單擊修改:"));
save.add(b_xiu);
save.add(new Label("輸入查詢代號:"));
save.add(查詢文本框);
save.add(new Label("單擊查詢:"));
save.add(b_xun);
JPanel del=new JPanel();
del.setLayout(new GridLayout(2,2));
del.add(new Label("輸入刪除的代號:"));
del.add(刪除文本框);
del.add(new Label("單擊刪除:"));
del.add(b_del);
JPanel show=new JPanel();
show.setLayout(new BorderLayout());
show.add(pane,BorderLayout.CENTER);
show.add(b_show,BorderLayout.SOUTH);
JSplitPane split_one,split_two;
split_one=new JSplitPane(JSplitPane.VERTICAL_SPLIT,save,del);
split_two=new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split_one,show);
con.add(split_two,BorderLayout.CENTER);
JPanel xun=new JPanel();
xun.add(new Label("所得信息:"));
xun.add(查詢信息文本框);
xun.setLayout(new GridLayout(2,1));
con.add(xun,BorderLayout.SOUTH);
b_add.addActionListener(this);
b_del.addActionListener(this);
b_xun.addActionListener(this);
b_xiu.addActionListener(this);
b_show.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b_add)
{String daihao=null,mingcheng=null;int kucun=0;float danjia=0.0f;
daihao=代號文本框.getText();mingcheng=名稱文本框.getText();
kucun=Integer.parseInt(庫存文本框.getText());
danjia=Float.valueOf(單價文本框.getText()).floatValue();
商品 goods=new 商品(daihao,mingcheng,kucun,danjia);
hashtable.put(daihao,goods);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
else if(e.getSource()==b_del)
{String daihao1=刪除文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(daihao1);
{hashtable.remove(daihao1);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_xun)
{ String aa;
aa=查詢文本框.getText();
查詢信息文本框.setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 a=(商品)hashtable.get(aa);
查詢信息文本框.setText(" 代號:"+a.代號+" 名稱:"+a.名稱+" 庫存:"+a.庫存+" 單價:"+a.單價);
}
//
else if(e.getSource()==b_xiu)
{ String bb;
bb=代號文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(bb);
{hashtable.remove(bb);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
String daihao1=null,mingcheng1=null;int kucun1=0;float danjia1=0.0f;
daihao1=代號文本框.getText();mingcheng1=名稱文本框.getText();
kucun1=Integer.parseInt(庫存文本框.getText());
danjia1=Float.valueOf(單價文本框.getText()).floatValue();
商品 goods1=new 商品(daihao1,mingcheng1,kucun1,danjia1);
hashtable.put(daihao1,goods1);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_show)
{ 顯示區(qū).setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
}
catch(ClassNotFoundException event){}
catch(IOException event){}
Enumeration enum=hashtable.elements();
while(enum.hasMoreElements())
{ 商品 te=(商品)enum.nextElement();
顯示區(qū).append("商品代號:"+te.代號+" ");
顯示區(qū).append("商品名稱:"+te.名稱+" ");
顯示區(qū).append("商品庫存:"+te.庫存+" ");
顯示區(qū).append("商品單價:"+te.單價+" ");
顯示區(qū).append("\n ");
}
}
}
}
public class LinkListFour
{public static void main(String args[])
{ ShowWin win=new ShowWin();
win.setSize(400,350);
win.setVisible(true);
win.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{ System.exit(0);}});
}
}
package?entity;
public?class?Market?{
private?int?id;//id
private?int?num;//數(shù)量
private?String?goods;//商品
private?double?price;//價格
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("您消費共計:"+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("-------超市計價系統(tǒng)-------");
String?goods1="可口可樂";
String?goods2="爆米花";
String?goods3="益達";
printTable("編號","商品","價格");
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("請輸入商品的編號:");
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é)果:
-------超市計價系統(tǒng)-------
編號????????????商品??????????價格
1?????可口可樂??????????3.0¥
2?????爆米花??????????5.0¥
3?????益達??????????10.0¥
請輸入商品的編號:
3
請輸入商品的數(shù)量
5
您消費共計:50.0¥
首先,需要下載JDK源代碼(Oracle官網(wǎng)找或者搜一下,到處都有),一般會打成zip包做下載,下載后并不需要進行解壓;
然后,可使用以下幾種方式將class文件與源文件進行關(guān)聯(lián):
(1) 如果你沒有進行關(guān)聯(lián)過,可以在Editor中寫下如下的語句:
String str = null;
然后按住Ctrl鍵, 用鼠標左鍵點擊"String",
就會彈出 Class File Editor 的界面讓你關(guān)聯(lián)源文件,
點擊界面上的"Attach Source..."按鈕,
在彈出的"Source Attachment Configuration"界面中,
點擊"External File", 選擇你下載的源文件zip包,一路OK即可;
(2) 在項目中找到 JRE System Library,定位到如下:
JRE System Library - rt.jar - java-lang-String.class
雙擊String.class,即彈出關(guān)聯(lián)源文件的界面;
(3) 在項目中找到 JRE System Library, 定位到 rt.jar,
鼠標右鍵點擊,在彈出的界面中選擇"Properties...",
在彈出的界面中,左邊默認會選中"Java Source Attachment",
在右邊進行源文件的關(guān)聯(lián);
(4) Window-Preferences-Java-Installed JREs
在右邊的"Installed JREs:"窗口中選中所使用的JRE,
點擊其右邊的"Edit",在彈出的"Edit JRE"窗口中,
有一個"JRE system libraries:"列表,
在其中找到 "...jdk1.6.0_13\jre\lib\rt.jar" 并選中,
點擊右邊的"Source Attachment...",
在彈出的"Source Attachment Configuration"界面中,
點擊文本框右邊的"External File",
選擇你下載的源文件zip包,一路OK即可;
以下方法實現(xiàn)了用戶界面登陸
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用戶名:");//使用文本創(chuàng)建一個用戶名標簽
TextField t1=new TextField();//創(chuàng)建一個文本框?qū)ο?/p>
Label password=new Label("密碼:");//創(chuàng)建一個密碼標簽
TextField t2=new TextField();
Button b1=new Button("登陸");//創(chuàng)建登陸按鈕
Button b2=new Button("取消");//創(chuàng)建取消按鈕
public DengLuJieMian()
{
this.setTitle("學生信息管理系統(tǒng)");//設置窗口標題
this.setLayout(null);//設置窗口布局管理器
username.setBounds(50,40,60,20);//設置姓名標簽的初始位置
this.add(username);// 將姓名標簽組件添加到容器
t1.setBounds(120,40,80,20);// 設置文本框的初始位置
this.add(t1);// 將文本框組件添加到容器
password.setBounds(50,100,60,20);//密碼標簽的初始位置
this.add(password);//將密碼標簽組件添加到容器
t2.setBounds(120,100,80,20);//設置密碼標簽的初始位置
this.add(t2);//將密碼標簽組件添加到容器
b1.setBounds(50,150,60,20);//設置登陸按鈕的初始位置
this.add(b1);//將登陸按鈕組件添加到容器
b2.setBounds(120,150,60,20);//設置取消按鈕的初始位置
this.add(b2);// 將取消按鈕組件添加到容器
b1.addActionListener(this);//給登陸按鈕添加監(jiān)聽器
b2.addActionListener(this);// 給取消按鈕添加監(jiān)聽器
this.setVisible(true);//設置窗口的可見性
this.setSize(300,200);//設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通過內(nèi)部類重寫關(guān)閉窗體的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//處理登陸事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判斷語句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函數(shù)
{
new DengLuJieMian();
}
}
以下方法實現(xiàn)了學生界面設計
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//創(chuàng)建菜單欄
Menu m1=new Menu("信息");//創(chuàng)建菜單“信息”
MenuItem m11=new MenuItem("插入");//創(chuàng)建“插入”的菜單項
MenuItem m12=new MenuItem("查詢");
Menu m2=new Menu("成績");//創(chuàng)建菜單“成績”
MenuItem m21=new MenuItem("查詢");
public StudentJieMian()
{
this.setTitle("學生界面");//設置窗口標題
this.setLayout(new CardLayout());//設置窗口布局管理器
this.setMenuBar(m);//將菜單欄組件添加到容器
m.add(m1);//將信息菜單放入菜單欄
m.add(m2);
m1.add(m11);//將“插入”菜單項添加到“信息”菜單
m1.add(m12); //將“查詢”菜單項添加到“信息”菜單
m2.add(m21); //將“查詢”菜單項添加到“成績”菜單
m11.addActionListener(this); //給“插入”菜單項添加監(jiān)聽器
m12.addActionListener(this); //給“查詢”菜單項添加監(jiān)聽器
m21.addActionListener(this); //給“查詢”菜單項添加監(jiān)聽器
this.setVisible(true); //設置窗口的可見性
this.setSize(300,200); //設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//關(guān)閉窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //處理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //處理“查詢信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //處理“查詢成績”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //創(chuàng)建一個對象 }
文章標題:java項目系統(tǒng)代碼 java項目源碼大全免費版下載
本文網(wǎng)址:http://jinyejixie.com/article22/dossejc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、企業(yè)建站、網(wǎng)站營銷、虛擬主機、微信公眾號、品牌網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)