java1996 2016-09-01 14:09 采纳率: 0%
浏览 1219

怎么在jdbc里添加背景图片,怎么把两个代码和起来

  1. package edu.jmi.xyh.view;

import java.awt.*;

public class LoginView_3 extends JFrame {
//创建一个容器
Container ct;
//创建背景面板。
BackgroundPanel bgp;
public static void main(String[] args)
{
new LoginView_3();
}
public LoginView_3()
{
//不采用任何布局方式。
ct=this.getContentPane();
getContentPane().setLayout(null);

        //在这里随便找一张400*300的照片既可以看到测试结果。
        bgp=new BackgroundPanel((new ImageIcon("C:\\Users\\asus123\\Desktop\\images\\2.jpg")).getImage());
        bgp.setBounds(0,0,400,300);
        ct.add(bgp);
        bgp.setLayout(null);

        this.setSize(400,300);
        this.setLocation(400,300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
}
class BackgroundPanel extends JPanel
{
    Image im;
    public BackgroundPanel(Image im)
    {
        this.im=im;
        this.setOpaque(true);
    }
    //Draw the back ground.
    public void paintComponent(Graphics g)
    {
        super.paintComponents(g);
        g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);

    }

}
2. package edu.jmi.xyh.view;

import java.awt.BorderLayout;

public class LoginView extends JFrame {
private JPanel contentPane;
private JTextField txID;
private JPasswordField txPw;
protected int loginCount;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                LoginView frame = new LoginView();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public LoginView() {
    setTitle("\u6B22\u8FCE\u767B\u5F55\u5B66\u751F\u7BA1\u7406\u7CFB\u7EDF");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 445, 306);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setForeground(Color.BLACK);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
    lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 12));
    lblNewLabel.setBounds(114, 98, 54, 15);
    contentPane.add(lblNewLabel);

    JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801\uFF1A");
    lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 12));
    lblNewLabel_1.setBounds(114, 135, 54, 15);
    contentPane.add(lblNewLabel_1);

    txID = new JTextField();
    txID.setBounds(204, 95, 118, 21);
    contentPane.add(txID);
    txID.setColumns(10);

    txPw = new JPasswordField();
    txPw.setBounds(204, 132, 118, 21);
    contentPane.add(txPw);

    JButton btnNewButton = new JButton("\u767B\u5F55");
    btnNewButton.setFont(new Font("宋体", Font.PLAIN, 12));
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //登陆代码,将用户输入的内容打印在控制台中
            String id=txID.getText();
            String pw=txPw.getText();
            //调用studentDao查询是否有该学生信息
            Student student=StudentDao.query(id);
            loginCount++;
            if(student==null || !pw.equals(student.getStuPwd())){
                if(loginCount<4)
                    JOptionPane.showMessageDialog(null, "您的用户名或者密码输入错误");
                else{
                    JOptionPane.showMessageDialog(null, "您以输错三次退出登录");
                    System.exit(0);
                }
            }
            else 
            {
                    LoginView.this.dispose();
                    MainView mv=new MainView();
                    mv.initView();
                    mv.setVisible(true);
                    //JOptionPane.showMessageDialog(null, "您的用户名或者密码输入正确!");
                }
            System.out.println("id="+id+"pw="+pw);
            }

    });
    btnNewButton.setBounds(75, 198, 93, 23);
    contentPane.add(btnNewButton);

    JButton btnNewButton_1 = new JButton("\u53D6\u6D88");
    btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 12));
    btnNewButton_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //单击事件
            System.exit(0);
        }
    });
    btnNewButton_1.setBounds(260, 198, 93, 23);
    contentPane.add(btnNewButton_1);

    JLabel label = new JLabel("\u6B22 \u8FCE \u767B \u5F55 \u5B66 \u751F");
    label.setFont(new Font("宋体", Font.PLAIN, 17));
    label.setBounds(131, 21, 186, 23);
    contentPane.add(label);

    JLabel label_1 = new JLabel("\u7BA1 \u7406 \u7CFB \u7EDF");
    label_1.setFont(new Font("宋体", Font.PLAIN, 17));
    label_1.setBounds(156, 54, 130, 23);
    contentPane.add(label_1);

    JLabel lblAdmin = new JLabel("\u5982\u679C\u60A8\u9996\u6B21\u767B\u9646\u7528\u6237\u540D\u4E3A  admin  \u5BC6\u7801\u4E3A\u7A7A\uFF01");
    lblAdmin.setForeground(Color.RED);
    lblAdmin.setBounds(86, 173, 267, 15);
    contentPane.add(lblAdmin);

}

protected Student StudentDao(String id) {
    // TODO Auto-generated method stub
    return null;
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-09-01 14:12
    关注

    把第一个代码贴在第二个里面比较简单,而且没有看到你用jsbc

    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