java中setborder_java中setBorder和setFocusable是什么意思

展开全部

/*

*以下是我曾经做项目时候做的登录,是从数据库提取登e5a48de588b63231313335323631343130323136353331333262383538录名和密码的.具有广泛意义;如按楼主自己定义密码等,就更容易了。

p.s:因为时间忙,我就不另写程序了 希望对你有用。

*/

package com.youngmaster.view;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

import javax.swing.*;

import javax.swing.border.*;

import com.youngmaster.jdbc.*;

import java.awt.Dimension;

import java.awt.Rectangle;

import java.awt.Font;

import javax.swing.DebugGraphics;

import javax.swing.text.html.ImageView;

import javax.swing.BorderFactory;

import java.awt.Color;

/**

*

Title: 企业绩效管理系统

*

*

Description:

*

*

Copyright: Copyright (c) 2009

*

*

Company:

*

* @author youngmaster

* @version 1.0

*/

public class FrLogin extends JFrame {

JPanel contentPane;

JLabel jLabel1 = new JLabel();

JLabel jLabel2 = new JLabel();

JLabel jLabel3 = new JLabel();

JButton jButton1 = new JButton();

JButton jButton2 = new JButton();

JTextField txtName = new JTextField();

JLabel jLabel5 = new JLabel();

JPasswordField txtPsw = new JPasswordField();

TitledBorder titledBorder1 = new TitledBorder("");

JComboBox jComboBox1 = new JComboBox();

JPanel jPanel1 = new JPanel();

ImageIcon image = new ImageIcon("image/building.gif");

JButton btnImage = new JButton();

TitledBorder titledBorder2 = new TitledBorder("");

public FrLogin() {

try {

setDefaultCloseOperation(EXIT_ON_CLOSE);

jbInit();

} catch (Exception exception) {

exception.printStackTrace();

}

}

/**

* Component initialization.

*

* @throws java.lang.Exception

*/

private void jbInit() throws Exception {

contentPane = (JPanel) getContentPane();

contentPane.setLayout(null);

setSize(new Dimension(443, 327));

setTitle("Frame Title");

jLabel1.setFont(new java.awt.Font("楷体_GB2312", Font.BOLD, 20));

jLabel1.setText("企业绩效管理系统");

jLabel1.setBounds(new Rectangle(126, 28, 168, 24));

jLabel2.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 16));

jLabel2.setText("用户名:");

jLabel2.setBounds(new Rectangle(75, 124, 59, 24));

jLabel3.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 16));

jLabel3.setText("密 码:");

jLabel3.setBounds(new Rectangle(75, 173, 59, 24));

jButton1.setBounds(new Rectangle(99, 218, 80, 28));

jButton1.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 14));

jButton1.setText("登录");

jButton1.addActionListener(new FrLogin_jButton1_actionAdapter(this));

jButton2.setBounds(new Rectangle(221, 217, 83, 29));

jButton2.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 14));

jButton2.setText("取消");

jButton2.addActionListener(new FrLogin_jButton2_actionAdapter(this));

txtName.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 14));

txtName.setBounds(new Rectangle(146, 120, 102, 23));

txtName.addActionListener(new FrLogin_txtName_actionAdapter(this));

jLabel5.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 16));

jLabel5.setText("等 级:");

jLabel5.setBounds(new Rectangle(75, 74, 59, 24));

txtPsw.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 14));

txtPsw.setBounds(new Rectangle(146, 168, 102, 23));

txtPsw.addActionListener(new FrLogin_txtPsw_actionAdapter(this));

contentPane.setBorder(titledBorder1);

contentPane.setDebugGraphicsOptions(0);

contentPane.setNextFocusableComponent(jComboBox1);

contentPane.setToolTipText("企业绩效管理系统");

jPanel1.setNextFocusableComponent(jComboBox1);

jPanel1.setToolTipText("企业绩效管理系统");

jPanel1.setBounds(new Rectangle(1, 0, 441, 330));

jPanel1.setLayout(null);

jComboBox1.setFont(new java.awt.Font("楷体_GB2312", Font.PLAIN, 14));

