java作业

本文详细介绍了登录界面的设计与实现过程,包括用户输入验证、窗口布局、按钮交互等功能。

import javax.swing.;
import java.awt.Window;
import java.awt.event.
;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JLabel;
import javax.swing.ButtonGroup;
public class Homework {

protected static final Window dlg1 = null;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    final JFrame frm = new JFrame("登陆");
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setLayout(null);
    
    JLabel userLabel = new JLabel();
    userLabel.setText("账号:");
    userLabel.setBounds(40, 20, 80, 30);
    
    JLabel userLabel1 = new JLabel();
    userLabel1.setText("密码:");
    userLabel1.setBounds(40, 20, 80, 110);
    
    JLabel slabel = new JLabel("服务区:");
    slabel.setBounds(40, 20, 80, 170);
    frm.add(slabel);
    
    ButtonGroup btnGroup = new ButtonGroup();
    
    JRadioButton aRadioButton = new JRadioButton("网通");
    aRadioButton.setBounds(100, 90, 70, 30);
    aRadioButton.setSelected(true);
    JRadioButton bRadioButton = new JRadioButton("电信");
    bRadioButton.setBounds(190, 90, 70, 30);
    
    btnGroup.add(aRadioButton);
    btnGroup.add(bRadioButton);
    frm.add(aRadioButton);
    frm.add(bRadioButton);
    
    JTextField userText = new JTextField();
    userText.setEditable(true);
    userText.setHorizontalAlignment(SwingConstants.LEFT);
    userText.setColumns(20);
    userText.setBounds(100, 20, 120, 30);
    
    JTextField userText1 = new JTextField();
    userText1.setEditable(true);
    userText1.setHorizontalAlignment(SwingConstants.LEFT);
    userText1.setColumns(20);
    userText1.setBounds(100, 60, 120, 30);
    
    final JDialog dlg = new JDialog(frm,"窗口");
    dlg.setBounds(470, 220, 200, 150);
    dlg.setLayout(null);
    dlg.setModal(true);
    


    JButton obtn = new JButton("登陆");
    obtn.setBounds(60, 125, 60, 30);
    obtn.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            dlg.setVisible(true);
        }
        });
    frm.add(obtn);
    
    JButton btn = new JButton("进入游戏");
    btn.setBounds(50, 40, 100, 25);
    btn.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            dlg.setVisible(false);
        } 
        });
    dlg.add(btn);
    
    final JDialog dlg1 = new JDialog(frm,"窗口");
    dlg1.setBounds(470, 220, 200, 150);
    dlg1.setLayout(null);
    dlg1.setModal(true);
    
    JButton obtn1 = new JButton("退出");
    obtn1.setBounds(180, 125, 60, 30);
    obtn1.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            dlg1.setVisible(true);
        }
        });
    frm.add(obtn1);
    
    JButton btn1 = new JButton("确认退出");
    btn1.setBounds(50, 40, 100, 25);
    btn1.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            dlg1.setVisible(false);
        }
        });
    dlg1.add(btn1);
    
    
    frm.add(userLabel);
    frm.add(userText);
    frm.add(obtn1);
    frm.add(obtn);
    frm.add(userLabel1);
    frm.add(userText1);
    frm.setBounds(450, 200, 325, 200);
    frm.setVisible(true);
}

}
j'a

转载于:https://www.cnblogs.com/zhangfengfeng/p/5295963.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值