| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 560 人关注过本帖
标题:求助 高手帮忙!
只看楼主 加入收藏
st163163
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-5-26
收藏
 问题点数:0 回复次数:2 
求助 高手帮忙!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class login extends JPanel
{
    static final int WIDTH=300;
    static final int HEIGHT=150;
    JFrame loginframe;
    
    public void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)
    {
        constraints.gridx=x;
        constraints.gridy=y;
        constraints.gridwidth=w;
        constraints.gridheight=h;
        add(c,constraints);
    }
    
    
    
    login()
    {
        JFrame loginframe=new JFrame("性息管理系统");
        loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        GridBagLayout lay=new GridBagLayout();
        setLayout(lay);
        loginframe.add(this, BorderLayout.WEST);
        loginframe.setSize(WIDTH,HEIGHT);
        TOOLkit kit=Toolkit.getDefaultToolkit();
        Dimension screenSize=kit.getScreenSize();
        int width=screenSize.width;
        int height=screenSize.height;
        int x=(width-WIDTH)/2;
        int y=(height-HEIGHT)/2;
        loginframe.setLocation(x,y);
        JButton ok=new JButton("登陆");
        JButton cancel=new JButton("放弃");
        JLabel title=new JLabel("性息系统登陆窗口");
        JLabel name=new JLbel("用户名");
        JLabel password=new JLabel("密码");
        final JTextField nameinput=new JTextField(15);
        final JTextField passwordinput=new JTextField(15);
        GridBagConstraints constraints=new GridBagConstraints();
        constraints.fill=GridBagConstraints.NONE;
        constraints.anchor=GridBagConstraints.EAST;
        constraints.weightx=3;
        constraints.heighty=4;
        add(title,constraints,0,0,4,1);
        add(name,constraints,0,1,1,1);
        add(password,constraints,0,2,1,1);
        add(nameinput,constraints,2,1,1,1);
        add(passwordinput,constraints,2,2,1,1);
        add(ok,constraints,0,3,1,1);
        add(cancel,constraints,2,3,1,1);
        loginframe.setResizable(false);
        loginframe.setVisible(true);
        ok.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent Event)
            {
                String nametext=nameinput.getText();
                String passwordtext=passwoedinput.getText();
                String str=new String(passwordtext);
                boolean x=(nametext.equals("shy"));
                boolean y=(str.equals("111"));
                boolean z=(x&&y);
                if(z==true)
                {
                    loginframe.dispose();
                    //mainframe main=new mainframe();
                    System.out.pringln("正确");
                }
                else if(z==false)
                {
                    nameinput.setText("");
                    passwordinput.setText("");
                }
            }
        };
        cancel.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent Event)
            {
                loginframe.dispose();
            }
        };
    }
}

public class studentlog
{
    public static void main(String[] args)
    {
        login log=new login();
    }
}
一个登陆界面  编译不过!!!
搜索更多相关主题的帖子: static public import 
2008-05-28 12:04
freish
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1223
专家分:437
注 册:2007-6-1
收藏
得分:0 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class login extends JPanel
{
        static final int WIDTH=300;
        static final int HEIGHT=150;
       // final JFrame loginframe;
        
        public void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)
        {
                constraints.gridx=x;
                constraints.gridy=y;
                constraints.gridwidth=w;
                constraints.gridheight=h;
                add(c,constraints);
        }
        
        
        
        login()
        {
                final JFrame loginframe=new JFrame("性息管理系统");
                loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                GridBagLayout lay=new GridBagLayout();
                setLayout(lay);
                loginframe.add(this, BorderLayout.WEST);
                loginframe.setSize(WIDTH,HEIGHT);
                Toolkit kit=Toolkit.getDefaultToolkit();
                Dimension screenSize=kit.getScreenSize();
                int width=screenSize.width;
                int height=screenSize.height;
                int x=(width-WIDTH)/2;
                int y=(height-HEIGHT)/2;
                loginframe.setLocation(x,y);
                JButton ok=new JButton("登陆");
                JButton cancel=new JButton("放弃");
                JLabel title=new JLabel("性息系统登陆窗口");
                JLabel name=new JLabel("用户名");
                JLabel password=new JLabel("密码");
                final JTextField nameinput=new JTextField(15);
                final JTextField passwordinput=new JTextField(15);
                GridBagConstraints constraints=new GridBagConstraints();
                constraints.fill=GridBagConstraints.NONE;
                constraints.anchor=GridBagConstraints.EAST;
                constraints.weightx=3;
                constraints.weighty=4;
                add(title,constraints,0,0,4,1);
                add(name,constraints,0,1,1,1);
                add(password,constraints,0,2,1,1);
                add(nameinput,constraints,2,1,1,1);
                add(passwordinput,constraints,2,2,1,1);
                add(ok,constraints,0,3,1,1);
                add(cancel,constraints,2,3,1,1);
                loginframe.setResizable(false);
                loginframe.setVisible(true);
                ok.addActionListener(new ActionListener()
                {
                        public void actionPerformed(ActionEvent Event)
                        {
                                String nametext=nameinput.getText();
                                String passwordtext=passwordinput.getText();
                                String str=new String(passwordtext);
                                boolean x=(nametext.equals("shy"));
                                boolean y=(str.equals("111"));
                                boolean z=(x&&y);
                                if(z==true)
                                {
                                        loginframe.dispose();
                                        //mainframe main=new mainframe();
                                        System.out.println("正确");
                                }
                                else if(z==false)
                                {
                                        nameinput.setText("");
                                        passwordinput.setText("");
                                }
                        }
                });
                cancel.addActionListener(new ActionListener()
                {
                        public void actionPerformed(ActionEvent Event)
                        {
                                loginframe.dispose();
                        }
                });
        }
}

public class studentlog
{
        public static void main(String[] args)
        {
                login log=new login();
        }
}



用不着这么麻烦
一个登陆界面而已
2008-05-28 12:21
st163163
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-5-26
收藏
得分:0 
谢谢啦  我是新手 看着书自己做的玩的!!
2008-05-28 12:23
快速回复:求助 高手帮忙!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034802 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved