PassTest

public class PassTest{

    float ptValue;

 

    public static void main(String args[]){

      String str;

      int val;

 

      PassTest pt=new PassTest();

     

      val=11;

      pt.changeInt(val);

      System.out.println("Int value is:"+val);

 

       str=new String("Hello");

       pt.changeStr(str);

       System.out.println(Str value is:"+str);

 

        pt.ptValue=101f;

        pt.changeObiValue(pt); 

        System.out.println("Current ptValue is:"+pt.ptValue);

    }

 

    public void changeInt(int value){

      value=55;

    }

 

    public void changeStr(String value){

      value=new String("different")

    }

 

    public void changeObjValue(PassTest ref)

      ref.ptValue=99f;

    }

}

   

  

package guiTest603; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class QQloginWindow extends JFrame{//定义窗口,顶层容器,默认布局方式为BorderLayout //成员变量:定义窗口中需要的组件 JPanel uPanel,centerPanle,bottomPanel;//面板:用于组织窗口的不同部分 JLabel nameLable,passLable;//标签组件:通常显示静态文本 JTextField nameText;//文本框组件:允许用户输入用户名 JPasswordField passTest;//密码输入框组件:用于隐藏用户输入的密码内容。与 JTextField 不同,JPasswordField 会用掩码字符 //(通常是 * 或 ●)替代实际输入的内容 JButton logButton,registerButton,cancelButton;//登录按钮 QQloginWindow(){//定义构造方法,初始化(生成)成员变量对象 uPanel=new JPanel();//创建中间容器对象,JPanel centerPanle=new JPanel();//JPanel默认布局是Flow bottomPanel=new JPanel(); Color myColor=new Color(15,150,150);//参数代表:红色,绿色,蓝色 uPanel.setBackground(myColor); centerPanle.setBackground(Color.cyan); bottomPanel.setBackground(Color.gray); //只要是容器,都有设置布局方式的方法setLayout(),以便按照制定的布局添加控件 //如果没有明显的设定容器布局,系统会采用默认的布局方式 //创建基本控件 nameLable=new JLabel("请输入账号:"); nameText=new JTextField(10); //设置容器的布局方式 FlowLayout flowLayout=new FlowLayout();//创建布局策略对象 uPanel.setLayout(flowLayout);//设置布局 //想在中间容器中添加控件 uPanel.add(nameLable);uPanel.add(nameText); //在顶层容器(窗口)中添加中间容器,位置为上面(北方) this.add(uPanel,BorderLayout.NORTH); //中间区域的面板 passLable=new JLabel("请输入密码:"); passTest=new JPasswordField(10); centerPanle.add(passLable);//采用默认布局方式 centerPanle.add(passTest); this.add(centerPanle); //底部区域,创建三个按钮,添加到中间容器 logButton=new JButton("登录"); bottomPanel.add(logButton);//JPanle默认是FlowLayout() registerButton=new JButton("注册");//跳转到注册窗口,自己新建一个窗口 bottomPanel.add(registerButton); cancelButton=new JButton("取消"); bottomPanel.add(cancelButton); this.add(bottomPanel,BorderLayout.SOUTH);//添加中间容器到顶层窗口 //给按钮添加事件监听器,当点击按钮的时候,做出适当的相应 LogBtListener lbl=new LogBtListener();//创建监听器 logButton.addActionListener(lbl);//使用内部类作为事件监听器 //设置窗口属性 this.setSize(600,400); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false);//固定窗口大小 }//构造方法 //定义内部类,作为事件监听器(登录) class LogBtListener implements ActionListener{ @Override public void actionPerformed(ActionEvent ae) { String name=nameText.getText(); String pass=passTest.getText(); if(name.equals("java")&&pass.equals("java123")) { JOptionPane.showMessageDialog(null, "登录成功"); } else { JOptionPane.showMessageDialog(null, "账户或密码错误!"); } } } //注册 class RegisterButton implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { JOptionPane.show } } }//class 检测注册按钮
最新发布
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值