jComboBox1.setBounds(new Rectangle(146, 72, 102, 23));

jComboBox1.addActionListener(new FrLogin_jComboBox1_actionAdapter(this));

btnImage.setBounds(new Rectangle(271, 55, 120, 160));

btnImage.setBorder(titledBorder2);

jPanel1.add(jLabel1);

jPanel1.add(jLabel5);

jPanel1.add(jLabel2);

jPanel1.add(jLabel3);

jPanel1.add(txtName);

jPanel1.add(jComboBox1);

jPanel1.add(txtPsw);

jPanel1.add(jButton2);

jPanel1.add(jButton1);

jPanel1.add(btnImage);

contentPane.add(jPanel1);

jComboBox1.addItem(1);

jComboBox1.addItem(2);

btnImage.setIcon(image);

this.setTitle("登录");

}

public void jButton2_actionPerformed(ActionEvent e) {

System.exit(0);

}

public void jButton1_actionPerformed(ActionEvent e) {

//栏位判断

if (txtName.getText().equals("") || txtPsw.getText().equals("")) {

javax.swing.JOptionPane.showMessageDialog(this, "登录信息错误!请重新输入。");

txtName.setText("");

txtPsw.setText("");

} else {

boolean success = false;

int grade;

String name = "";

String psw = "";

JdbcUtils dbc = JdbcUtils.getInstance();

ResultSet rs = dbc.executeQuery("SELECT * FROM user");

//查询帐号和密码是否匹配

try {

while (rs.next()) {

grade = rs.getInt("grade");

name = rs.getString("name");

psw = rs.getString("password");

if (txtName.getText().equals(name) &&

txtPsw.getText().equals(psw) &&

((jComboBox1.getSelectedIndex() + 1) == grade)) {

//当时出现问题地方

//Integer.parseInt(jComboBox1.getSelectedItem()

success = true;

break;

}

}

//若匹配则登陆成功并进入主界面

if (success) {

FrMain ufram = new FrMain();

this.setVisible(false);

Dimension screenSize = Toolkit.getDefaultToolkit().

getScreenSize();

Dimension frameSize = ufram.getSize();

if (frameSize.height > screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width > screenSize.width) {

frameSize.width = screenSize.width;

}

ufram.setLocation((screenSize.width - frameSize.width) /

2,

(screenSize.height - frameSize.height) /

2);

ufram.setVisible(true);

} else {

javax.swing.JOptionPane.showMessageDialog(this,

"管理员名或密码错误!请重新输入。");

txtName.setText("");

txtPsw.setText("");

txtName.setFocusable(true);

}

} catch (SQLException ex) {

javax.swing.JOptionPane.showMessageDialog(this,

ex.getMessage().toString());

return;

}

}

}

public void txtName_actionPerformed(ActionEvent e) {

}

public void jComboBox1_actionPerformed(ActionEvent e) {

}

public void txtPsw_actionPerformed(ActionEvent e) {

}

}

class FrLogin_txtPsw_actionAdapter implements ActionListener {

private FrLogin adaptee;

FrLogin_txtPsw_actionAdapter(FrLogin adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.txtPsw_actionPerformed(e);

}

}

class FrLogin_jComboBox1_actionAdapter implements ActionListener {

private FrLogin adaptee;

FrLogin_jComboBox1_actionAdapter(FrLogin adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jComboBox1_actionPerformed(e);

}

}

class FrLogin_txtName_actionAdapter implements ActionListener {

private FrLogin adaptee;

FrLogin_txtName_actionAdapter(FrLogin adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.txtName_actionPerformed(e);

}

}

class FrLogin_jButton1_actionAdapter implements ActionListener {

private FrLogin adaptee;

FrLogin_jButton1_actionAdapter(FrLogin adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton1_actionPerformed(e);

}

}

class FrLogin_jButton2_actionAdapter implements ActionListener {

private FrLogin adaptee;

FrLogin_jButton2_actionAdapter(FrLogin adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton2_actionPerformed(e);

}

}

本回答被网友采纳

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值