package UI;
import Common.Keep_It_Safe;
import IO.OpenObject;
import java.lang.reflect.Method;
import java.util.Arrays;
import javax.swing.JOptionPane;
/*
* NewJFrame.java
*
* Created on February 15, 2008, 12:48 AM
*/
/**
*
* @author psychok7
*/
public class Frame_Main extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public Frame_Main() {
initComponents();
this.setResizable(false);
check_account_exists();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
Create_Account_btn1 = new javax.swing.JButton();
login_btn1 = new javax.swing.JButton();
exit_btn1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
login_btn2 = new javax.swing.JMenuItem();
Create_Account_btn2 = new javax.swing.JMenuItem();
delete_btn = new javax.swing.JMenuItem();
Show_Account_btn = new javax.swing.JMenuItem();
exit_btn2 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
about_btn = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Keep It Safe", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Purisa", 0, 13))); // NOI18N
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Version 2.0", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Purisa", 0, 13))); // NOI18N
Create_Account_btn1.setFont(new java.awt.Font("Purisa", 0, 13));
Create_Account_btn1.setText("Create Account"); // NOI18N
Create_Account_btn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Create_Account_btn1ActionPerformed(evt);
}
});
login_btn1.setFont(new java.awt.Font("Purisa", 0, 13));
login_btn1.setText("Login"); // NOI18N
login_btn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
login_btn1ActionPerformed(evt);
}
});
exit_btn1.setFont(new java.awt.Font("Purisa", 0, 13));
exit_btn1.setText("Exit"); // NOI18N
exit_btn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exit_btn1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(91, 91, 91)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(exit_btn1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
.addComponent(login_btn1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
.addComponent(Create_Account_btn1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
.addGap(86, 86, 86))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(Create_Account_btn1)
.addGap(18, 18, 18)
.addComponent(login_btn1)
.addGap(32, 32, 32)
.addComponent(exit_btn1)
.addContainerGap(32, Short.MAX_VALUE))
);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/image.png"))); // NOI18N
jLabel1.setText("jLabel1");
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel1MouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jMenu1.setText("File"); // NOI18N
jMenu1.setFont(new java.awt.Font("Purisa", 0, 13));
login_btn2.setFont(new java.awt.Font("Purisa", 0, 13));
login_btn2.setText("Login"); // NOI18N
login_btn2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
login_btn2ActionPerformed(evt);
}
});
jMenu1.add(login_btn2);
Create_Account_btn2.setFont(new java.awt.Font("Purisa", 0, 13));
Create_Account_btn2.setText("Create Account"); // NOI18N
Create_Account_btn2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Create_Account_btn2ActionPerformed(evt);
}
});
jMenu1.add(Create_Account_btn2);
delete_btn.setFont(new java.awt.Font("Purisa", 0, 13));
delete_btn.setText("Delete Account");
delete_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
delete_btnActionPerformed(evt);
}
});
jMenu1.add(delete_btn);
Show_Account_btn.setFont(new java.awt.Font("Purisa", 0, 13));
Show_Account_btn.setText("Show Accounts");
Show_Account_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Show_Account_btnActionPerformed(evt);
}
});
jMenu1.add(Show_Account_btn);
exit_btn2.setFont(new java.awt.Font("Purisa", 0, 13));
exit_btn2.setText("Exit"); // NOI18N
exit_btn2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exit_btn2ActionPerformed(evt);
}
});
jMenu1.add(exit_btn2);
jMenuBar1.add(jMenu1);
jMenu3.setText("Help"); // NOI18N
jMenu3.setFont(new java.awt.Font("Purisa", 0, 13));
about_btn.setFont(new java.awt.Font("Purisa", 0, 13));
about_btn.setText("About Keep It Safe"); // NOI18N
about_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
about_btnActionPerformed(evt);
}
});
jMenu3.add(about_btn);
jMenuBar1.add(jMenu3);
setJMenuBar(jMenuBar1);
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()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
public void change_label_true(){
login_btn1.setEnabled(true);
login_btn2.setEnabled(true);
delete_btn.setEnabled(true);
}
public void change_label_false(){
login_btn1.setEnabled(false);
login_btn2.setEnabled(false);
delete_btn.setEnabled(false);
}
//check if any accounts exists and loads them
private void check_account_exists(){
Keep_It_Safe.read=new OpenObject();
if(Keep_It_Safe.read.openfile());
if (Keep_It_Safe.accounts.isEmpty())
change_label_false();
}
private void Create_Account_btn2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Create_Account_btn2ActionPerformed
// TODO add your handling code here:
Frame_Create_Account obj2=new Frame_Create_Account(this);
obj2.setVisible(true);
}//GEN-LAST:event_Create_Account_btn2ActionPerformed
private void login_btn2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_login_btn2ActionPerformed
// TODO add your handling code here:
new Frame_Login(1,this,null).setVisible(true); // 1 for a login
//this.dispose();
}//GEN-LAST:event_login_btn2ActionPerformed
private void exit_btn2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exit_btn2ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_exit_btn2ActionPerformed
private void about_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_about_btnActionPerformed
// TODO add your handling code here:
new Frame_About().setVisible(true);
}//GEN-LAST:event_about_btnActionPerformed
private void Show_Account_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Show_Account_btnActionPerformed
// TODO add your handling code here:
new Frame_Search("Show Accounts").setVisible(true);
}//GEN-LAST:event_Show_Account_btnActionPerformed
private void delete_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delete_btnActionPerformed
// TODO add your handling code here:
new Frame_Search("Remove Account",this).setVisible(true);
}//GEN-LAST:event_delete_btnActionPerformed
private void exit_btn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exit_btn1ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_exit_btn1ActionPerformed
private void login_btn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_login_btn1ActionPerformed
// TODO add your handling code here:
new Frame_Login(1,this,null).setVisible(true); //1 for a login
//this.dispose();
}//GEN-LAST:event_login_btn1ActionPerformed
private void Create_Account_btn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Create_Account_btn1ActionPerformed
// TODO add your handling code here:
Frame_Create_Account obj2=new Frame_Create_Account(this);
obj2.setVisible(true);
}//GEN-LAST:event_Create_Account_btn1ActionPerformed
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
// TODO add your handling code here:
//Code to open URL
String[] browsers = { "google-chrome","firefox", "opera", "konqueror", "epiphany",
"seamonkey", "galeon", "kazehakase", "mozilla", "netscape" };
String url="http://psychok7.blogspot.com/";
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Mac OS")) {
Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL",
new Class[] {String.class});
openURL.invoke(null, new Object[] {url});
}
else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
else { //assume Unix or Linux
boolean found = false;
for (String browser : browsers)
if (!found) {
found = Runtime.getRuntime().exec(
new String[] {"which", browser}).waitFor() == 0;
if (found)
Runtime.getRuntime().exec(new String[] {browser, url});
}
if (!found)
throw new Exception(Arrays.toString(browsers));
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,
"Error attempting to launch web browser\n" + e.toString());
}
}//GEN-LAST:event_jLabel1MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame_Main().setVisible(true);
//new Play_Sound("sound.wav").start();
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton Create_Account_btn1;
private javax.swing.JMenuItem Create_Account_btn2;
private javax.swing.JMenuItem Show_Account_btn;
private javax.swing.JMenuItem about_btn;
private javax.swing.JMenuItem delete_btn;
private javax.swing.JButton exit_btn1;
private javax.swing.JMenuItem exit_btn2;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JButton login_btn1;
private javax.swing.JMenuItem login_btn2;
// End of variables declaration//GEN-END:variables
}