我在以下声明中收到错误
public class project {
JFrame start ;
JButton submit;
JButton cancel ;
JButton fp ;
JTextField username;
JPasswordField pass ;
JLabel uname ;
JLabel pawd ;
project()
{
start = new JFrame("Project");
submit = new JButton("Submit");
cancel = new JButton("Cancel");
fp = new JButton("Forgot Password ?") ;
uname = new JLabel("Username");
pass = new JPasswordField();
pawd = new JLabel("Password");
username = new JTextField();
start.setBounds(300,400,900,900);
start.setResizable(true);
start.setVisible(true);
uname.setBounds(180,200,80,25);
pawd.setBounds(230,225,80,25);
submit.setBounds(250,350,90,25);
cancel.setBounds(3400,350,90,25);
username.setBounds(300,200,100,25);
pass.setBounds(300,230,100,25);
fp.setBounds(420,215,125,25);
start.add(submit);
start.add(cancel);
start.add(fp);
start.add(username);
start.add(pass);
start.add(username);
start.add(uname);
start.add(pawd);
submit.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent ae){
submitperformed(ae);
}
});
}
public void submitperformed(ActionEvent ae)
{
if((username.getText()).equals("root") && (pass.getPassword().equals("11223344")))
{
start.setVisible(false);
}
else
JOptionPane.showMessageDialog( null,"Wrong Username or Password","Error Mesage", JOptionPane.ERROR_MESSAGE);
}
public void cancelperformed(ActionEvent ae)
{
System.exit(0);
}
public static void main(String []s)
{
project a = new project();
}
}
不兼容的类型:框架“项目”无法转换为组件!
我在What is first argument in 'JOptionPane.showConfirmDialog() here?得到了类似的问题,但有点过于复杂。 现在,根据老师告诉我的内容,我们将当前类的对象作为参数传递,代替我通过它的位置。但“这个”也是这个工作。那么上面提到的错误是什么意思? 谁能解释这个比上面的链接?
这是整个代码。实际上截至目前,我还不知道你所谈论的组件概念。我听过几次。它是一个类还是一个包?你能不能说一下?当我们应该提供一个组件参数时,应该感激并且null如何工作?
另一件事!!
我附上了上述代码结果的快照。忽略按钮和用户名标签。只需注意密码标签。现在不是根据我设置界限的位置。无论我设定什么界限,它的位置都不会改变。它令人沮丧,我不知道什么导致了这个问题。是否与在设置边界或类似内容之前添加标签和按钮有关?你能看一遍并找出发生了什么吗?