如何创建一个按钮来链接Java MVC中的2个帧

时间:2015-08-04 20:03:58

标签: java model-view-controller jframe

抱歉,我在MVC Java GUI中遇到了麻烦。因为这对我来说非常新。 1.单击“运行”时,如何创建框架,将显示带有2个按钮的框架。 1个按钮是学校链接此框架

This is School Frame

另一个按钮是教师链接教师框架

  1. 关于教师框架,我将在“视图包”中创建另一个离散表单,如JFTeacher,或者只在其他组件中创建TeacherFrame。像这样。 (JFrame =学校框架) enter image description here
  2. 这是我的控制器

     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);
    }}
    

    对于长篇文章感到抱歉,但我真的不知道什么是最好的解决方案。先谢谢!

0 个答案:

没有答案