** SOLVED **
I am new to Java and still like it!
So, I'm just asking if anyone has an idea that could help me. So here is what I would like to do.
Now I am working on an application that can interact with my local site (change names, content, etc.). So what I like is to show JOptionPane.showConfirmDialogand enter the username and password.
So if the username or password is incorrect, I would like to show JOptionPane.showMessageDialog, but when they click Okto tell them that the information is incorrect, it showConfirmDialogdisappears!
Any ideas guys ?! Here is my code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class javaTesting extends JFrame {
public JFrame mrFrame;
public int enter;
public JPanel mrPanel;
public javaTesting() throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cms","root","");
} catch (SQLException e){
System.out.println(e.getMessage());
}
mrFrame = new JFrame();
mrPanel = new JPanel();
mrPanel.setLayout(new GridLayout(4,1));
JLabel user = new JLabel("Username");
mrPanel.add(user);
JTextField user_input = new JTextField(30);
mrPanel.add(user_input);
JLabel pass = new JLabel("Password");
mrPanel.add(pass);
JTextField pw_input = new JPasswordField(30);
mrPanel.add(pw_input);
mrFrame.setSize(700,700);
mrFrame.setLocationRelativeTo(null);
mrFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mrFrame.setResizable(false);
input();
if(enter == JOptionPane.OK_OPTION)
{
JOptionPane.showMessageDialog(null, "You clicked ok!");
input();
} else {
System.exit(1);
}
}
public void input()
{
enter = (int) JOptionPane.showConfirmDialog(mrFrame,mrPanel,"Login Cridantiels",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
}
public static void main(String agrs[]) throws Exception
{
new javaTesting();
}
}
So this is what I did, and it seems to be normal for me, I don’t know if it is wrong. However, it works:]
do{
input();
if(enter == JOptionPane.OK_OPTION)
{
JOptionPane.showMessageDialog(null, "You clicked ok!");
} else {
System.exit(1);
}
} while(enter != JOptionPane.CANCEL_OPTION);