📄 face.java
字号:
}
}
else
{
list.setListData(columnData);
list.setCellRenderer(new MyCellRenderer());
JMenuBar mb = new JMenuBar();
fileMenu.add( createFileNewItem() );
fileMenu.add( createFileExitItem() );
mb.add( fileMenu );
toolMenu.add( createSetPasswordItem() );
mb.add( toolMenu );
helpMenu.add( createHelperItem() );
mb.add( helpMenu );
frame.setJMenuBar( mb );
JPanel columnPanel = new JPanel();
columnPanel.setLayout( new GridLayout(1,3) );
columnPanel.add( createUsernameButton() );
columnPanel.add( createPasswordButton() );
columnPanel.add( createRemarkButton() );
JPanel buttonPanel = new JPanel();
buttonPanel.add( createEditButton() );
buttonPanel.add( createDeleteButton() );
JPanel items = new JPanel();
pb = new PanelBuilder();
items.setLayout( new BorderLayout() );
items.add( columnPanel, BorderLayout.NORTH );
items.add( pb, BorderLayout.CENTER );
items.add( buttonPanel, BorderLayout.SOUTH );
frame.setContentPane(items);
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.show();
}
try
{
createKey();
}
catch (Exception e)
{
System.out.println(e);
}
}
private class PanelBuilder extends JPanel
{
public PanelBuilder()
{
GridBagLayout layout = new GridBagLayout();
GridBagConstraints layoutConstraints = new GridBagConstraints();
setLayout(layout);
layoutConstraints.gridx = 0;
layoutConstraints.gridy = 0;
layoutConstraints.gridwidth = 1;
layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(1, 1, 1, 1);
layoutConstraints.anchor = GridBagConstraints.CENTER;
layoutConstraints.weightx = 1.0;
layoutConstraints.weighty = 1.0;
scroll = new JScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane. HORIZONTAL_SCROLLBAR_NEVER);
layout.setConstraints(scroll, layoutConstraints);
add(scroll);
}
}
static class MyCellRenderer extends JPanel implements ListCellRenderer
{
JLabel left, middle, right;
MyCellRenderer()
{
setLayout(new GridLayout(1, 3));
left = new JLabel();
middle = new JLabel();
right = new JLabel();
left.setOpaque(true);
middle.setOpaque(true);
right.setOpaque(true);
add(left);
add(middle);
add(right);
}
public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus)
{
String leftData = ((String[])value)[0];
String middleData = ((String[])value)[1];
String rightData = ((String[])value)[2];
left.setText(leftData);
middle.setText(middleData);
right.setText(rightData);
if (isSelected)
{
left.setBackground(list.getSelectionBackground());
left.setForeground(list.getSelectionForeground());
middle.setBackground(list.getSelectionBackground());
middle.setForeground(list.getSelectionForeground());
right.setBackground(list.getSelectionBackground());
right.setForeground(list.getSelectionForeground());
}
else
{
left.setBackground(list.getBackground());
left.setForeground(list.getForeground());
middle.setBackground(list.getBackground());
middle.setForeground(list.getForeground());
right.setBackground(list.getBackground());
right.setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
return this;
}
}
//--------------------------------------------------Menu-------------------------------------------------------------//
// Event handler for the File->Exit event
private JMenuItem createFileExitItem()
{
JMenuItem item = new JMenuItem("Exit");
class MenuItemListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.exit( 0 );
}
}
ActionListener listener = new MenuItemListener();
item.addActionListener(listener);
return item;
}
// Event handler for the File->New event
private JMenuItem createFileNewItem()
{
JMenuItem item = new JMenuItem("New Information");
class MenuItemListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
final JDialog newInformation = new JDialog(frame, "New Information");
newInformation.setSize(400,400);
newInformation.getContentPane().setLayout(new BorderLayout());
JPanel tmpPanel = new JPanel();
JLabel tmpLabel = new JLabel("Username: ");
final TextField tmpText = new TextField(30);
tmpPanel.add(tmpLabel);
tmpPanel.add(tmpText);
JLabel setInit = new JLabel("Password: ");
final TextField tmpText2 = new TextField(30);
tmpText2.setEchoChar('*');
JPanel tmpPanel2 = new JPanel();
tmpPanel2.add(setInit);
tmpPanel2.add(tmpText2);
JPanel tmpPanel3 = new JPanel();
JLabel tmpLabel2 = new JLabel("Remark: ");
final TextField tmpText3 = new TextField(30);
tmpPanel3.add(tmpLabel2);
tmpPanel3.add(tmpText3);
JPanel tmpPanel4 = new JPanel();
tmpPanel4.setLayout(new BoxLayout( tmpPanel4, BoxLayout.Y_AXIS ));
tmpPanel4.add(tmpPanel );
tmpPanel4.add(tmpPanel2);
tmpPanel4.add(tmpPanel3);
newInformation.getContentPane().add(tmpPanel4, BorderLayout.CENTER);
JButton tmpButton = new JButton("OK");
JLabel lb = new JLabel();
JPanel pl = new JPanel();
pl.add(lb);
pl.add(tmpButton);
pl.add(lb);
newInformation.getContentPane().add(pl, BorderLayout.SOUTH);
newInformation.show();
tmpButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e1)
{
// tmpText2.setEchoChar('*');
String n = tmpText.getText();
String p = tmpText2.getText();
String r = tmpText3.getText();
Information infor = new Information( n, p, r );
inforList.add(infor);
String[][] temp = new String[inforList.size()][3];
for ( int i=0; i<inforList.size(); i++)
{
temp[i][0] = ( ( Information )inforList.get( i ) ).getName();
temp[i][1] = ( ( Information )inforList.get( i ) ).getPassword();
temp[i][2] = ( ( Information )inforList.get( i ) ).getRemark();
}
list.setListData(temp);
list.setCellRenderer(new MyCellRenderer());
try
{
writeFile();
}
catch (Exception e)
{
System.out.println(e);
}
newInformation.setVisible(false);
newInformation.dispose();
pb.repaint();
}
});
}
}
ActionListener listener = new MenuItemListener();
item.addActionListener(listener);
return item;
}
// Event handler for the Tools->SetPassword event
private JMenuItem createSetPasswordItem()
{
JMenuItem item = new JMenuItem("Set Password");
class MenuItemListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
final JDialog newInformation = new JDialog(frame, "New Information");
newInformation.setSize(400,200);
newInformation.getContentPane().setLayout(new BorderLayout());
JPanel tmpPanel = new JPanel();
JLabel tmpLabel = new JLabel("New Password: ");
final TextField tmpText = new TextField(30);
tmpText.setEchoChar('*');
tmpPanel.add(tmpLabel);
tmpPanel.add(tmpText);
JLabel setInit = new JLabel("Confirm Password: ");
final TextField tmpText2 = new TextField(30);
tmpText2.setEchoChar('*');
JPanel tmpPanel2 = new JPanel();
tmpPanel2.add(setInit);
tmpPanel2.add(tmpText2);
JPanel tmpPanel3 = new JPanel();
tmpPanel3.setLayout(new BoxLayout( tmpPanel3, BoxLayout.Y_AXIS ));
tmpPanel3.add(tmpPanel );
tmpPanel3.add(tmpPanel2);
newInformation.getContentPane().add(tmpPanel3, BorderLayout.CENTER);
JButton tmpButton = new JButton("OK");
JLabel lb = new JLabel();
JPanel pl = new JPanel();
pl.add(lb);
pl.add(tmpButton);
pl.add(lb);
newInformation.getContentPane().add(pl, BorderLayout.SOUTH);
newInformation.show();
tmpButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e1)
{
String np = tmpText.getText();
String np1 = tmpText2.getText();
if ( np.equals(np1) )
{
pw = np;
securityFlag = 1;
try
{
writeFile();
}
catch (Exception e)
{
System.out.println(e);
}
JOptionPane.showMessageDialog(
null,
"Password Changed",
"Notice",
JOptionPane.WARNING_MESSAGE);
newInformation.setVisible(false);
newInformation.dispose();
pb.repaint();
}
else
{
JOptionPane.showMessageDialog(
null,
"Two inputs are different, please try again!",
"Notice",
JOptionPane.WARNING_MESSAGE);
}
}
});
}
}
ActionListener listener = new MenuItemListener();
item.addActionListener(listener);
return item;
}
// Event handler for the Help->Helper event
private JMenuItem createHelperItem()
{
JMenuItem item = new JMenuItem("My Password Manager Helper");
class MenuItemListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
final JDialog help = new JDialog(frame, "Help");
help.setSize(600,300);
help.getContentPane().setLayout(new BorderLayout());
JPanel helpPanel = new JPanel();
JLabel helpLabel = new JLabel("File->New Information: to add a new list of username, password and remark. ");
helpPanel.add(helpLabel);
JPanel helpPanel2 = new JPanel();
JLabel helpLabel2 = new JLabel("File->Exit: to exit this software. ");
helpPanel2.add(helpLabel2);
JPanel helpPanel3 = new JPanel();
JLabel helpLabel3 = new JLabel("Tool->Set Password: to set the password which uses for login. ");
helpPanel3.add(helpLabel3);
JPanel helpPanel4 = new JPanel();
JLabel helpLabel4 = new JLabel("Button->Edit: to edit any list of username, password and remark which you choose. ");
helpPanel4.add(helpLabel4);
JPanel helpPanel5 = new JPanel();
JLabel helpLabel5 = new JLabel("Button->Delete: to delete any list of username, password and remark which you choose. ");
helpPanel5.add(helpLabel5);
JPanel helpPanel6 = new JPanel();
JLabel helpLabel6 = new JLabel("Help-> My Password Manager Help: to give all of help information. ");
helpPanel6.add(helpLabel6);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -