大家好~!~!我是一名大一的学生~!学习JAVA才半学期~!~期末了~!老师布置了一个课程实践~!题目自拟~!由于上个学期我是先学VB的~!在期末课程实践中我用VB做了个人力资源管理系统~!所以JAVA我也想做个音像管理系统~!但是我还没有学到JAVA和数据库编程~!~我原先是用HashTable和数据的输入输出来存储数据~(自学的~!很多地方都不明白~!)!但是不知道怎么回事,没有数据的输入和输出~!(问老师了~!老师也搞不懂~!~因为我写的代码带乱了,也带多了~!嘿嘿~~~~~!)现在老师规定的时间快到了 `!~而我又不得不用数据库来进行存储~~!所以请各位帮我完成我的课程实践~!谢谢`各位`!~我也可以从中学习`!~,并且得到提高`!~我的QQ:24215382 邮箱:[email protected]
******************************************************************************************************************************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class VideoManage extends JDialog implements ActionListener
{
TodayBalance Tb=new TodayBalance();
JPanel p,p1,p2,p3,pAll;
Box box1,box2,box3,boxAll;
JLabel l1,l2,l3,l4,l5,l6;
JButton b1,b2,b3,b4,b5;
JTextField t1,t2,t3,t4,t5;
CardLayout card;
public VideoManage(JFrame s)
{
super(s,"管理",true);
setVisible(false);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
l1=new JLabel("编号:",JLabel.CENTER);
l1.setFont(new Font("宋体",Font.BOLD,20));
l2=new JLabel("名称:",JLabel.CENTER);
l2.setFont(new Font("宋体",Font.BOLD,20));
l3=new JLabel("进货时间:",JLabel.CENTER);
l3.setFont(new Font("宋体",Font.BOLD,20));
l4=new JLabel("进货价:",JLabel.CENTER);
l4.setFont(new Font("宋体",Font.BOLD,20));
l5=new JLabel("出售价:",JLabel.CENTER);
l5.setFont(new Font("宋体",Font.BOLD,20));
l6=new JLabel("元:",JLabel.CENTER);
l6.setFont(new Font("宋体",Font.BOLD,15));
b1=new JButton("查看"
;
b1.setForeground(Color.blue);
b1.setFont(new Font("楷体",Font.BOLD+Font.ITALIC,20));
b1.addActionListener(this);
b2=new JButton("确定"
;
b2.setForeground(Color.blue);
b2.setFont(new Font("楷体",Font.BOLD+Font.ITALIC,20));
b2.setEnabled(false);
b2.addActionListener(this);
b3=new JButton("出售价"
;
b3.setForeground(Color.blue);
b3.setFont(new Font("楷体",Font.BOLD+Font.ITALIC,20));
b3.addActionListener(this);
b4=new JButton("今日结算"
;
b4.setForeground(Color.blue);
b4.setFont(new Font("楷体",Font.BOLD+Font.ITALIC,20));
b4.addActionListener(this);
t1=new JTextField(8);
t2=new JTextField(8);
t2.setEditable(false);
t3=new JTextField(12);
t3.setEditable(false);
t4=new JTextField(8);
t4.setEditable(false);
t5=new JTextField(8);
box1=Box.createHorizontalBox();
box1.add(l1);
box1.add(t1);
box1.add(b1);
box2=Box.createHorizontalBox();
box2.add(l2);
box2.add(t2);
box2.add(l3);
box2.add(t3);
box3=Box.createHorizontalBox();
box3.add(l4);
box3.add(t4);
box3.add(l5);
box3.add(t5);
box3.add(l6);
boxAll=Box.createVerticalBox();
boxAll.add(box1);
boxAll.add(box2);
boxAll.add(box3);
p3=new JPanel();
p3.add(b2);
p=new JPanel();
p.setLayout(new BorderLayout());
p.add(boxAll,BorderLayout.NORTH);
p.add(p3,BorderLayout.SOUTH);
p1=new JPanel();
p1.add(b3);
p1.add(b4);
p1.setLayout(new GridLayout(2,1));
p2=new JPanel();
p2.setLayout(new BorderLayout());
p2.add(p1,BorderLayout.WEST);
card=new CardLayout();
pAll=new JPanel();
pAll.setLayout(card);
pAll.add("出售价",p);
pAll.add("今日结算",Tb);
Container c=getContentPane();
c.add(pAll,BorderLayout.CENTER);
c.add(p2,BorderLayout.WEST);
setVisible(false);
setBounds(300,300,640,300);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b3)
{
card.show(pAll,"出售价"
;
}
if(e.getSource()==b4)
{
//this.setVisible(false);
card.show(pAll,"今日结算"
;
}
if(e.getSource()==b1)
{
b2.setEnabled(true);
}
}
}
——————————————————————————————————————————————————————-———
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Colligate extends JPanel
{
JTable tb;
JScrollPane sp;
JPanel p,p1,p2,p3;
public Colligate()
{
String[] title={"编号","名称","类别编号","类别","类型编号","类型","进货量","进货价","出售量",
"出售价","总计(元)"};
String[][] data={{"1234","1234","1234","1234","1234","1234","1234","1234","1234","1234","1234"}
,{"4567","4567","4567","4567","4567","4567","4567","4567","4567","4567","4567"}};
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
tb=new JTable(data,title);
//
tb.setAutoResizeMode(20);
sp=new JScrollPane(tb,v,h);
add(sp,BorderLayout.CENTER);
//
setSize(500,500);
}
}
——————————————————————————————————————————————————————————
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JOptionPane;
import java.util.*;
public class VideoImport extends JPanelimplements ActionListener,ItemListener
{
String s1[];
String s2[];
String s3[];
String s4[];
Hashtable ht=new Hashtable();
Communication com;
FileInputStream inOne;
ObjectInputStream inTwo;
FileOutputStream outOne;
ObjectOutputStream outTwo;
File f;
JButton b1,b2;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14;
JPanel p,p1,p2;
JComboBox cb1,cb2,cb3,cb4;
Box box1,box2,box3,box4,box5,box6,boxAll;
public VideoImport(File f)
{
//设置面版组件;
this.f=f;
l1=new JLabel("编号:",JLabel.CENTER);
l1.setFont(new Font("宋体",Font.BOLD,20));
l2=new JLabel("名称:",JLabel.CENTER);
l2.setFont(new Font("宋体",Font.BOLD,20));
l3=new JLabel("类别编号:",JLabel.CENTER);
l3.setFont(new Font("宋体",Font.BOLD,20));
l4=new JLabel("类别:",JLabel.CENTER);
l4.setFont(new Font("宋体",Font.BOLD,20));
l5=new JLabel("类型编号:",JLabel.CENTER);
l5.setFont(new Font("宋体",Font.BOLD,20));
l6=new JLabel("类型:",JLabel.CENTER);
l6.setFont(new Font("宋体",Font.BOLD,20));
l7=new JLabel("主演:",JLabel.CENTER);
l7.setFont(new Font("宋体",Font.BOLD,20));
l8=new JLabel("进货价:",JLabel.CENTER);
l8.setFont(new Font("宋体",Font.BOLD,20));
l9=new JLabel("进货时间:",JLabel.CENTER);
l9.setFont(new Font("宋体",Font.BOLD,20));
l10=new JLabel("进货量:",JLabel.CENTER);
l10.setFont(new Font("宋体",Font.BOLD,20));
l11=new JLabel("元",JLabel.CENTER);
l11.setFont(new Font("宋体",Font.BOLD,15));
l12=new JLabel("年",JLabel.CENTER);
l12.setFont(new Font("宋体",Font.BOLD,20));
l13=new JLabel("月",JLabel.CENTER);
l13.setFont(new Font("宋体",Font.BOLD,20));
l14=new JLabel("日",JLabel.CENTER);
l14.setFont(new Font("宋体",Font.BOLD,20));
s1=new String[]{"","影视类","音乐类","动漫类","游戏类","磁带类"};
s2=new String[]{"","动作","喜剧","爱情","科幻","恐怖","战争","连续剧","中国大陆","港台","外国"};
s3=new String[]{"","A001","B001","C001","D001","E001"};
s4=new String[]{"","a001","a002","a003","a004","a005","a006","a007","b001","b002","b003"};
t1=new JTextField(8);
t2=new JTextField(8);
t3=new JTextField(8);
t4=new JTextField(8);
t5=new JTextField(8);
t6=new JTextField(8);
t7=new JTextField(8);
t8=new JTextField(4);
t9=new JTextField(2);
t10=new JTextField(2);
t11=new JTextField(3);
//添加内容到列表框;
cb1=new JComboBox();
for(int i=0;i0 && name.length()>0)
{
try {
inOne=new FileInputStream(f);
inTwo=new ObjectInputStream(inOne);
ht=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception e1)
{
}
if(ht.containsKey(id))
{
String warning=new String("该"+id+"的"+name+"已经有X张!"
;
JOptionPane.showMessageDialog(this,warning,"信息",JOptionPane.WARNING_MESSAGE);
String m="进货确认!";
int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
{
String sortid=cb1.getUIClassID();
String sort=cb2.getUIClassID();
String typeid=cb3.getUIClassID();
String type=cb4.getUIClassID();
String person1=t3.getText();
String person2=t4.getText();
String person3=t5.getText();
String person4=t6.getText();
String inmoney=t7.getText();
String indate1=t8.getText();
String indate2=t9.getText();
String indate3=t10.getText();
String innumber=t11.getText();
com=new Communication();
com.setId(id);
com.setName(name);
com.setSortId(sortid);
com.setSort(sort);
com.setTypeId(typeid);
com.setType(type);
com.setPerson1(person1);
com.setPerson2(person2);
com.setPerson3(person3);
com.setPerson4(person4);
com.setInmoney(inmoney);
com.setIndate1(indate1);
com.setIndate2(indate2);
com.setIndate3(indate3);
com.setInnumber(innumber);
}
}
else
{
String m1="进货确认!";
int ok1=JOptionPane.showConfirmDialog(this,m1,"确认",JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if(ok1==JOptionPane.YES_OPTION)
{
String sortid=cb1.getUIClassID();
String sort=cb2.getUIClassID();
String typeid=cb3.getUIClassID();
String type=cb4.getUIClassID();
String person1=t3.getText();
String person2=t4.getText();
String person3=t5.getText();
String person4=t6.getText();
String inmoney=t7.getText();
String indate1=t8.getText();
String indate2=t9.getText();
String indate3=t10.getText();
String innumber=t11.getText();
com=new Communication();
com.setId(id);
com.setName(name);
com.setSortId(sortid);
com.setSort(sort);
com.setTypeId(typeid);
com.setType(type);
com.setPerson1(person1);
com.setPerson2(person2);
com.setPerson3(person3);
com.setPerson4(person4);
com.setInmoney(inmoney);
com.setIndate1(indate1);
com.setIndate2(indate2);
com.setIndate3(indate3);
com.setInnumber(innumber);
try{
outOne=new FileOutputStream(f);
outTwo=new ObjectOutputStream(outOne);
ht.put(id,com);
outTwo.writeObject(ht);
outTwo.close();
outOne.close();
t1.setText(null);
t2.setText(null);
t3.setText(null);
t4.setText(null);
t5.setText(null);
t6.setText(null);
t7.setText(null);
t8.setText(null);
t9.setText(null);
t10.setText(null);
t11.setText(null);
}
catch(Exception e2)
{
//System.out.println(e2);
}
}
}
//}
}
else
{
String warning="请输入编号和名称!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
//}
}
if(e.getSource()==b2)
{
t1.setText(null);
t2.setText(null);
t3.setText(null);
t4.setText(null);
t5.setText(null);
t6.setText(null);
t7.setText(null);
t8.setText(null);
t9.setText(null);
t10.setText(null);
t11.setText(null);
}
//}
}
public void itemStateChanged(ItemEvent isc)
{
int x=0,y;
int x1=0,y1;
String ok1=(String)isc.getItem();
String ok=(String)isc.getItem();
if(isc.getSource()==cb2)
{
for(y=0;y<s1.length;y++)
{
if(ok==s1[y])
{
x=cb2.getSelectedIndex();
switch(x)
{
case 0:
cb1.setSelectedItem(s3[y]);
break;
case 1:
cb1.setSelectedItem(s3[y]);
break;
case 2:
cb1.setSelectedItem(s3[y]);
break;
case 3:
cb1.setSelectedItem(s3[y]);
break;
case 4:
cb1.setSelectedItem(s3[y]);
break;
case 5:
cb1.setSelectedItem(s3[y]);
break;
}
}
}
}
if(isc.getSource()==cb4)
{
for(y1=0;y1<s2.length;y1++)
{
if(ok1==s2[y1])
{
x1=cb4.getSelectedIndex();
if(x1==0)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==1)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==2)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==3)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==4)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==5)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==6)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==7)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==8)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==9)
{
cb3.setSelectedItem(s4[y1]);
}
else if(x1==10)
{
cb3.setSelectedItem(s4[y1]);
}
}
}
}
}
}
——————————————————————————————————————————————————————————
public class Communication implements java.io.Serializable
{
String id,name,sortid,sort,typeid,type,person1,person2,person3,person4,
inmoney,outmoney,indate1,indate2,indate3,innumber,outnumber,outdate1,outdate2,outdate3;
public Communication()
{
}
public void setId(String id)
{
this.id=id;
}
public String getId()
{
return id;
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setSortId(String sortid)
{
this.sortid=sortid;
}
public String getSortId()
{
return sortid;
}
public void setSort(String sort)
{
this.sort=sort;
}
public String getSort()
{
return sort;
}
public void setTypeId(String typeid)
{
this.typeid=typeid;
}
public String getTypeId()
{
return typeid;
}
public void setType(String type)
{
this.type=type;
}
public String getType()
{
return type;
}
public void setPerson1(String person1)
{
this.person1=person1;
}
public String getPerson1()
{
return person1;
}
public void setPerson2(String person2)
{
this.person2=person2;
}
public String getPerson2()
{
return person2;
}
public void setPerson3(String person3)
{
this.person3=person3;
}
public String getPerson3()
{
return person3;
}
public void setPerson4(String person4)
{
this.person4=person4;
}
public String getPerson4()
{
return person4;
}
public void setInmoney(String inmoney)
{
this.inmoney=inmoney;
}
public String getInmoney()
{
return inmoney;
}
public void setOutmoney(String outmoney)
{
this.outmoney=outmoney;
}
public String getOutmoney()
{
return outmoney;
}
public void setIndate1(String year)
{
this.indate1=indate1;
}
public String getIndate1()
{
return indate1;
}
public void setIndate2(String month)
{
this.indate2=indate2;
}
public String getIndate2()
{
return indate2;
}
public void setIndate3(String day)
{
this.indate3=indate3;
}
public String getIndate3()
{
return indate3;
}
public void setOutdate1(String Yera)
{
this.outdate1=outdate1;
}
public String getOutdate1()
{
return outdate1;
}
public void setOutdate2(String Month)
{
this.outdate2=outdate2;
}
public String getOutdate2()
{
return outdate2;
}
public void setOutdate3(String Day)
{
this.outdate3=outdate3;
}
public String getOutdate3()
{
return outdate3;
}
public void setInnumber(String innumber)
{
this.innumber=innumber;
}
public String getInnumber()
{
return innumber;
}
public void setOutnumber(String outnumber)
{
this.outnumber=outnumber;
}
public String getOutnumber()
{
return outnumber;
}
}
|