当前位置: 代码迷 >> Java相关 >> JOptionPane.showMessageDialog的问题
  详细解决方案

JOptionPane.showMessageDialog的问题

热度:639   发布时间:2007-01-12 17:04:22.0
JOptionPane.showMessageDialog的问题

package 学生管理系统;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class MainClass extends JFrame {

public MainClass() {
super("学生管理系统---管理员登陆");
this.init();
}

public void init() {
Container cp = this.getContentPane();
cp.setLayout(null);


JLabel jlabel1 = new JLabel("管理员帐号:");
JLabel jlabel2 = new JLabel("管理员密码:");
JButton jbutton = new JButton("登陆");
final JTextField text = new JTextField(10);
final JPasswordField password = new JPasswordField();
jbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] str =
new DatabaseUtilities().getDataTypes("Admin_info");
if(str[0].equals(text.getText()))
if(str[1].equals(password.getText()))
JOptionPane.showMessageDialog(f,"你以管理员"
+str[0]+"的身份登陆");  //这里有错误,该怎么办。。。意思是不认识F
else
JOptionPane.showMessageDialog(f,"你输入的密码有误");
else
JOptionPane.showMessageDialog(f,"你输入的用户名不存在");
}
});

cp.add(jlabel1);
cp.add(jlabel2);
cp.add(text);
cp.add(password);
cp.add(jbutton);

jlabel1.setBounds(150, 150, 100, 20);
jlabel2.setBounds(150, 200, 100, 20);
text.setBounds(260, 150, 150, 20);
password.setBounds(260, 200, 150, 20);
jbutton.setBounds(220, 270, 90, 40);

this.setSize(new Dimension(600, 400));
this.setLocation(200, 200);
this.show();

this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

/*class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
String SQLCommand = "SELECT * FROM Admin_info";
execute(SQLCommand);
}
}*/

public static void main(String[] args) {
final MainClass f = new MainClass();
}

}

搜索更多相关的解决方案: JOptionPane  quot  import  JLabel  awt  

----------------解决方案--------------------------------------------------------
什么 问题
----------------解决方案--------------------------------------------------------

那个f表示这个dialog所在的frame,明显f没有定义。你可以改成null或者this


----------------解决方案--------------------------------------------------------

如果我想让他访问外面的那个在MAIN中声明的F 该怎么办?
把F声明为FINAL?好像不管用。。。


----------------解决方案--------------------------------------------------------
传入this就可以了
----------------解决方案--------------------------------------------------------
真想骂楼主,包名竟然用中文,接受不了.最好用english.
----------------解决方案--------------------------------------------------------

看到红线了没有?怎么是这样呢? 千里再解释一下.



----------------解决方案--------------------------------------------------------
晕。。。楼上的  我E文不好。。。
建的包太多了。。。这样中文名我自已好认识。。。。
自已做练习的东西。。。。。
----------------解决方案--------------------------------------------------------
以下是引用千里冰封在2007-1-12 20:51:17的发言:
传入this就可以了

this不可以啊,因为我是在BUTTON这个ACTION方法中声明写的这段代码。。
THIS不是对当初引用对像的引用么。。。那如果我用 THIS的话就得到BUTTON这个对像啦。。。。


----------------解决方案--------------------------------------------------------
有时候,用中文包编译器解析不了的.信不信你.
----------------解决方案--------------------------------------------------------