首页 新闻 会员 周边 捐助

Java JFrame 背景设置

0
悬赏园豆:10 [已关闭问题] 关闭于 2016-05-10 10:20

问题1:如何设置背景,百度了也尝试,没有成功

问题2:这是我做的数据库课程设计的界面(一部分),注册根据人的身份不同  分为借书者和管理者(如下图)

但是我想当点击借书者注册时,出现这个界面

当点击管理员注册时,出现这样的界面

单个身份的注册我会,不过重叠的做不来,

该如何做,请大神帮忙

我把自己写的代码  传上,可修改,注明修改的地方,谢谢!!!!

package LibrarySystem;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

public class LSLogin extends JFrame {
    public static void main(String[] args) {
        new LSLogin();

    }

    public LSLogin() {
        setTitle("图书馆管理系统");
        Container con = getContentPane();
        setLayout(null);
        /*------------标题奥设置--------------------*/
        JLabel jl1 = new JLabel("图书馆管理系统");
        jl1.setBounds(450, 40, 110, 30);
        // jl1.setSize(100, 30);
        jl1.setBackground(Color.DARK_GRAY);
        con.add(jl1);
        /*-----------账号设置--------------*/
        JPanel jp2 = new JPanel();
        jp2.setLayout(new FlowLayout());
        JLabel jl2 = new JLabel("账号");
        JTextField jtf2 = new JTextField(14);
        jp2.add(jl2);
        jp2.add(jtf2);
        jp2.setBounds(150, 110, 270, 40);
        con.add(jp2);
        /*--------------密码设置----------------*/
        JPanel jp3 = new JPanel();
        jp3.setLayout(new FlowLayout());
        JLabel jl3 = new JLabel("密码");
        JPasswordField jpf3 = new JPasswordField(14);
        jpf3.setEchoChar('*');
        jp3.add(jl3);
        jp3.add(jpf3);
        jp3.setBounds(150, 150, 270, 40);
        con.add(jp3);
        /*----------------用户身份----------------------*/
        JPanel jp4 = new JPanel();
        ButtonGroup bg4 = new ButtonGroup();

        jp4.setLayout(new GridLayout(1, 3, 5, 0));
        String identity[] = new String[] { "管理员", "教师", "学生" };
        for (int i = 0; i < identity.length; i++) {
            // JCheckBox jcb4 = new JCheckBox(identity[i]);
            JRadioButton rb4 = new JRadioButton(identity[i]);
            bg4.add(rb4);
            jp4.add(rb4);
        }
        jp4.setBounds(200, 220, 220, 40);
        con.add(jp4);
        /*-----------------两个button 登陆 注册设置---------*/
        JPanel jp5 = new JPanel();
        JButton jb5a = new JButton("登陆");
        JButton jb5b = new JButton("注册");
        jp5.add(jb5a);
        jp5.add(jb5b);
        jp5.setBounds(140, 290, 300, 40);
        con.add(jp5);
        /**
         * 为注册设置监听事件
         */
        jb5b.addActionListener(new ActionListener() {

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

                new Register().RDemo("注册界面");

            }
        });

        /*-----------------窗体界面设置---------------*/
        setVisible(true);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(400, 0, 600, 400);
        setBackground(Color.cyan);
        addWindowListener(new WindowAdapter() {
            public void WindowClosing(WindowEvent e) {
                // this.dispose();
            }
        });

    }

}

class Register extends JFrame {
    String Sinfer[] = new String[] { "姓名", "密码", "年龄", "性别", "联系方式", "所在学院" };
    String Minfer[] = new String[] { "姓名", "密码", "年龄", "性别", "联系方式", "家庭住址" };
    private JLabel jl1;
    private JLabel jl2;
    private JTextField jtf;
    private JTextField jtf2;
    private JPanel jp = new JPanel(new GridLayout(Sinfer.length, 2, 0, 5));//学生注册界面小窗体设置
    private JPanel jp2 = new JPanel(new GridLayout(Minfer.length, 2, 0, 5));//管理员注册界面小窗体设置
    private JButton jb;

    public void RDemo(String title) {
        setTitle(title);
        final Container con = getContentPane();
        setLayout(null);
        /*------------身份种类---------------*/
        JPanel jp1 = new JPanel();
        jp1.setLayout(new FlowLayout());
        JButton jb1a = new JButton("借书者注册");
        JButton jb1b = new JButton("管理员注册");
        jp1.add(jb1a);
        jp1.add(jb1b);
        jp1.setBounds(25, 10, 300, 35);
        con.add(jp1);

        /*-----------------学生注册信息设置-----------*/
         jb1a.addActionListener(new ActionListener() {
        
         @Override
         public void actionPerformed(ActionEvent arg0) {
         // TODO Auto-generated method stub
         for (int i = 0; i < Sinfer.length; i++) {
         jl1 = new JLabel(Sinfer[i]);
         jtf = new JTextField(16);
         jp.add(jl1);
         jp.add(jtf);
        
         }
         jp.setBounds(55, 60, 240, 250);
         con.add(jp);
        
         }
         });
        /*--------------管理员注册信息设置-----------------*/
        jb1b.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                for (int i = 0; i < Minfer.length; i++) {
                    jl2 = new JLabel(Minfer[i]);
                    jtf2 = new JTextField(16);
                    jp2.add(jl2);
                    jp2.add(jtf2);

                }
                jp2.setBounds(55, 60, 240, 250);
                con.add(jp2);

            }

        });

        /*---------确定button------------*/
        jb = new JButton("确定");
        jb.setBounds(135, 320, 80, 30);
        con.add(jb);
        /* 为确定按钮添加监听事件 */
        jb.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                JOptionPane.showMessageDialog(null, "保存完成");

            }
        });
        /*-------------窗体设置*/
        setVisible(true);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                // this.dispose();// 释放当前窗口资源,并且设置为不可见 } });
            }
        });
        setBounds(800, 100, 350, 450);

    }

}

 

 

 

 

搬砖工奶爸的主页 搬砖工奶爸 | 初学一级 | 园豆:184
提问于:2014-05-13 22:28
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册