java中setBorder和setFocusable是什么意思

 我来答
bzhuorui
推荐于2018-04-30 · 超过14用户采纳过TA的回答
知道答主
回答量:52
采纳率:100%
帮助的人:21万
展开全部
这两个方法是swing组件的方法,setBorder设置组件的边框,如大小、是否透明、其他特殊效果。setFocusable设置组件是否可被选中,如文本框不允许复制内容,则setFocusable(false),不能被选中,就不可以复制。
setBorder(Border border) 设置组件的边框,Border 对象负责定义组件的 insets(直接对组件重写所有 insets 设置),并且可选地呈现这些 insets
范围内的边框装饰。要为 swing 组件创建有装饰的和无装饰的区域(例如边距和填充),应该使用边框(而不是
insets)。在单个组件中可使用复合边框来嵌套多个边框。
setFocusable(boolean focusable) 表明此 Component 是否可以获得焦点。
jvutdv
2010-12-08 · TA获得超过836个赞
知道小有建树答主
回答量:829
采纳率:0%
帮助的人:772万
展开全部
/*
*以下是我曾经做项目时候做的登录,是从数据库提取登录名和密码的.具有广泛意义;如按楼主自己定义密码等,就更容易了。
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;

/**
* <p>Title: 企业绩效管理系统</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company: </p>
*
* @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);
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式