抱歉,我在MVC Java GUI中遇到了麻烦。因为这对我来说非常新。 1.单击“运行”时,如何创建框架,将显示带有2个按钮的框架。 1个按钮是学校链接此框架
另一个按钮是教师链接教师框架
这是我的控制器
public class ControllerSchool implements ActionListener{
JFSchool viewSchool = new JFSchool();
SchoolDAO modelSchool = new SchoolDAO();
public ControllerSchool(JFSchool viewSchool, SchoolDAO modelSchool){
this.modelSchool = modelSchool;
this.viewSchool = viewSchool;
this.viewSchool.btnadd.addActionListener(this);
this.viewSchool.btndisplay.addActionListener(this);
}
public void InitializeSchool(){}
public void actionPerformed(ActionEvent e){
if(e.getSource() ==viewSchool.btnadd){
String scname = viewSchool.txtname.getText();
String scadd = viewSchool.txtadd.getText();
String scjobpos = viewSchool.txtjobpos.getText();
String scjobexp = viewSchool.txtjobexp.getText();
String rptaRegister = modelSchool.insertSchool(scname, scadd, scjobpos, scjobexp);
if(rptaRegister!=null){
JOptionPane.showMessageDialog(null, rptaRegister);
}else{
JOptionPane.showMessageDialog(null, "Add Error");}}
if (e.getSource()==viewSchool.btndisplay){
LLenarTabla(viewSchool.tbdata);
JOptionPane.showMessageDialog(null, "Display records");
} }}
这是我的MVC代码
public class SchoolMVC {
public static void main(String[] args) {
JFSchool viewC = new JFSchool();
SchoolDAO modelC = new SchoolDAO();
ControllerSchool controlC = new ControllerSchool(viewC, modelC);
viewC.setVisible(true);
viewC.setLocationRelativeTo(null);
}}
对于长篇文章感到抱歉,但我真的不知道什么是最好的解决方案。先谢谢!