Ciao a tutti,
Ho un problema!
sto creando un'applicazione in java con eclipse ho creato e connesso il database.
Ho creato una pagina che consenta di effettuare la login con 2 JtextField e 1 Jbutton "entra". Qualcuno può consigliarmi su come gestire la login??
il codice della pagina è:
package org.schedule.iu;
import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
public class Login {
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="38,21"
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu editMenu = null;
private JMenu helpMenu = null;
private JMenuItem exitMenuItem = null;
private JMenuItem aboutMenuItem = null;
private JMenuItem cutMenuItem = null;
private JMenuItem copyMenuItem = null;
private JMenuItem pasteMenuItem = null;
private JMenuItem saveMenuItem = null;
private JPasswordField jPasswordField1;
private JButton jButton1;
private JLabel jLabel3;
private JLabel jLabel2;
private JTextField jTextField2;
private JLabel jLabel1;
private JDialog aboutDialog = null;
private JPanel aboutContentPane = null;
private JLabel aboutVersionLabel = null;
private JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
FormLayout jFrameLayout = new FormLayout(
"max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu)",
"max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu)");
jFrame.getContentPane().setLayout(jFrameLayout);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(1025, 588);
jFrame.setTitle("Schedule");
jFrame.setPreferredSize(new java.awt.Dimension(1025, 588));
jFrame.getContentPane().setBackground(new java.awt.Color(0,128,255));
jFrame.getContentPane().add(getJLabel1(), new CellConstraints("4, 1, 1, 1, default, default"));
jFrame.getContentPane().add(getJTextField2(), new CellConstraints("4, 2, 1, 1, default, default"));
jFrame.getContentPane().add(getJPasswordField1(), new CellConstraints("4, 3, 1, 1, default, default"));
jFrame.getContentPane().add(getJLabel2(), new CellConstraints("1, 2, 1, 1, right, top"));
jFrame.getContentPane().add(getJLabel3(), new CellConstraints("1, 3, 1, 1, right, top"));
jFrame.getContentPane().add(getJButton1(), new CellConstraints("4, 4, 1, 1, default, default"));
}
return jFrame;
}
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getEditMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("File");
fileMenu.add(getSaveMenuItem());
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
private JMenu getEditMenu() {
if (editMenu == null) {
editMenu = new JMenu();
editMenu.setText("Edit");
editMenu.add(getCutMenuItem());
editMenu.add(getCopyMenuItem());
editMenu.add(getPasteMenuItem());
}
return editMenu;
}
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("Help");
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
private JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
return exitMenuItem;
}
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog aboutDialog = getAboutDialog();
aboutDialog.pack();
Point loc = getJFrame().getLocation();
loc.translate(20, 20);
aboutDialog.setLocation(loc);
aboutDialog.setVisible(true);
}
});
}
return aboutMenuItem;
}
private JDialog getAboutDialog() {
if (aboutDialog == null) {
aboutDialog = new JDialog(getJFrame(), true);
aboutDialog.setTitle("About");
aboutDialog.setContentPane(getAboutContentPane());
}
return aboutDialog;
}
private JPanel getAboutContentPane() {
if (aboutContentPane == null) {
aboutContentPane = new JPanel();
aboutContentPane.setLayout(new BorderLayout());
aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
}
return aboutContentPane;
}
private JLabel getAboutVersionLabel() {
if (aboutVersionLabel == null) {
aboutVersionLabel = new JLabel();
aboutVersionLabel.setText("Version 1.0");
aboutVersionLabel.setHorizontalAlignment(SwingCons tants.CENTER);
}
return aboutVersionLabel;
}
private JMenuItem getCutMenuItem() {
if (cutMenuItem == null) {
cutMenuItem = new JMenuItem();
cutMenuItem.setText("Cut");
cutMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_X,
Event.CTRL_MASK, true));
}
return cutMenuItem;
}
private JMenuItem getCopyMenuItem() {
if (copyMenuItem == null) {
copyMenuItem = new JMenuItem();
copyMenuItem.setText("Copy");
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_C,
Event.CTRL_MASK, true));
}
return copyMenuItem;
}
private JMenuItem getPasteMenuItem() {
if (pasteMenuItem == null) {
pasteMenuItem = new JMenuItem();
pasteMenuItem.setText("Paste");
pasteMenuItem.setAccelerator(KeyStroke.getKeyStrok e(KeyEvent.VK_V,
Event.CTRL_MASK, true));
}
return pasteMenuItem;
}
private JMenuItem getSaveMenuItem() {
if (saveMenuItem == null) {
saveMenuItem = new JMenuItem();
saveMenuItem.setText("Save");
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_S,
Event.CTRL_MASK, true));
}
return saveMenuItem;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Login application = new Login();
application.getJFrame().setVisible(true);
}
});
}
private JLabel getJLabel1() {
if(jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText(" " +
"");
jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource( "img/schedule.png")));
}
return jLabel1;
}
private JTextField getJTextField2() {
if(jTextField2 == null) {
jTextField2 = new JTextField();
}
return jTextField2;
}
private JPasswordField getJPasswordField1() {
if(jPasswordField1 == null) {
jPasswordField1 = new JPasswordField();
}
return jPasswordField1;
}
private JLabel getJLabel2() {
if(jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Username");
jLabel2.setFont(new java.awt.Font("Comic Sans MS",1,18));
jLabel2.setBackground(new java.awt.Color(0,128,192));
jLabel2.setLocation(new java.awt.Point(0, 0));
jLabel2.setForeground(new java.awt.Color(255,255,255));
}
return jLabel2;
}
private JLabel getJLabel3() {
if(jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("Password");
jLabel3.setFont(new java.awt.Font("Comic Sans MS",1,18));
jLabel3.setForeground(new java.awt.Color(255,255,255));
}
return jLabel3;
}
private JButton getJButton1() {
if(jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("entra");
}
return jButton1;
}
}

Rispondi quotando