所以我正在尝试制作一个利用 JDesktopPane 来保存许多不同内部框架的程序。在下面的代码中,我只有一个内部框架(一个登录框架)。我希望将内框传递给外框并像这样添加它们。但是我在这样做时遇到了问题....文件名是 TheProgram.java 看:
import javax.swing.*;
import java.awt.BorderLayout;
class OuterFrame
{
JDesktopPane outframe = new JDesktopPane();
OuterFrame()
{
}
OuterFrame(JInternalFrame inframe)
{
outframe.add(inframe);
}
}
class Login extends JFrame
{
JPanel panel;
JLabel lblname;
JLabel lblpassword;
JTextField txtname;
JPasswordField txtpassword;
JButton btlogin;
JInternalFrame login = new JInternalFrame();
Login()
{
login.setSize(300,200);
login.setLocation(10,2);
login.setTitle("Member Login");
lblname=new JLabel("User Name:");
lblpassword=new JLabel("Password:");
btlogin=new JButton("Login");
txtname=new JTextField(20);
txtpassword=new JPasswordField(20);
panel=new JPanel();
panel.add(lblname);
panel.add(txtname);
panel.add(lblpassword);
panel.add(txtpassword);
panel.add(btlogin);
//panel.add(lblmess);
login.add(panel);
login.setVisible(true);
}
public void method()
{
OuterFrame.OuterFrame(login);
}
}
public class TheProgram
{
public static void main(String[] args)
{
new OuterFrame();
}
}