That's a fair-sized project. I don't expect anyone is going to do that much coding for you in one shot.
If you have more specific questions, for example about file I/O from Java, then you should ask those instead.
2007-07-08 03:47:53
·
answer #1
·
answered by McFate 7
·
0⤊
0⤋
i wrote it using netbean, and i'm not sure if yahoo cuts out some long line or whatever because when I preview it, it looks weird. anyway, if you need the source code, you can email me at wppdzus@yahoo.com
import java.io.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SafeUI extends javax.swing.JFrame implements ActionListener{
/** Creates new form UI */
public UI() {
initComponents();
newFile.addActionListener(this);
saveFile.addActionListener(this);
openFile.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==saveFile){
saveFile();
}else if(ae.getSource()==openFile){
openFile();
}else{
newFile();
}
}
//
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
information = new javax.swing.JTextArea();
password = new javax.swing.JTextField();
saveFile = new javax.swing.JButton();
openFile = new javax.swing.JButton();
newFile = new javax.swing.JButton();
fileName = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Peng Wei's Safe");
information.setColumns(20);
information.setRows(5);
information.setText("information:");
jScrollPane1.setViewportView(information);
password.setText("password");
saveFile.setText("Save");
openFile.setText("Open");
newFile.setText("New");
fileName.setText("put your file's name here.");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(password, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(fileName, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveFile)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(openFile)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(newFile)))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {newFile, openFile});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(openFile)
.addComponent(newFile)
.addComponent(saveFile)
.addComponent(fileName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}//
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new UI().setVisible(true);
}
});
}
public void saveFile(){
FileWriter outputStream = null;
try {
outputStream = new FileWriter(fileName.getText()+".safe");
outputStream.write(password.getText());
outputStream.write("\n");
outputStream.write(information.getText());
if (outputStream != null) {
outputStream.close();
}
}catch(IOException ioe){information.setText("error saving file.");
}
}
public void openFile(){
BufferedReader inputStream = null;
try {
inputStream = new BufferedReader(new FileReader(fileName.getText()+".safe"));
password.setText(inputStream.readLine());
information.setText(inputStream.readLine());
if (inputStream != null) {
inputStream.close();
}
}catch(IOException ioe){information.setText("error reading file.");
}
}
public void newFile(){
password.setText("");
information.setText("");
fileName.setText("");
}
// Variables declaration - do not modify
private javax.swing.JTextField fileName;
private javax.swing.JTextArea information;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton newFile;
private javax.swing.JButton openFile;
private javax.swing.JTextField password;
private javax.swing.JButton saveFile;
// End of variables declaration
}
2007-07-08 11:36:32
·
answer #2
·
answered by peng w 2
·
0⤊
0⤋