Java学习笔记——IMuser(暂且叫这个)登陆界面

前言:今天算是忙活一天了,从睁开眼睛到现在都在弄那个登陆界面。考虑到了用CardLayout的布局,但是又不熟悉,还好这些类库都还算简单,查查JDK,外加到网上搜索下下就OK完成了。其实服务器和客户端是早写好了,不过就是在测试阶段,不好弄出来,因为很多功能还没有实现,总不能光有个框架不干事是吧。这个登陆界面也是光有个框架,干事么,还论不到它,所以就先贴出来了。至于地图编辑器,我想还是以后再弄吧,因为牵涉到的东西蛮多的,而自己现有的知识量又一下子撑不起整个程序,还是慢慢积累了去弄,到时候一起把那个游戏也A出来就成了……

         登陆界面是用CardLayout做的,而且这个只能算是个自己的类库的一种,还是提供蛮多可内部操作的。大致就是一个成型的登陆界面。

        第一页为登陆的用户ID和密码,下面是个连接信息显示区域,最上面还留出了个广告条的JLabel。

        第二页是连接的参数设置。考虑以后还可以用代理实现,这里就先放一下。

        下面是整个程序:

import  java.awt. * ;
import  javax.swing. * ;
import  java.awt.event. * ;
import  java.awt.event.ActionListener;
import  java.util.EventListener;

