need help with this code i wrote. it executes but not like i want it too. A folder is suppost install on the desktop before it ask the user to log in, but in my case its not installing it till after. The other promblem is once the user logs in the folder on the desktop should open, displaying the contents in the folder, but thats not happening. can any one tell me what im doing wrong and show me how to correct it. I have been working this issue for the last two day with no luck.
i tried having the file created before before the doMyAction is performed, but it gives tons of errors.
Hope someone can help
package javaapplication32;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class BoxX {
private static JTextField user;
private static JPasswordField password;
public static void main(String args[]) {
JFrame f = new JFrame("BoxX");
Container content = f.getContentPane();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
content.setLayout(new GridLayout(3, 1));
JButton mybtn = new JButton("Log in");
mybtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e) {
doMyAction();
}
}
);
user = new JTextField(15);
password = new JPasswordField(15);
panel1.add(new JLabel("Username"));
panel1.add(user);
panel2.add(new JLabel("Password"));
panel2.add(password);
panel3.add(mybtn);
content.add(panel1);
content.add(panel2);
content.add(panel3);
f.setSize(300, 200);
f.setVisible(true);
}
public static void doMyAction() {
if (user.getText().equals ("Solris") &&
password.getText().equals ("hi123")) {
JOptionPane.showMessageDialog (null, "You may enter");
}
File data = new File("C:/Users/Solris/Desktop/data");
data.mkdir();
try {
FileWriter d = new FileWriter(data);
} catch (IOException e) {
e.printStackTrace();
}
File f = null;
Scanner scan = null;
try{
f = new File("path");
scan = new Scanner(f);
}
catch(Exception e){
System.out.println("Exception");
System.exit(0);
}
JOptionPane.showMessageDialog(null, "You May Not Enter", "NOT GOOD", JOptionPane.PLAIN_MESSAGE); //display incorrect password message
}
}

New Topic/Question
Reply




MultiQuote







|