📄 viewimpl.java~93~
字号:
package train.client;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableModel;
import train.gui.*;
import train.mvc.*;
import train.parameter.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 沈阳化工学院计算机</p>
*
* @author 彭胜勇 胡林
* @version 1.0
*/
public class ViewImpl implements View {
Model model;
Controller con;
ClientGui clientGui;
SaleTickets saleTickets1;
List trainList;
TableModelTrain tableModelTrain = new TableModelTrain();
public ViewImpl(Model model) {
this.model = model;
this.clientGui=new ClientGui();
this.saleTickets1=new SaleTickets();
model.addViewListener(this,tableModelTrain);
this.saleTickets1.saleTicketsRegister(processAl, staIndexList,lslList,
(TableModel) tableModelTrain);
this.clientGui.clientGuiRegister(processAl);
this.saleTickets1.setTrainjTableSelectedObject(1);//设置为零,情况就完全不同了
//this.refreshTableTrainChange();
this.getArrStation();
}
//**********************************************************************
// 测试用的
/*public static void main(String[] args)throws Exception {
Model model = new ModelNetImpl();
View view = new ViewImpl(model);
Controller con = new ControllerImpl(model, view);
}*/
public void addControllerListener(Controller con) {
this.con = con;
}
public void refreshTableTrainChange() {
List list = null;
try {
list = this.model.getTrain();
tableModelTrain.setTrain(list);
saleTickets1.setContent(list);
} catch (Exception e) {
e.printStackTrace();
}
}
public void getArrStation() {
List list = null;
Object []stationList=null;
try {
list = this.model.getStation();
stationList=list.toArray();
saleTickets1.setArrStation(stationList);
} catch (Exception e) {
e.printStackTrace();
}
}
/**************************************************************************
* 注册监听器
*/
transient ActionListener saleMenuItem = new ActionListener() {
public void actionPerformed(ActionEvent e) {
saleTickets1.setVisible(true);
clientGui.setVisible(false);
}
};
//*****************************************************************************
// 查询按钮监听器
transient ActionListener searchjButton = new ActionListener() {
public void actionPerformed(ActionEvent e) {
trainList = new ArrayList();
String trainID=saleTickets1.getTrainID();
trainList=con.processQueryTrainWiID(trainID);
tableModelTrain.setTrain(trainList);
saleTickets1.setContent(trainList);
}
};
transient ListSelectionListener trainJTableList = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int index = saleTickets1.getTrainjTableSelectedObject();
if (index < 0) {
return;
}
try {
Object obj = trainList.get(index);
System.out.println("列车车次为:"+index);
if (obj instanceof Train) {
Train train = (Train) obj;
saleTickets1.setTrainID(train.getTrainID());
saleTickets1.setFromSta(train.getFromSta());
saleTickets1.setEndSta(train.getEndSta());
}
} catch (Exception excp) {
}
}
};
//**************************************************************************
// 当用户输入车站首字母时,该控件响应输入事件,自动将符合条件的车站列出
transient KeyListener arrStajComBoxListener = new KeyListener() {
public void keyReleased(KeyEvent e){
List stationList = new ArrayList();
//String staIndex=saleTickets1.getArrStaIndex();
char staIndex=saleTickets1.getArrStaIndex();
saleTickets1.getSelectStation(staIndex);
System.out.print(staIndex);
}
public void keyTyped(KeyEvent e){
}
public void keyPressed(KeyEvent e){
}
};
//*************************************************************************
// 为界面中的控件注册合适的监听器
transient ActionListener processAl[]={searchjButton,saleMenuItem};
transient KeyListener staIndexList[] = {arrStajComBoxListener};
transient ListSelectionListener lslList[] = {trainJTableList};
transient ActionListener guiAl[] = {saleMenuItem}; //菜单点击监听
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -