Java GUI创建一个登录界面(未含有事件响应)

package 数据库课程设计;

import javax.swing.*;
import java.awt.Font;  
import java.awt.*;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  

public class GUI界面 extends JFrame implements ActionListener {  

    //定义组件   
    JButton button1,button2,button3=null;   //登录,退出,重置 按钮
    JRadioButton radioButton1,radioButton2=null;//教师,学生 单选框  
    JPanel panel1,panel2,panel3,panel4=null; //声明面板 
    JLabel label1,label2,label3=null; //用户名,密码,权限 标签 
    JTextField textField=null;  //输入账号的文本框
    JPasswordField passwordField=null;  //输入密码的密码框  
    
    Font font =new Font("楷体", Font.PLAIN, 20);//定义字体

    public static void main(String[] args) {  
    	GUI界面 mUI=new GUI界面(); 
    	mUI.setLayout(new GridLayout(2,1));  //选择GridLayout布局管理器        
    	mUI.setTitle("毕业论文管理系统");        //框架标题       
    	mUI.setSize(400,475); 
    	mUI.setLocation(400, 200);           
        mUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    //设置当关闭窗口时,保证JVM也退出 
        mUI.setVisible(true);     //设置框架可见
        mUI.setResizable(true);  
        mUI.setResizable(false);       
    }  
    
    public GUI界面() {  
         //创建组件  
        button1=new JButton("退出");  
        button2=new JButton("帮助"); 
        button3=new JButton("登录");

        Color buttonColor1=new Color(255 ,48 ,48);
        button1.setBackground(buttonColor1);
        
        Color buttonColor2=new Color(65 ,105 ,180);
        button2.setBackground(buttonColor2);
        
        Color buttonColor3=new Color(0 ,255 ,127);
        button3.setBackground(buttonColor3);
        
        
        //设置监听  
        button1.addActionListener(this);  
        button2.addActionListener(this);  
        button3.addActionListener(this);  

        panel1=new JPanel();  
        panel2=new JPanel();  
        panel3=new JPanel();  
        panel4=new JPanel();     
        
        //设置图片
        ImageIcon bgim = new ImageIcon(GUI界面.class.getResource("背景图片3.gif")) ;//背景图案  
        bgim.setImage(bgim.getImage().  
                                     getScaledInstance(bgim.getIconWidth(),  
                                                       bgim.getIconHeight(),   
                                                       Image.SCALE_DEFAULT)); 
        JLabel label背景=new JLabel();
        label背景.setIcon(bgim);
        panel1.add(label背景);  

        label1=new JLabel("账  号:");  
        label1.setBounds(20, 50, 60, 50);
        label1.setFont(font);
        label2=new JLabel("密  码:");  
        label2.setBounds(20, 50, 60, 50);
        label2.setFont(font);

        textField=new JTextField(20);  //设置账号文本框长度
        passwordField=new JPasswordField(20);  //设置密码框长度
        //加入到JPanel中  
        panel3.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
        panel3.add(label1);  
        panel3.add(textField);  

        panel3.add(label2);  
        panel3.add(passwordField);  
           
        panel3.add(button1);       //添加按钮
        panel3.add(button2);  
        panel3.add(button3);

        //加入JFrame中  
        this.add(panel1);  
        //this.add(panel2);  
        this.add(panel3);  
        //this.add(panel4);  
    }  

//    public void actionPerformed(ActionEvent e) {            //事件判断
//
//        if(e.getActionCommand()==" ") {  

    //清空文本框和密码框  
    public  void clear()  {  
        textField.setText("");  
        passwordField.setText("");  
    }

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO 自动生成的方法存根
		
	}  
} 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值