public   class  CheckFrame  extends  JFrame  implements  ActionListener  {
    
// 数据定义
    /*
    private JMenu menu = null;
    private JMenuItem jmiAdvantage = null;
    
*/

    
    
private JTextArea jta = null;
    
private JTextField jtfID = null
            jtfServerIP 
= null, jtfPort = null;
    
private JPasswordField jpwdf = null;
    
private JLabel labelAD = null;
    
private JButton jbOK = null, jbCancel = null, jbAdv = null
            jbApply 
= null, jbReturnLogin = null;
    
private ImageIcon IconAD = null;
    
private CardLayout card = null;
    
private Container content = null;
    
    
public CheckFrame (String title) {
        
super(title);
        
// 考虑,当关闭时,整个程序也是要关闭的
        this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        card 
= new CardLayout();
        
this.setLayout (card);
        
        
/*
        // JMenu
        menu = new JMenu("设置");
        jmiAdvantage = new JMenuItem("IP手动设置");
        jmiAdvantage.addActionListener (this);
        menu.add (jmiAdvantage);
        
        // JMenuBar
        JMenuBar menubar = new JMenuBar();
        menubar.add (menu);
        this.setJMenuBar (menubar);
        
*/

        
        
// JPanel
        
// 登陆面板
        JPanel jpLogin = new JPanel (new BorderLayout());
        
        JPanel jpNorthLogin 
= new JPanel ();
        
        JPanel jpCenterLogin 
= new JPanel (new GridLayout(0,1));
        JPanel jpUserID 
= new JPanel (new FlowLayout());
        JPanel jpPwd 
= new JPanel (new FlowLayout());

        JPanel jpSouthLogin 
= new JPanel(new BorderLayout());
        JPanel jpButtonLogin 
= new JPanel(new FlowLayout());
        
        JPanel jpInfoArea 
= new JPanel();
        
        IconAD 
= new ImageIcon("ad.gif");
        
        
// 设置IP面板
        JPanel jpSetting = new JPanel (new BorderLayout());
        
        JPanel jpCenterSetting 
= new JPanel (new GridLayout(0,1));
        JPanel jpNorthSetting 
= new JPanel (new FlowLayout());
        JPanel jpSouthSetting 
= new JPanel (new FlowLayout());
        
        JPanel jpSvIP 
= new JPanel (new FlowLayout());
        JPanel jpPort 
= new JPanel (new FlowLayout());
        JPanel jpButtonSetting 
= new JPanel (new FlowLayout());
        
        
// JLabel
        labelAD = new JLabel(IconAD);
        JLabel labelID 
= new JLabel("用户号码:");
        JLabel labelPwd 
= new JLabel("用户密码:");
        
        JLabel labelSetting 
= new JLabel ("连接设置");
        JLabel labelSvIP 
= new JLabel("服务器IP:");
        JLabel labelPort 
= new JLabel("端口号:");
        
        
// JTextField
        jtfID = new JTextField(18);
        jpwdf 
= new JPasswordField(18);
        jtfServerIP 
= new JTextField("192.168.18.5"10);
        jtfPort 
= new JTextField("2007"5);
        
        
// JButton
        jbOK = new JButton("确定");
        jbCancel 
= new JButton("取消");
        jbCancel.addActionListener (
this);
        jbApply 
= new JButton("应用");
        jbAdv 
= new JButton("高级");
        jbAdv.addActionListener (
this);
        jbReturnLogin 
= new JButton("返回");
        jbReturnLogin.addActionListener (
this);
        
        
// JTextArea
        jta = new JTextArea(325);
        
// jta.append ("1 2 3 4 ");
        jta.setEditable (false);
        jta.setWrapStyleWord (
true);
        
        
// JScrollPane
        JScrollPane jsp = new JScrollPane(jta);
        
        
// JPanel add
        jpUserID.add (labelID);
        jpUserID.add (jtfID);
        jpPwd.add (labelPwd);
        jpPwd.add (jpwdf);
        
        jpSvIP.add (labelSvIP);
        jpSvIP.add (jtfServerIP);
        jpPort.add (labelPort);
        jpPort.add (jtfPort);
        
        jpButtonLogin.add (jbOK);
        jpButtonLogin.add (jbCancel);
        jpButtonLogin.add (jbAdv);
        
        
// 连接信息区域    
        jpInfoArea.add (jsp);
        
        
// 登陆界面
        jpNorthLogin.add (labelAD);
        jpCenterLogin.add (jpUserID);
        jpCenterLogin.add (jpPwd);
        jpCenterLogin.add (jpButtonLogin);
        
        jpSouthLogin.add (
new JLabel("连接信息:"), BorderLayout.NORTH);
        jpSouthLogin.add (jpInfoArea, BorderLayout.CENTER);
        
        jpLogin.add (jpNorthLogin, BorderLayout.NORTH);
        jpLogin.add (jpCenterLogin, BorderLayout.CENTER);
        jpLogin.add (jpSouthLogin, BorderLayout.SOUTH);
        
        
// 设置IP界面
        jpNorthSetting.add (labelSetting);
        
        jpCenterSetting.add (jpSvIP);
        jpCenterSetting.add (jpPort);
        
        jpButtonSetting.add (jbApply);
        jpButtonSetting.add (jbReturnLogin);
        jpSouthSetting.add (jpButtonSetting);
        
        jpSetting.add (jpNorthSetting, BorderLayout.NORTH);
        jpSetting.add (jpCenterSetting, BorderLayout.CENTER);
        jpSetting.add (jpSouthSetting, BorderLayout.SOUTH);
                
        content 
= this.getContentPane ();
        content.add (jpLogin, 
"login");
        content.add (jpSetting, 
"setting");
        
this.pack ();
        
        card.show(content, 
"login");
    }

    
    
// 返回JTextArea的对象
    public JTextArea getTheJTA () {
        
return this.jta;
    }

    
    
// 返回按钮对象
    public JButton getTheButton (int index) {
        
switch (index) {
            
case 1:
                
return jbOK;
            
case 2:
                
return jbCancel;
            
case 3:
                
return jbAdv;
            
case 4:
                
return jbApply;
            
case 5:
                
return jbReturnLogin;
        }

        
return null;
    }

    
    
// 设置图片 暂时未实现
    public void SetImageIcon (String iconPath) {
        
this.IconAD = new ImageIcon(iconPath);
    }

    
    
public static void main(String[] args) {
        CheckFrame frame 
= new CheckFrame("欢迎测试IMuser");
        frame.setVisible (
true);
    }


    
/**
     * Method actionPerformed
     *
     *
     * 
@param e
     *
     
*/

    
public void actionPerformed (ActionEvent e) {
        
// TODO: 在这添加你的代码
        if (e.getSource ().equals (jbAdv)) {
            card.show (content, 
"setting");
            
this.pack ();
        }

        
else if (e.getSource ().equals (jbReturnLogin)) {
            card.show (content, 
"login");
            
this.pack ();
        }

        
else if (e.getSource ().equals (jbCancel)) {
            System.exit (
0);
        }

    }

}

        类可以返回出要在外部调用的监听对象,比如“确定”按钮,“应用”按钮等,还可以返回JTextArea的对象,来把信息输出到内部的文本区域上去。外部调用且创建这个类的实例就是一个登陆窗口了。

后话:我这个人还是真的三天打鱼两天晒网啊~这个弄好以后估计我页蛮少会专心去弄这个IMuser了,因为开学了,事情很多,明天老娘出院,这几天估计也没什么时间搞这个了。十一假期过后我想自己应该会收敛心思看书去,毕竟还有好多艰难困苦的路等着我走,而且最近就有一条……哎,自己真的是什么都不懂啊,开始编程序后越来越觉得自己知识的匮乏。大学生活很令人留恋。老师在学生身上打好模子,然后以后可以让别人来浇铸,难说还能弄出许多不同的造型或者形状出来。学校里面真少有成品诞生……还是个只有个人想法的大学生啊,这个名号也叫不久了……

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值