XiongBaDaoFengXueL 2016-12-06 17:12 采纳率: 0%
浏览 1291
已结题

有个想不通的问题,请大神帮我一下~java返回值的问题

http://tieba.baidu.com/p/4889944890
整体代码如下:
父类是这个样子的
package login;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRootPane;
import javax.swing.JTextField;

public class loginFrame
{ Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screensize.getWidth();
int height = (int)screensize.getHeight();
JFrame loginin1 = new JFrame(); //窗体框架
JPanel login1 = new JPanel();
//窗体主面板
public JTextField user = new JTextField();
public JPasswordField password = new JPasswordField();

protected String user1 ="空值";
protected String password1="空值";
protected String verifycode1="空值";
protected String character1="空值";

JLabel l1 = new JLabel("账号");
JLabel l2 = new JLabel("密码");
JLabel l3 = new JLabel("权限");
JLabel l4 = new JLabel("验证");
public String code2;
public JComboBox cb1 = new JComboBox();
public JTextField verify = new JTextField();
ImageIcon bg = new ImageIcon("src\\image\\loginbj.jpg");
ImageIcon bg1 = new ImageIcon("src\\image\\robot.jpg");
ImageIcon bg2 = new ImageIcon("src\\image\\dian.jpg");
JLabel background = new JLabel(bg);//底色背景图片
JLabel background1 = new JLabel(bg1);//机器人背景图片
JLabel background2 = new JLabel(bg2);//让密码明文显示的图片
public JTextField passwordclear = new JTextField();
JButton bt1 =new JButton("登录");

protected void cleartextpre()   //这个是鼠标按压后显示明文的方法
{
    Point mousepoint = MouseInfo.getPointerInfo().getLocation();
    if(mousepoint.x>=1163&&mousepoint.x<=1174&&mousepoint.y>=420
            &&mousepoint.y<=430)
    {
        System.out.println("成功点击密码明文显示!");
        char[] passwordclearword = password.getPassword();
        String clearword = new String(passwordclearword);
        password.setVisible(false);
        passwordclear.setVisible(true);
        passwordclear.setText(clearword);
        passwordclear.setBounds(335, 99, 110, 25);
        login1.add(passwordclear);
        loginin1.repaint();
        loginin1.setVisible(true);
    };

}

protected void cleartext()  //鼠标松开后还原密文
{
        passwordclear.setVisible(false);
        password.setVisible(true);
        loginin1.repaint();
        loginin1.setVisible(true);
}

public loginFrame() 
{
    // TODO Auto-generated method stub
    VerifyCodeUtils code1 = new VerifyCodeUtils();

    JLabel pic = null;
    try 
    {
        code2 = code1.run1();
        //验证码的String
        pic= new JLabel(new ImageIcon("src\\verifycode\\"+code2+".jpg"));
        pic.setBounds(455, 180, 110, 60);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.print("加载验证码出错");
    }//验证码的生成,四位验证码
    ImageIcon icon = new ImageIcon("src\\image\\loginbutton.jpg");
    bt1.setIcon(icon);
    bt1.setBounds(335, 240, 110, 27);
    login1.add(bt1);
    bt1.addActionListener(al1);
    background.setBounds(0,-25,600,300);
    loginin1.getLayeredPane().add(background,new Integer(Integer.MIN_VALUE));
    //最上层面板透明
    JPanel jp=(JPanel)loginin1.getContentPane(); 
    jp.setOpaque(false);
    //设置透明
    background1.setBounds(30,30,200,200);
    login1.add(background1);
    login1.add(pic);
    login1.setSize(600, 300);
    login1.setLocation(0,0);
    login1.setOpaque(false);
    login1.setLayout(null);
    loginin1.add(login1);
    l1.setBounds(270, 40, 200, 50);
    l1.setFont(new Font("楷体",Font.BOLD, 20));
    l2.setBounds(270, 90, 200, 50);
    l2.setFont(new Font("楷体",Font.BOLD, 20));
    l3.setBounds(270, 140, 200, 50);
    l3.setFont(new Font("楷体",Font.BOLD, 20));
    l4.setBounds(270, 190, 200, 50);
    l4.setFont(new Font("楷体",Font.BOLD, 20));
    user.setBounds(335, 49, 110, 25);
    user.setBackground(new Color(204,249,236));
    user.setForeground(Color.RED);
    password.setBounds(335, 99, 110, 25);
    password.setBackground(new Color(204,249,236));
    verify.setBounds(335, 199, 110, 25);
    verify.setBackground(new Color(204,249,236));

    background2.setBounds(450, 105, 10, 10);//让密码明文显示的小点

    background2.addMouseListener(m1);
    cb1.addItem("管理员");
    cb1.setSelectedItem("管理员");
    cb1.setBounds(335, 149, 110, 25);
    login1.add(verify);
    login1.add(l4);
    login1.add(background2);
    login1.add(cb1);
    login1.add(user);
    login1.add(password);
    login1.add(l3);
    login1.add(l1);
    login1.add(l2);
    loginin1.setBounds(width/2-250,height/2-250,600,300);
    loginin1.setTitle("无人仓储系统登录");
    loginin1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    loginin1.setResizable(false);
    loginin1.setIconImage((new ImageIcon("src\\image\\warehouse.png").getImage()));


    loginin1.setVisible(true);
}


MouseListener m1 = new MouseListener(){

    @Override
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub
        cleartextpre();
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub
        cleartext();
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }};


    ActionListener al1 = new ActionListener()
    {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub

            user1=user.getText();
            character1=cb1.getSelectedItem().toString();
            password1=new String(password.getPassword());
            verifycode1 = verify.getText();
            loginproof lp = new loginproof();
            lp.runloginproof();
            loginin1.setVisible(false);

        }

    };



    public String getcharacter()
    {   
        return character1;

    }

    public String getUser()
    {   
        if(user.getText()==null&&user.getText()==""&&
                user.getText().length()==0
                &&user1.equals("空值")&&user==null)
        {return "bingo 终于出错了";}
        else
        {
        return user1=user.getText();
        }

    }

    public String getPassword()
    {
        return password1;
    }

    public String getVerifycode()
    {
        return verifycode1;
    }

}

