关于用Java做出QQ登录界面的大致样板。在账号栏中有文本框 还有下拉列表这么弄。求解,谢了!!!!!!

解决方案 »

  1.   

    package com.lovo;import java.awt.Color;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.BorderFactory;
    import javax.swing.ButtonGroup;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPasswordField;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    import javax.swing.border.Border;public class GuiQQ extends JFrame implements ActionListener{ private JTextField jtf1;
     private JPasswordField jpf;
     public GuiQQ(){
      Container conn = this.getContentPane();//加入一个容器
      
      conn.setLayout(null);//绝对布局
      
      Font font = new Font("宋体",Font.BOLD,15);//创建一个字体以便其它调用
      
      this.setSize(337,300);
      
      Image image = new ImageIcon("2.jpg").getImage();//窗口图像
      
      this.setIconImage(image);
      
      //设置背景
      JLabel jl1 = new JLabel();//也相当于一个容器
      
      Image image1 = new ImageIcon("background.jpg").getImage();
      
      jl1.setIcon(new ImageIcon(image1));
      
      jl1.setBounds(0,0,337,50);
      
      conn.add(jl1);
      
      //设置一个大的边框
      
      JLabel jlb = new JLabel();
      
      jlb.setBounds(5,70,320,100);
      
      conn.add(jlb);
      
      Border border = BorderFactory.createLineBorder(Color.getHSBColor(5,50,500));
      
      jlb.setBorder(border);
      
      
      //在容器里面设置背景
      conn.setBackground(Color.getHSBColor(30, 20, 120));
      
      JLabel jl2 = new JLabel("账号:");
      
      jl2.setBounds(50,80,50,20);
      
      conn.add(jl2);
      
      //账号的文本框
      
      jtf1 = new JTextField();
      
      jtf1.setBounds(110,80,150,20);
      
      jtf1.setFont(font);
      
      conn.add(jtf1);
      
      JLabel jl3 = new JLabel("密码:");
      
      jl3.setBounds(50,120,50,20);
      
      jl3.setForeground(Color.red);//字体颜色
      
      conn.add(jl3);
      
      jpf = new JPasswordField();
      
      jpf.setBounds(110,120,150,20);
      
      jpf.setFont(font);
      
      conn.add(jpf);
      
      //状态
      
      JLabel jl4 = new JLabel("状态");
      
      jl4.setBounds(20,180,50,20);
      
      conn.add(jl4);
      
      JComboBox jcb = new JComboBox();
      
      jcb.addItem("在线");
      
      jcb.addItem("隐身");
      
      jcb.addItem("离开");
      
      jcb.setBounds(60,180,70,20);
      
      conn.add(jcb);
      
      JCheckBox jcb1 = new JCheckBox("自动登录");
      
      jcb1.setBounds(140,180,90,20);
      
      conn.add(jcb1);
      
      JCheckBox jcb2 = new JCheckBox("隐身登录");
      
      jcb2.setBounds(230,180,90,20);
      
      conn.add(jcb2);
      
      JRadioButton jr = new JRadioButton("男");
      
      jr.setBounds(20,220,50,20);
      
      conn.add(jr);
      
      JRadioButton jr1 = new JRadioButton("女");
      
      jr1.setBounds(80,220,50,20);
      
      conn.add(jr1);
      
      //要设置一个按钮组才不会既选择男又选择女
      
      ButtonGroup bg=new ButtonGroup();
      bg.add(jr);
      bg.add(jr1);
      
      JButton jb1 = new JButton("登录");
      
      jb1.setBounds(140,220,80,20);
      
      conn.add(jb1);
      
      jb1.addActionListener(this);
      
      JButton jb2 = new JButton("退出");
      
      jb2.setBounds(230,220,80,20);
      
      conn.add(jb2);
      
      jb2.addActionListener(this);
      
      
      this.setTitle("QQ2009 正式版");
      
      this.setResizable(false);//设置尺寸不可改变
      
      this.setLocationRelativeTo(null);//设置居中
      
      this.setDefaultCloseOperation(3);//当点击关闭时进行关闭
      
      this.setVisible(true); }
     
     @Override
     public void actionPerformed(ActionEvent e) {
      
      String getCommand = e.getActionCommand();
      
      if("登录".equals(getCommand)){
       
       String getName = this.jtf1.getText();
       
       String getPwd = this.jpf.getText();
       
       
       JOptionPane.showMessageDialog(null,"你输入的值是"+getName+""+getPwd);
       
      }
      else if("退出".equals(getCommand)){
       
       this.dispose();
       
      }
     }
     public static void main(String[] args) {
      
      new GuiQQ();
     }
    }
      

  2.   

    ---------- 编译 ----------
    注意:GuiQQ.java 使用或覆盖了已过时的 API。
    注意:要了解详细信息,请使用 -Xlint:deprecation 重新编译。输出完成 (耗时 4 秒) - 正常终止 
    出现这怎么办?
      

  3.   


      String getPwd = this.jpf.getText();
    这句改成
       String getPwd = String.valueOf(this.jpf.getPassword());
    其它的就要靠你自已改成让别人看来出来了。