java 按钮字体_java 设置窗口背景图片还有设置按钮的字体格式例如大小等等··...

importjava.awt.event.WindowAdapter;importjava.awt.event.ActionListener;importjava.awt.event.WindowEvent;importjava.awt.event.ActionEvent;importjava.awt.Color;importjava.a...

import java.awt.event.WindowAdapter ;

import java.awt.event.ActionListener ;

import java.awt.event.WindowEvent ;

import java.awt.event.ActionEvent ;

import java.awt.Color ;

import java.awt.Font ;

import javax.swing.JFrame ;

import javax.swing.JButton ;

import javax.swing.JLabel ;

import javax.swing.JTextField ;

import javax.swing.JPasswordField ;

class LoginCheck{

private String name ;

private String password ;

public LoginCheck(String name,String password){

this.name = name ;

this.password = password ;

}

public boolean validate(){

if("mwb".equals(name)&&"mwb".equals(password)){

return true ;

}else{

return false ;

}

}

};

class ActionHandle{

private JFrame frame = new JFrame("Logion") ;

private JButton submit = new JButton("登陆");

private JButton reset = new JButton("重置");

private JLabel nameLab = new JLabel("用户名:") ;

private JLabel passLab = new JLabel("密 码:") ;

private JLabel infoLab = new JLabel("登陆系统") ;

private JTextField nameText = new JTextField(10) ;

private JPasswordField passText = new JPasswordField();

public ActionHandle(){

Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,12) ;

infoLab.setFont(fnt) ;// 设置标签的显示文字

submit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

if(e.getSource()==submit){

String tname = nameText.getText() ;

String tpass = new String(passText.getPassword()) ;

LoginCheck log = new LoginCheck(tname,tpass) ;

if(log.validate()){

infoLab.setText("登陆成功,欢迎光临!") ;

}else{

infoLab.setText("登陆失败,错误的用户名或密码!") ;

}

}

}

}) ;

reset.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

if(e.getSource()==reset){

nameText.setText("") ;

passText.setText("") ;

infoLab.setText("用户登陆系统") ;

}

}

}) ;

frame.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System.exit(1) ;

}

}) ;// 加入事件

frame.setLayout(null) ;

nameLab.setBounds(650,300,60,20) ;

passLab.setBounds(650,325,60,20) ;

infoLab.setBounds(650,360,220,30) ;

nameText.setBounds(710,300,100,20) ;

passText.setBounds(710,325,100,20) ;

submit.setBounds(810,300,60,20) ;

reset.setBounds(810,325,60,20) ;

frame.add(nameLab) ;

frame.add(passLab) ;

frame.add(infoLab) ;

frame.add(nameText) ;

frame.add(passText) ;

frame.add(submit) ;

frame.add(reset) ;

frame.setSize(280,130) ;

frame.setBackground(Color.WHITE) ;

frame.setSize(1000,500);

frame.setLocation(200,150) ;

frame.setVisible(true) ;

}

}

public class Login{

public static void main(String args[]){

new ActionHandle() ;

}

}

展开

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值