LaoGGa 2021-12-14 10:08 采纳率: 100%
浏览 35
已结题

Java中两类的跳转问题

登录界面登录进去,不知道如何跳转界面。跟着网上的各种解决方法,都无法解决。先用了new GoodsInformationManageN();但是销毁这个界面后什么都没出现就结束了。
第一个界面监听:

package HuoWuGuanLiXiTong.JieMian;


import HuoWuGuanLiXiTong.Dao.*;
import HuoWuGuanLiXiTong.JDBC.JDBCUtils;
import HuoWuGuanLiXiTong.JDBC.RootjdbcUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

public class Login {
    static JFrame flogin = new JFrame("货物管理系统");
    static JLabel l = new JLabel("货物管理系统", JLabel.CENTER);
    static JButton blogin = new JButton("普通用户登录");
    static JButton brootlogin = new JButton("管理员登录");
    static JButton bexit = new JButton("退出系统");
    static JLabel lusername = new JLabel("用户名:");
    static JLabel lpassword = new JLabel("密    码:");
    static TextField username = new TextField();
    static TextField password = new TextField();
    static Font font = new Font("Serief", Font.BOLD, 40);
    static JDBCUtils jdbcUtils = new JDBCUtils();
    static UserDao userDao = new UserDao();
    static RootjdbcUtils rootjdbcUtils = new RootjdbcUtils();
    static RootuserDao rootuserDao = new RootuserDao();



    public static void main(String[] args) {
        flogin.setVisible(true);
        flogin.setLocationRelativeTo(null);
        flogin.setSize(550, 430);
        flogin.setLayout(null);
        l.setFont(font);
        flogin.add(l);
        flogin.add(username);
        flogin.add(password);
        flogin.add(blogin);
        flogin.add(brootlogin);
        flogin.add(bexit);
        flogin.add(lusername);
        flogin.add(lpassword);

        l.setBounds(120, 50, 300, 38);
        lusername.setBounds(50,120,70,30);
        lpassword.setBounds(50,170,70,30);
        username.setBounds(135, 120, 260, 30);
        password.setBounds(135, 170, 260, 30);
        blogin.setBounds(160, 220, 218, 40);
        brootlogin.setBounds(160, 270, 218, 40);
        bexit.setBounds(160, 320, 218, 40);

        bexit.addActionListener(new ButtonExitHandler());

        blogin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String Username = Login.username.getText();
                String Password = Login.password.getText();
                if (StringUtil.isEmpth(Username)) {
                    JOptionPane.showMessageDialog(null, "用户名不能为空");
                    return;
                }
                if (StringUtil.isEmpth(Password)) {
                    JOptionPane.showMessageDialog(null, "密码不能为空");
                    return;
                }
                User user = new User(Username,Password);
                Connection con = null;
                try {
                    con=jdbcUtils.getCon();
                    User currentUser = userDao.login(con, user);
                    if (currentUser!=null){
                        JOptionPane.showMessageDialog(null,"登录成功");
                        flogin.dispose();
                        new GoodsInformationManageN();
                    }else {
                        JOptionPane.showMessageDialog(null,"用户名或者密码错误");
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        brootlogin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String RootUsername = Login.username.getText();
                String RootPassword = Login.password.getText();
                if (StringUtil.isEmpth(RootUsername)) {
                    JOptionPane.showMessageDialog(null, "用户名不能为空");
                    return;
                }
                if (StringUtil.isEmpth(RootPassword)) {
                    JOptionPane.showMessageDialog(null, "密码不能为空");
                    return;
                }
                Rootuser rootuser = new Rootuser(RootUsername,RootPassword);
                Connection con = null;
                try {
                    con=rootjdbcUtils.getCon();
                    Rootuser currentrootUser = rootuserDao.login(con,rootuser);
                    if (currentrootUser!=null){
                        JOptionPane.showMessageDialog(null,"登录成功");
                        flogin.dispose();
                        new GoodsInformationManageR();
                    }else {
                        JOptionPane.showMessageDialog(null,"用户名或者密码错误");
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });

    }

}

class ButtonExitHandler implements ActionListener{
    public void actionPerformed(ActionEvent e) {
        System.exit(0);
    }
}

第二个界面:

package HuoWuGuanLiXiTong.JieMian;

import HuoWuGuanLiXiTong.JieMian.ButtonExitHandler;

import javax.swing.*;


public class GoodsInformationManageN {
    private static final JFrame fmanage = new JFrame("货物信息管理界面");
    static JButton bquery = new JButton("查询货物");
    static JButton badd = new JButton("增加货物");
    static JButton bdelete = new JButton("删除货物");
    static JButton bexit = new JButton("退出系统");


    public static void main(String[] args) {
        fmanage.setVisible(true);
        fmanage.setLocationRelativeTo(null);
        fmanage.setSize(550,430);
        fmanage.setLayout(null);
        fmanage.add(bquery);
        fmanage.add(badd);
        fmanage.add(bdelete);
        fmanage.add(bexit);

        bquery.setBounds(160,80,218,40);
        badd.setBounds(160,130,218,40);
        bdelete.setBounds(160,180,218,40);
        bexit.setBounds(160,280,218,40);

        bexit.addActionListener(new ButtonExitHandler());
    }
}


运行后的图:

img


另一种方法报错

img

  • 写回答

1条回答 默认 最新

  • 关注

    new GoodsInformationManageN();这个类必须是实现了JFrame类的类。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月22日
  • 已采纳回答 12月14日
  • 创建了问题 12月14日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来