jav control
package org.hvbk.test.control;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import org.hvbk.test.bean.Hocsinh;
import org.hvbk.test.bean.Khoavien;
import org.hvbk.test.model.HocsinhModel;
import org.hvbk.test.model.HocsinhModel.KhoavienModel;
import org.hvbk.test.view.HocsinhView;
public class HocsinhControl {
private HocsinhView view = null;
private HocsinhModel model = null;
private HocsinhModel.DSHocsinhModel dshsModel = null;
private List<Hocsinh> hocsinhList = new Vector<Hocsinh>();
private List<Khoavien> khoavienList = new Vector<Khoavien>();
private KhoavienModel khoavienModel = null;
private JInternalFrame frame = new JInternalFrame();
public HocsinhControl(JDesktopPane pane) {
view = new HocsinhView();
model = new HocsinhModel();
dshsModel = model.new DSHocsinhModel();
khoavienModel = model.new KhoavienModel();
dshsModel.setHocsinhList(hocsinhList);
khoavienList.add(new Khoavien("KHT", "Khoa toan", ""));
khoavienList.add(new Khoavien("KHTI", "Khoa CNTT", ""));
khoavienModel.setKhoavienList(khoavienList);
view.setModel(dshsModel);
view.setComboModel(khoavienModel);
frame.setSize(800, 600);
frame.setVisible(true);
frame.add(view);
pane.add(frame);
initAction();
}
private void initAction() {
doThoat();
doThem();
doGhi();
doXoa();
}
private void doThoat() {
view.doThoat(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
frame.dispose();
}
});
}
private void doThem() {
view.doThem(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
view.xoaDuLieu();
}
});
}
private void doGhi() {
view.doGhi(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Hocsinh item = view.getHocsinhInfo();
dshsModel.addHocsinh(item);
hocsinhList = dshsModel.getHocsinhList();
}
});
}
private void doXoa() {
view.doXoa(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int i = view.getSelectedRow();
if (i >= 0) {
dshsModel.removeHocsinh(i);
hocsinhList = dshsModel.getHocsinhList();
}
}
});
}
}
---------------------------------------------------------------------------------------------------------------------------------
package org.hvbk.test.control;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import org.hvbk.test.view.Mainview;
public class Maincontrol {
private Mainview view = new Mainview();
private JDesktopPane pane = new JDesktopPane();
public Maincontrol() {
// TODO Auto-generated constructor stub
view.setContentPane(pane);
doAction();
}
private void doAction() {
// TODO Auto-generated method stub
doNew();
}
private void doNew() {
// TODO Auto-generated method stub
view.doNew(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new HocsinhControl(pane);
}
});
}
public static void main(String[] args) {
new Maincontrol();
}
}
Bạn đang đọc truyện trên: Truyen247.Pro