📄 dbs.java
字号:
tableList(hang);
}
catch(Exception e1)
{
}
}
}
void fileOpen2()////////////打开文件2
{
hang2.clear();
suoyin2.clear();
load.setVisible(true);
if(load.getFile()!=null)
{
try
{
File file=new File(load.getDirectory(),load.getFile());
filename[1]=""+file.getName();
FileInputStream fi=new FileInputStream(file);
ObjectInputStream oi=new ObjectInputStream(fi);
LinkedList newhang=((LinkedList)oi.readObject());
fi.close();
oi.close();
for(int i=0;i<newhang.size()-3;i++)
{
object o=new object();
LinkedList l=new LinkedList((LinkedList)newhang.get(i));
for(int j=0;j<l.size();j++)
{
CreatBox c=new CreatBox();
c.name=(String)l.get(j);
c.type=(String)((LinkedList)newhang.get(newhang.size()-3)).get(j);
c.leg=(String)((LinkedList)newhang.get(newhang.size()-2)).get(j);
c.NULL=(String)((LinkedList)newhang.get(newhang.size()-1)).get(j);
o.ob.add(c);
}
hang2.add(o.ob);
}
jianlisuoyin2();
tableList(hang2);inlian=((LinkedList)hang.get(0)).size();
}
catch(Exception e1)
{
}
}
}
void shuxing()
{
shuxingFrame=new JFrame("属性");
shuxingFrame.setVisible(true);
shuxingFrame.setBounds(100,100,300,300);
Container con=shuxingFrame.getContentPane();
LinkedList l=(LinkedList)hang.get(0);
con.setLayout(new GridLayout(l.size()+1,1));
s_name=new JTextField[l.size()];
for(int i=0;i<l.size();i++)
{
s_name[i]=new JTextField(5);
CreatBox oo=(CreatBox)l.get(i);
s_name[i].setText(oo.name);
}
s_width=new JTextField[l.size()];
for(int i=0;i<l.size();i++)
{
s_width[i]=new JTextField(5);
CreatBox oo=(CreatBox)l.get(i);
s_width[i].setText(oo.leg);
}
s_type=new JComboBox[l.size()];
for(int i=0;i<l.size();i++)
{
String t_name[]={"Character","Integer"};
s_type[i]=new JComboBox(t_name);
s_type[i].setMaximumRowCount(2);
CreatBox oo=(CreatBox)l.get(i);
s_type[i].setSelectedItem(oo.type);
}
s_NULL=new JButton[l.size()];
for(int i=0;i<l.size();i++)
{
CreatBox oo=(CreatBox)l.get(i);
s_NULL[i]=new JButton(oo.NULL);
}
s_p=new JPanel[l.size()+1];
for(int i=0;i<l.size();i++)
{
s_p[i]=new JPanel();
s_p[i].add(s_name[i]);
s_p[i].add(s_type[i]);
s_p[i].add(s_width[i]);
s_p[i].add(s_NULL[i]);
con.add(s_p[i]);
}
s_p[l.size()]=new JPanel();
s_b=new JButton("确定");
s_p[l.size()].add(s_b);
s_b.addActionListener(this);
con.add(s_p[l.size()]);
shuxingFrame.pack();
}
boolean xiangrongbox()
{
LinkedList l=new LinkedList((LinkedList)hang.get(0));
LinkedList l2=new LinkedList((LinkedList)hang2.get(0));
if(l.size()!=l2.size())
{
JOptionPane.showMessageDialog(null,"两张表属性个数不同\n请重新打开两张表");
return false;
}
for(int i=0;i<l.size();i++)
{
CreatBox c=new CreatBox((CreatBox)l.get(i));
CreatBox c2=new CreatBox((CreatBox)l2.get(i));
if(!c.leg.equals(c2.leg)||!c.name.equals(c2.name)||!c.type.equals(c2.type))
{JOptionPane.showMessageDialog(null,"两张表属性个数不同\n请重新打开两张表");
return false;
}
}
return true;
}
void tableList(LinkedList link)
{
for(int i=0;i<link.size();i++)
{
LinkedList l=(LinkedList)link.get(i);
if(i==0)
{
area.append("序号"+"\t");
}
else
{
area.append(i+"\t");
}
for(int j=0;j<l.size();j++)
{
CreatBox oo=(CreatBox)l.get(j);
area.append(oo.name+"\t");
}
area.append("\n");
}
area.append("\n\n");
for(int i=0;i<suoyin.size();i++)
{
index in=new index((index)suoyin.get(i));
}
}
void bing()
{
daishu.clear();
boolean b=xiangrongbox();
if(b)
{
int i=0,j=0;
daishu.add(hang.get(0));
while(i<suoyin.size()&&j<suoyin2.size())
{
index dex=new index((index)suoyin.get(i));
index dex2=new index((index)suoyin2.get(j));
if((dex.key.compareTo(dex2.key))>0)
{
int a=Integer.parseInt(dex2.location);
LinkedList l=new LinkedList((LinkedList)hang2.get(a));
daishu.add(l);
j++;
}
else if((dex.key.compareTo(dex2.key))<0)
{
int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang.get(a));
daishu.add(l);
i++;
}
else
{
int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang.get(a));
daishu.add(l);
j++;i++;
}
}
if(i<=suoyin.size())
{
for(int k=i;k<suoyin.size();k++)
{
index dex=new index((index)suoyin.get(k));
// int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang.get(k));
daishu.add(l);
}
}
if(j<=suoyin2.size())
{
for(int k=j;k<suoyin2.size();k++)
{
index dex=new index((index)suoyin2.get(k));
int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang2.get(a));
daishu.add(l);
}
}
tableList(daishu);
}
}
///////////////////////相交/////////////////////////
void jiao()
{
daishu.clear();
boolean b=xiangrongbox();
if(b)
{
int i=0,j=0;daishu.add(hang.get(0));
while(i<suoyin.size()&&j<suoyin2.size())
{
index dex=new index((index)suoyin.get(i));
index dex2=new index((index)suoyin2.get(j));
if((dex.key.compareTo(dex2.key))>0)
{
j++;
}
else if((dex.key.compareTo(dex2.key))<0)
{
i++;
}
else
{
int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang.get(a));
daishu.add(l);
j++;i++;
}
}
tableList(daishu);
}
}
void cha()
{
daishu.clear();
boolean b=xiangrongbox();
if(b)
{
int i=0,j=0;daishu.add(hang.get(0));
while(i<suoyin.size()&&j<suoyin2.size())
{
index dex=new index((index)suoyin.get(i));
index dex2=new index((index)suoyin2.get(j));
if((dex.key.compareTo(dex2.key))>0)
{
j++;
}
else if((dex.key.compareTo(dex2.key))<0)
{
int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang.get(a));
daishu.add(l);
i++;
}
else
{
j++;i++;
}
}
if(i<=suoyin.size())
{
for(int k=i;k<suoyin.size();k++)
{
index dex=new index((index)suoyin.get(k));
int a=Integer.parseInt(dex.location);
LinkedList l=new LinkedList((LinkedList)hang.get(a));
daishu.add(l);
}
}
tableList(daishu);
}
}
void lianjieF()////////////////连接窗口
{
lianjieFrame=new JFrame("连接");
lianjieFrame.setBounds(150,150,300,200);
lianjieFrame.setVisible(true);
Container c=lianjieFrame.getContentPane();
JPanel p=new JPanel();
p.setLayout(new GridLayout(2,1));
JPanel p1=new JPanel();
p1.add(new Label("表一"));
ButtonGroup group1=new ButtonGroup();
LinkedList l=new LinkedList((LinkedList)hang.get(0));
lianb1=new JRadioButton[l.size()];
for(int i=0;i<l.size();i++)
{
CreatBox o=new CreatBox((CreatBox)l.get(i));
lianb1[i]=new JRadioButton(o.name);
p1.add(lianb1[i]);
group1.add(lianb1[i]);
}
JPanel p2=new JPanel();
p2.add(new Label("表二"));
ButtonGroup group2=new ButtonGroup();
LinkedList l2=new LinkedList((LinkedList)hang2.get(0));
lianb2=new JRadioButton[l2.size()];
for(int i=0;i<l2.size();i++)
{
CreatBox o=new CreatBox((CreatBox)l2.get(i));
lianb2[i]=new JRadioButton(o.name);
p2.add(lianb2[i]);
group2.add(lianb2[i]);
}
p.add(p1);p.add(p2);
c.add(p,BorderLayout.CENTER);
JLabel label=new JLabel("请选择两个属性是两个表连接起来");
c.add(label,BorderLayout.NORTH);
button_lianjie=new JButton("确定");
button_lianjie.addActionListener(this);
c.add(button_lianjie,BorderLayout.SOUTH);
lianjieFrame.validate();
}
void connect()
{
String s1=new String();
for(int i=0;i<lianb1.length;i++)
{
if(lianb1[i].isSelected())
{
s1=""+lianb1[i].getText();
break;
}
}
String s2=new String();
for(int i=0;i<lianb2.length;i++)
{
if(lianb2[i].isSelected())
{
s2=""+lianb2[i].getText();
break;
}
}
int m=-1,n=-1;
LinkedList l1=new LinkedList((LinkedList)hang.get(0));
LinkedList l2=new LinkedList((LinkedList)hang2.get(0));
CreatBox o1=new CreatBox();
CreatBox o2=new CreatBox();
for(int i=0;i<l1.size();i++)
{
CreatBox c=new CreatBox((CreatBox)l1.get(i));
if(c.name.equals(s1))
{
o1=c;
m=i;break;
}
}
for(int i=0;i<l2.size();i++)
{
CreatBox c=new CreatBox((CreatBox)l2.get(i));
if(c.name.equals(s2))
{
o2=c;
n=i;break;
}
}
if(!o1.leg.equals(o2.leg)||!o1.type.equals(o2.type)||!o1.NULL.equals(o2.NULL))
{
JOptionPane.showMessageDialog(null,"两个属性不同重新选择");
}
else
{
daishu.clear();
for(int i=0;i<l2.size();i++)
{
l1.add(l2.get(i));
}
daishu.add(l1);
for(int i=1;i<hang.size();i++)
{
for(int j=1;j<hang2.size();j++)
{ LinkedList link1=new LinkedList((LinkedList)hang.get(i));
CreatBox c1=new CreatBox((CreatBox)link1.get(m));
LinkedList link2=new LinkedList((LinkedList)hang2.get(j));
CreatBox c2=new CreatBox((CreatBox)link2.get(n));
if(c1.name.equals(c2.name))
{
for(int k=0;k<link2.size();k++)
{
link1.add(link2.get(k));
}
daishu.add(link1);
}
}
}
hang.clear();
for(int i=0;i<daishu.size();i++)
{
hang.add(daishu.get(i));
}
}
}
void connectziran()
{
daishu.clear();
LinkedList l1=new LinkedList((LinkedList)hang.get(0));
if(contain(hang2,l1))
{
JOptionPane.showMessageDialog(null,"不能打开同一张表");
}
else
{
for(int i=0;i<hang.size();i++)
{
for(int j=0;j<hang2.size();j++)
{ LinkedList link1=new LinkedList((LinkedList)hang.get(i));
CreatBox c1=new CreatBox((CreatBox)link1.get(0));
LinkedList link2=new LinkedList((LinkedList)hang2.get(j));
CreatBox c2=new CreatBox((CreatBox)link2.get(0));
if(c1.name.equals(c2.name))
{
for(int k=1;k<link2.size();k++)
{
link1.add(link2.get(k));
}
daishu.add(link1);
}
}
}
hang.clear();
for(int i=0;i<daishu.size();i++)
{
hang.add(daishu.get(i));
}
tableList(hang);
}
}
void selectf()
{
selectFrame=new JFrame("投影");
selectFrame.setBounds(150,150,300,200);
selectFrame.setVisible(true);
Container c=selectFrame.getContentPane();
c.setLayout(new GridLayout(3,1));
JPanel sp1=new JPanel();
JPanel sp2=new JPanel();
if(inlian==0)
{
LinkedList l1=new LinkedList((LinkedList)hang.get(0));
sp1.setLayout(new GridLayout(1,(l1.size()+1)));
JLabel selectLabel1=new JLabel(filename[0]);
sp1.add(selectLabel1);
selectRadio1=new JRadioButton[l1.size()];
for(int i=0;i<l1.size();i++)
{
CreatBox b=new CreatBox((CreatBox)l1.get(i));
selectRadio1[i]=new JRadioButton(b.name);
sp1.add(selectRadio1[i]);
}
}
else if(inlian!=0)
{
LinkedList l=new LinkedList((LinkedList)hang.get(0));
sp1.setLayout(new GridLayout(1,inlian+1));
JLabel selectLabel1=new JLabel(filename[0]);
sp1.add(selectLabel1);
selectRadio1=new JRadioButton[inlian];
for(int i=0;i<inlian;i++)
{
CreatBox b=new CreatBox((CreatBox)l.get(i));
selectRadio1[i]=new JRadioButton(b.name);
sp1.add(selectRadio1[i]);
}
sp2.setLayout(new GridLayout(1,l.size()-inlian+1));
JLabel selectLabel2=new JLabel(filename[1]);
sp2.add(selectLabel2);
selectRadio2=new JRadioButton[l.size()-inlian];
for(int i=0;i<l.size()-inlian;i++)
{
CreatBox b=new CreatBox((CreatBox)l.get(i));
selectRadio2[i]=new JRadioButton(b.name);
sp2.add(selectRadio2[i]);
}
}
selectButton1=new JButton("确定");
selectButton1.addActionListener(this);
selectButton2=new JButton("取消");
selectButton2.addActionListener(this);
JPanel sp3=new JPanel();
sp3.setLayout(new GridLayout(1,2));
sp3.add(selectButton1);sp3.add(selectButton2);
c.add(sp1); c.add(sp2); c.add(sp3);
selectFrame.validate();
}
void select()
{
daishu.clear();
daishu2.clear();
if(inlian==0)
{
LinkedList link1=new LinkedList();
for(int i=0;i<selectRadio1.length;i++)
{
if(selectRadio1[i].isSelected())
{
link1.add(new Integer(i));
}
}
for(int i=0;i<hang.size();i++)
{
LinkedList l=new LinkedList((LinkedList)hang.get(i));
LinkedList ll=new LinkedList();
for(int j=0;j<link1.size();j++)
{
Integer dex=(Integer)link1.get(j);
int d=dex.intValue();
ll.add(l.get(d));
}
boolean boo=contain(daishu,ll);
if(!boo)
{
daishu.add(ll);
}
}
}
else
{
LinkedList link1=new LinkedList();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -