我无法在我创建的框架类上显示我的面板类。这是我的面板和框架
public class PasswordCheckerPanel extends JPanel
{
private String string;
private JButton B1, B2, B3;
private JLabel Rules, L1, L2, L3, Type, Retype;
private JTextField TF1, TF2;
private ArrayList<String> AR1 = new ArrayList<String>();
private ArrayList<String> AR2 = new ArrayList<String>();
private JFileChooser Input, Output;
public PasswordCheckerPanel()
{
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JPanel Panel1 = new JPanel();
TitledBorder Titled1 = BorderFactory.createTitledBorder("Password Checker Rules");
Rules = new JLabel();
Rules.setText("Use the following rules when creating your passwords");
L1= new JLabel();
L1.setText("1. Length must be greater than 6.");
L2 = new JLabel();
L2.setText("2. Must contain atleast one alpha character");
L3 = new JLabel();
L3.setText("3. Must contain atleast one numeric character");
Panel1.setBorder(Titled1);
Panel1.add(Rules);
Panel1.add(L1);
Panel1.add(L2);
Panel1.add(L3);
add(Panel1);
JPanel Panel2 = new JPanel();
Type = new JLabel();
Type.setText("Password: ");
Retype = new JLabel();
Retype.setText("Re-Type Password: ");
TF1 = new JTextField(20);
TF2 = new JTextField(20);
Panel2.add(Type);
Panel2.add(TF1);
Panel2.add(Retype);
Panel2.add(TF2);
add(Panel2);
JPanel Panel3 = new JPanel();
B1.setMnemonic('c');
B1.setText("Check Password");
B1.setToolTipText("Check Password");
B1.addActionListener(new ButtonListener());
B2.setMnemonic('f');
B2.setText("Check Password in File");
B2.setToolTipText("Check Password in File");
B2.addActionListener(new ButtonListener());
B3.setMnemonic('e');
B3.setText("Exit");
B3.setToolTipText("Exit");
B3.addActionListener(new ButtonListener());
Panel3.add(B1);
Panel3.add(B2);
Panel3.add(B3);
add(Panel3);
}
}
这是我的框架
public class PasswordCheckerFrame extends JFrame
{
private PasswordCheckerPanel Panel = new PasswordCheckerPanel(); // Creates a PasswordCheckerPanel object
public PasswordCheckerFrame() // PasswordCheckerFrame Constructor
{
JFrame WindowBox = new JFrame(); // Creates a new JFrame
WindowBox.setTitle("Password Checker"); // sets JFrame title
WindowBox.setSize(500, 500); // sets JFrame size
WindowBox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // sets the operation as to what happens when you close the gui
WindowBox.add(Panel); // adds the Panel to the JFrame
WindowBox.pack(); // Packs for size refitting
WindowBox.setVisible(true); // sets visibility of the Frame
}
public static void main(String[] args)
{
new PasswordCheckerFrame(); // creates an instance of the PasswordCheckerFrame class
}
}
你能指出我可能犯的任何错误吗?我不断得到一个 J 单元测试版本,所以真的很难找出我做错了什么。是代码还是其他?