package music.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import util.Constants;
import music.search.GoogleMusicSearcher;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* LoginFrame.java
*
* Created on Nov 14, 2010, 3:44:57 PM
*/
/**
*
* @author liutao
*/
public class LoginFrame extends javax.swing.JFrame {
/** Creates new form LoginFrame */
public LoginFrame() {
initComponents();
setTitle("Login");
setResizable(false);
setLocation(400, 400);
setVisible(true);
}
// check where to put download file
public void init()
{
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("choose download directory");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
chooser.showOpenDialog(this);
File file = chooser.getSelectedFile();
if(file != null)
{
if(!file.canRead() || !file.canWrite())
{
JOptionPane.showMessageDialog(this, "permission denied");
return ;
}
//System.out.println(file.getAbsolutePath());
Constants.DOWNLOAD_DIR = file.getAbsolutePath()+"/";
run();
}
}
public void run()
{
MyFrame frame = new MyFrame();
frame.setMusicSearcher(new GoogleMusicSearcher());
frame.setLocation(300,300);
frame.setVisible(true);
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
passwdField = new javax.swing.JPasswordField();
nameField = new javax.swing.JTextField();
okButton = new javax.swing.JButton();
notifyLabel = new javax.swing.JLabel();
//setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel1.setText("Username");
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel2.setText("Password");
passwdField.setFont(new java.awt.Font("DejaVu Sans", 0, 14)); // NOI18N
passwdField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
passwdFieldActionPerformed(evt);
}
});
nameField.setFont(new java.awt.Font("DejaVu Sans", 0, 14)); // NOI18N
okButton.setText("OK");
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
if(nameField.getText().equals("abc") && passwdField.getText().equals("abc"))
{
init();
dispose();
}
else
notifyLabel.setText("name or passwd error!");
}
});
notifyLabel.setForeground(new java.awt.Color(211, 48, 58));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(passwdField, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(notifyLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {nameField, passwdField});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(notifyLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(passwdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(okButton)
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, jLabel2});
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {nameField, passwdField});
pack();
}// </editor-fold>
private void passwdFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new LoginFrame();
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel notifyLabel;
private javax.swing.JTextField nameField;
private javax.swing.JButton okButton;
private javax.swing.JPasswordField passwdField;
// End of variables declaration
}