试验报告二分覆盖问题Word下载.docx
《试验报告二分覆盖问题Word下载.docx》由会员分享,可在线阅读,更多相关《试验报告二分覆盖问题Word下载.docx(16页珍藏版)》请在冰豆网上搜索。
importjava.util.*;
importjavax.swing.*;
importjavax.swing.table.*;
importjavax.swing.ListSelectionModel;
importjavax.swing.event.ListSelectionListener;
importjavax.swing.event.ListSelectionEvent;
importjava.io.OutputStream;
//~~~~~主函数
publicclasscover
{
publicstaticvoidmain(String[]args)
{
Centerfframe=newCenterf();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
classCenterfextendsJFrameimplementsActionListener
privateJLabelnum,price;
privateJButtonenter;
privateJButtonExit;
privateJTextFieldTanum,Tbnum;
privateJPanelpanelnum,panelprice,panelctr;
privateStringanum,bnum;
privateintianum,ibnum;
publicCenterf()
setSize(250,250);
setTitle("
二分覆盖"
);
num=newJLabel("
请输入A集个数"
price=newJLabel("
请输入B集个数"
enter=newJButton("
确定"
Exit=newJButton("
退出"
Tanum=newJTextField(5);
Tbnum=newJTextField(5);
panelnum=newJPanel();
panelnum.add(num);
panelnum.add(Tanum);
panelprice=newJPanel();
panelprice.add(price);
panelprice.add(Tbnum);
panelctr=newJPanel();
panelctr.add(enter);
panelctr.add(Exit);
Containercpanel=getContentPane();
cpanel.setLayout(newFlowLayout());
cpanel.add(panelnum,BorderLayout.NORTH);
cpanel.add(panelprice,BorderLayout.CENTER);
cpanel.add(panelctr,BorderLayout.SOUTH);
enter.addActionListener(this);
Exit.addActionListener(this);
publicvoidactionPerformed(ActionEventevent)//frame监听事件
{
if(event.getSource()==enter)
{
anum=Tanum.getText();
ianum=Integer.parseInt(anum);
bnum=Tbnum.getText();
ibnum=Integer.parseInt(bnum);
ZCenterfzframe=newZCenterf(ianum,ibnum);
zframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
zframe.show();
}
elseif(event.getSource()==Exit)
System.exit(0);
}
classZCenterfextendsJFrameimplementsActionListener
privateJButtonpr;
privateJPanelpanel;
privateCreatTabletb;
privateJScrollPanejsp;
privateintnum,col,contant;
privateinttotlecontant;
intselectedRow=0;
publicZCenterf(intanum,intbnum)
{
num=anum;
setSize(500,250);
pr=newJButton("
panel=newJPanel();
panel.add(pr);
panel.add(Exit);
pr.addActionListener(this);
col=bnum;
tb=newCreatTable();
jsp=tb.MakeTable(num,col);
Containercpanel=getContentPane();
cpanel.add(panel,BorderLayout.SOUTH);
cpanel.add(jsp,BorderLayout.CENTER);
publicvoidactionPerformed(ActionEventevent)
if(event.getSource()==Exit)//~~~监听退出事件
hide();
elseif(event.getSource()==pr)//~~~监听确定事件
tb.method(num,col);
}
classCreatTableimplementsListSelectionListener
AbstractTableModeltm;
Vectorvect;
//声明一个向量对象
privateJTabletab;
privateString[]title,kch;
privateObject[][]obj;
privateString[][]str;
privateint[]count;
privateint[]flag;
privateintrow,col,selectedRow=0;
publicCreatTable()
publicJScrollPaneMakeTable(intarow,intacol)//制作table表
try
row=arow;
intbcol=acol;
col=acol+1;
str=newString[row][col];
title=newString[col];
//table表头
title[0]="
A类/B类"
;
for(inti=1;
i<
=bcol;
i++)
intn=row+i;
title[i]=Integer.toString(n);
obj=newObject[row][col];
for(inti=0;
row;
obj[i][0]=Integer.toString(i+1);
tm=newAbstractTableModel()
publicintgetColumnCount()//取得表格列数
{
returntitle.length;
}
publicintgetRowCount()//取得表格行数
{
returnrow;
publicObjectgetValueAt(intarow,intacolumn)//取得单元格中的属性值
returnobj[arow][acolumn];
publicStringgetColumnName(intcolumn)//设置表格列名
returntitle[column];
publicbooleanisCellEditable(intarow,intcolumn)
returntrue;
}//设置单元格可编辑
publicvoidsetValueAt(Objectaobj,intarow,intacolumn)//设置单元格中的属性值
obj[arow][acolumn]=aobj;
};
tm.fireTableDataChanged();
//更新表格,显示向量vect的内容
tab=newJTable(tm);
intv=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
inth=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jsp=newJScrollPane(tab,v,h);
tab.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModelrowSM=tab.getSelectionModel();
rowSM.addListSelectionListener(this);
catch(NullPointerExceptionsqle){
System.out.println("
[tgetconnectionNullPointerException]:
"
+sqle.getMessage());
returnjsp;
publicvoidvalueChanged(ListSelectionEvente)//table监听
{
if(e.getValueIsAdjusting())
return;
ListSelectionModellsm=(ListSelectionModel)e.getSource();
if(!
(lsm.isSelectionEmpty()))
{
selectedRow=lsm.getMinSelectionIndex();
}
publicObjectgetvalue(intarow,intacol)//取得单元格中的属性值
returnobj[arow][acol];
publicvoidsetvalue(intarow,intacol)
obj[arow][acol]="
ok"
tm.fireTableDataChanged();
publicObject[][]update()
tab=newJTable(tm);
for(inti=0;
for(intj=0;
j<
col;
j++)
obj[i][j]=getvalue(i,j);
returnobj;
publicintover()
intoflag=1;
col-1;
if(flag[i]==0)oflag=0;
returnoflag;
publicvoidmethod(intarow,intacol)
intk,kt;
k=0;
intar,ac,n1;
ar=arow;
ac=acol;
flag=newint[ac];
count=newint[ar];
table=newint[ar][ac];
while(over()==0)
for(inti=0;
ar;
{
for(intj=1;
=ac;
if(String.valueOf(obj[i][j]).equals("
1"
))
{
count[i]++;
}
intmax=count[0];
if(count[i]>
max)
max=count[i];
for(kt=0;
kt<
kt++)
if(count[kt]==max)
{k=kt;
System.out.println(k);
{
if(Integer.parseInt(String.valueOf(obj[k][i]))==1)
{intlk;
lk=i;
setvalue(k,lk);
flag[i-1]=1;
}