子类是这个样子的
package login;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.plaf.ProgressBarUI;

import common.sqlconnext;
public class loginproof extends loginFrame {
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screensize.getWidth();
int height = (int)screensize.getHeight();
int progressint = 0;
JFrame f = new JFrame();
JPanel p = new JPanel();
ImageIcon bg = new ImageIcon("src\image\logincheck.jpg");
ImageIcon bg1 = new ImageIcon("src\image\loading.gif");
JLabel background = new JLabel(bg); //加载背景
JLabel background1 = new JLabel(bg1); //加载旋转轮
JLabel information = new JLabel("欢迎使用,请稍候......");
JLabel errorinformation = new JLabel("加载中,进度0%",JLabel.CENTER);
JProgressBar progressbar = new JProgressBar();
//加载过程中的进度条
public void progressbar()
{
progressbar.setOrientation(JProgressBar.HORIZONTAL);
progressbar.setMinimum(0);
progressbar.setMaximum(100);
progressbar.setValue(progressint);
progressbar.setBounds(0,275,600,25);
progressbar.setStringPainted(true);
p.add(progressbar);
}//添加进度条
public void addprogress()
{

System.out.println(super.getUser()); //显示获得到的父类的用户名
String us = super.getUser();
System.out.println(super.getPassword()); //显示获得到的父类的密码
String ps = super.getPassword();
System.out.println(super.getVerifycode()); //显示获得到的父类的验证码
String vc = super.getVerifycode();
System.out.println(super.getcharacter()); //显示获得到的父类的群组
String ca = super.getcharacter();
sqlconnext a = new sqlconnext();
int code = 0;
boolean a1 =a.GetAdminUser(us,ps,ca);
if(a1==true)
{progressbar.setValue(progressint=progressint+10);
errorinformation.setText("账户密码用户组验证成功,当前进度"+progressint+"%");
System.out.println("账户密码用户组验证成功");
}
else
{System.out.println("账户密码用户组没验证成功");
code =1;

    };
    if(vc.equalsIgnoreCase(code2))
    {
        progressbar.setValue(progressint=progressint+10);
        errorinformation.setText("验证码验证成功,当前进度"+progressint+"%");
        System.out.println("验证码验证成功");
    }else
    {System.out.println("验证码没验证成功");
    code =2;
    };
    if(code ==1)
    {errorinformation.setText("账户密码验证用户组未成功,请重新输入账户密码,按ESC退出");}
    else if(code ==2)
    {errorinformation.setText("验证码验证未成功,请重新输入验证码,按ESC退出");}
}//进度条进度添加


public void runloginproof() {
    // TODO Auto-generated method stub

    progressbar();
    addprogress();
    f.setLayout(null);
    p.setLayout(null);
    f.setUndecorated(true);
    f.setBounds(width/2-250,height/2-250,600,300);
    p.setBounds(0,0,600,300);
    f.getLayeredPane().add(background,new Integer(Integer.MIN_VALUE));
    f.getLayeredPane().add(background1,new Integer(Integer.MIN_VALUE));
    //最上层面板透明
    JPanel jp=(JPanel)f.getContentPane(); 
    jp.setOpaque(false);
    errorinformation.setBounds(0,225,600,50);
    errorinformation.setFont(new Font("宋体",Font.BOLD, 14));
    information.setBounds(220,175,160,50);
    information.setFont(new Font("宋体",Font.BOLD, 14));
    background.setBounds(0,0,600,300);
    background1.setBounds(265,20,70,70);



    p.add(errorinformation);
    p.add(information);
    p.add(background1);
    p.add(background);
    f.add(p);
    f.setVisible(true);

}

}

  • 写回答

2条回答 默认 最新

  • threenewbee 2016-12-06 18:23
    关注

    loginproof lp = new loginproof();
    后面你访问的lp是一个和当前对象毫无关系的新的loginproof的对象实例,它的基类protected成员自然不是当前调用它的loginFrame对象实例的

    另外,你在基类中创建派生类的对象实例并调用,这本身就违背面向对象的基本常识,基类都知道派生类的存在了它还要人家继承它干嘛,它直接把派生类要做的做好就行了。你这种写程序的方式就好像打扑克牌你一上来把你的牌摊开来给大家看,那还打什么牌。

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题的应用
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办