📄 inputpanel.java
字号:
//This class communicate with user for inputing
//student information.;
import javax.swing.JPanel;
import javax.swing.table.TableModel;
import java.awt.TextField;
import java.awt.Label;
import java.awt.Button;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class InputPanel extends JPanel implements ActionListener,KeyListener
{
Label l=null;
TextField tf=null;
Button b1=null;
InputTable table=null;
TableModel model=null;
MyStuInfoWriter writer=null;
GridBagLayout la=null;
GridBagConstraints c=null;
public InputPanel()
{
super();
la=new GridBagLayout();
c=new GridBagConstraints();
setLayout(la);
inital();
}
public void inital()
{
b1=new Button("提交信息");
b1.addActionListener(this);
table=new InputTable();
c.gridwidth=GridBagConstraints.REMAINDER;
addCom(table,la,c);
addCom(b1,la,c);
}
public void addCom(Component c1,GridBagLayout l,GridBagConstraints c)
{
l.setConstraints(c1,c);
add(c1);
}
public void actionPerformed(ActionEvent e)
{
try
{
model=table.getModel();
String stuClass=(String)model.getValueAt(1,0);
writer=new MyStuInfoWriter(stuClass);
writer.writeInfos(getAllInfos(model));
writer.close();
remove(table);
remove(b1);
inital();
getParent().setVisible(true);
}
catch(Exception es)
{
}
}
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
protected String getAllInfos(TableModel model)
{
StringBuffer s=new StringBuffer();
s.append(getValue(model,1,1)+"/");
s.append(getValue(model,1,2)+"/");
s.append(getValue(model,1,3)+"/");
s.append(getValue(model,1,4)+"/");
s.append(getValue(model,1,5)+"/");
s.append(getColumnInfos(model,0));
s.append(getColumnInfos(model,1));
s.append(getAllUsualScores(model));
s.append(getColumnInfos(model,6));
return s.toString();
}
private String getColumnInfos(TableModel model,int column)
{
StringBuffer buffer=new StringBuffer();
for(int i=3;i<model.getRowCount();i++)
{
String s=(String)model.getValueAt(i,column);
if(s==null)
{
s=new String("0");
}
buffer.append(s+"/");
}
return buffer.toString();
}
private String getAllUsualScores(TableModel model)
{
StringBuffer buffer=new StringBuffer();
for(int i=3;i<11;i++)
{
buffer.append(getUsualScores(model,i));
}
return buffer.toString();
}
private String getUsualScores(TableModel model,int row)
{
int allScores=0;
int key=0;
for(int i=2;i<6;i++)
{
int k=0;
String s=(String)model.getValueAt(row,i);
if(s!=null)
k=new Integer(s).intValue();
allScores+=k;
if(k!=0)
{
key++;
}
}
if(key==0)
return new String("0"+"/");
else
return new Integer((int)(allScores/key)).toString()+"/";
}
private String getValue(TableModel model,int row,int column)
{
String s=(String)model.getValueAt(row,column);
if(s==null)
return new String("0");
else
return s;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -