实验五-图形用户界面的设计与实现

上传人:繁星 文档编号:42809752 上传时间:2018-06-03 格式:DOC 页数:15 大小:239.50KB
返回 下载 相关 举报
实验五-图形用户界面的设计与实现_第1页
第1页 / 共15页
实验五-图形用户界面的设计与实现_第2页
第2页 / 共15页
实验五-图形用户界面的设计与实现_第3页
第3页 / 共15页
实验五-图形用户界面的设计与实现_第4页
第4页 / 共15页
实验五-图形用户界面的设计与实现_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《实验五-图形用户界面的设计与实现》由会员分享,可在线阅读,更多相关《实验五-图形用户界面的设计与实现(15页珍藏版)》请在金锄头文库上搜索。

1、实实验验报报告告课程名称面向对象程序设计实验名称实验五 图形用户界面的设计与实现日期2017-11-9学生学号姓名班级B150404实验目的:通过本次实验,要求学生能进一步掌握图形用户界面的设计方法。实验条件:电脑一台、能上网查阅资料。1.完成图书管理系统登陆界面和主界面的设计, 完成图书管理系统的基本框架设计。 源源代代码码:数数据据库库连连接接代代码码 : public class DbUtil private String dbUrl=“jdbc:mysql:/localhost:3306/db_book“; / 数据库连接地址private String dbUserName=“roo

2、t“; / 用户名private String dbPassword=“123456“; / 密码private String jdbcName=“com.mysql.jdbc.Driver“; / 驱动名称/* 获取数据库连接* return* throws Exception*/public Connection getCon()throws ExceptionClass.forName(jdbcName);Connection con=DriverManager.getConnection(dbUrl, dbUserName, dbPassword);return con;/* 关闭数据

3、库连接* param con* throws Exception*/public void closeCon(Connection con)throws Exceptionif(con!=null)con.close();public static void main(String args) DbUtil dbUtil=new DbUtil();try dbUtil.getCon();System.out.println(“数据库连接成功!“); catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();

4、System.out.println(“数据库连接失败“); 用户实体/* 用户实体* author Administrator*/public class User private int id; / 编号private String userName; / 用户名private String password; / 密码public User() super();/ TODO Auto-generated constructor stubpublic User(String userName, String password) super();this.userName = userNam

5、e;this.password = password;public int getId() return id;public void setId(int id) this.id = id;public String getUserName() return userName;public void setUserName(String userName) this.userName = userName;public String getPassword() return password;public void setPassword(String password) this.passw

6、ord = password;/* 用户 Dao 类* author Administrator*/public class UserDao /* 登录验证* param con* param user* return* throws Exception*/public User login(Connection con,User user)throws ExceptionUser resultUser=null;String sql=“select * from t_user where userName=? and password=?“;PreparedStatement pstmt=c

7、on.prepareStatement(sql);pstmt.setString(1, user.getUserName();pstmt.setString(2, user.getPassword();ResultSet rs=pstmt.executeQuery();if(rs.next()resultUser=new User();resultUser.setId(rs.getInt(“id“);resultUser.setUserName(rs.getString(“userName“);resultUser.setPassword(rs.getString(“password“);re

8、turn resultUser;public class JavaInterFrm extends JInternalFrame /* Launch the application.*/public static void main(String args) EventQueue.invokeLater(new Runnable() public void run() try Java1234InterFrm frame = new Java1234InterFrm();frame.setVisible(true); catch (Exception e) e.printStackTrace(

9、););/* Create the frame.*/public Java1234InterFrm() getContentPane().setBackground(Color.RED);setIconifiable(true);setClosable(true);setTitle(“u5173u4E8EJava1234“);setBounds(100, 100, 450, 300);JLabel lblNewLabel = new JLabel(“);lblNewLabel.setIcon(new ImageIcon(Java1234InterFrm.class.getResource(“/

10、images/java1234.png“);GroupLayout groupLayout = new GroupLayout(getContentPane();groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGap(98).addComponent(lblNewLabel).addContainerGap(126, Short.MAX_VALUE);groupLayout.setVe

11、rticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGap(48).addComponent(lblNewLabel).addContainerGap(149, Short.MAX_VALUE);getContentPane().setLayout(groupLayout);登登录录界界面面的的代代码码: public class LogOnFrm extends JFrame private JPanel contentPa

12、ne;private JTextField userNameTxt;private JPasswordField passwordTxt;private DbUtil dbUtil=new DbUtil();private UserDao userDao=new UserDao();/* Launch the application.*/public static void main(String args) EventQueue.invokeLater(new Runnable() public void run() try LogOnFrm frame = new LogOnFrm();f

13、rame.setVisible(true); catch (Exception e) e.printStackTrace(););/* Create the frame.*/public LogOnFrm() /改变系统默认字体 Font font = new Font(“Dialog“, Font.PLAIN, 12);java.util.Enumeration keys = UIManager.getDefaults().keys();while (keys.hasMoreElements() Object key = keys.nextElement();Object value = U

14、IManager.get(key);if (value instanceof javax.swing.plaf.FontUIResource) UIManager.put(key, font);setResizable(false);setTitle(“u7BA1u7406u5458u767Bu5F55“);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 450, 343);contentPane = new JPanel();contentPane.setBorder(new EmptyBorder(5,

15、5, 5, 5);setContentPane(contentPane);JLabel lblNewLabel = new JLabel(“u56FEu4E66u7BA1u7406u7CFBu7EDF“);lblNewLabel.setFont(new Font(“宋体“, Font.BOLD, 23); lblNewLabel.setIcon(new ImageIcon(LogOnFrm.class.getResource(“/images/logo.png“);JLabel lblNewLabel_1 = new JLabel(“u7528u6237u540DuFF1A“);lblNewL

16、abel_1.setIcon(new ImageIcon(LogOnFrm.class.getResource(“/images/userName.png“);JLabel lblNewLabel_2 = new JLabel(“u5BC6 u7801uFF1A“);lblNewLabel_2.setIcon(new ImageIcon(LogOnFrm.class.getResource(“/images/password.png“);userNameTxt = new JTextField();userNameTxt.setColumns(10);passwordTxt = new JPasswordField();JButton btnNewButton = n

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 总结/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号