标题:看看这里的this 是什么意思?
只看楼主
xiayongjie
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-12-3
 问题点数:0 回复次数:3 
看看这里的this 是什么意思?

//LoginDialogDemo.java import java.awt.*; import javax.swing.*; import java.awt.event.*;

public class LoginDialogDemo extends JFrame { JButton button = new JButton("Click Me"); JPanel panel = new JPanel(new FlowLayout());

public LoginDialogDemo() { final JFrame frame = this; this.getContentPane().add(panel,BorderLayout.SOUTH); panel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showLoginDialog(frame); } }); this.setSize(300,200); this.setTitle("显示登陆对话框"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.show(); }

void showLoginDialog(JFrame frame){ JPanel p = new JPanel(new GridLayout(0,1)); JTextField tfUserName = new JTextField(); JPasswordField tfPassword = new JPasswordField(); p.add(new JLabel("Username: ")); p.add(tfUserName); p.add(new JLabel("Password: ")); p.add(tfPassword); if (JOptionPane.showConfirmDialog(frame // may want to pass your application frame here ,p ,"Login" ,JOptionPane.OK_CANCEL_OPTION ,JOptionPane.PLAIN_MESSAGE ) == JOptionPane.OK_OPTION) { System.out.println("User Name:"+tfUserName.getText()); System.out.println("Password:" + new String(tfPassword.getPassword())); } }

public static void main(String[] args) { LoginDialogDemo frame = new LoginDialogDemo(); } }

看看这里的this 是什么意思?

搜索更多相关主题的帖子: frame public void button 
2004-12-07 15:03
pyzheng
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2004-12-5
得分:0 

public static void main(String[] args) { LoginDialogDemo frame = new LoginDialogDemo(); ========================

是这里的呢还是当前窗口的 我也不知道了


-----------人間太苦﹐成仙太難------------
2004-12-14 11:29
pyzheng
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2004-12-5
得分:0 
怎么没有人来说啊???????????

-----------人間太苦﹐成仙太難------------
2004-12-18 12:17
zhouyao_14
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2006-2-15
得分:0 

就是当前对象的意思啊!!!在程序里不用写(默认是这个)


2006-03-04 19:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-8972-1-1.html




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

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