Salve,
come prima cosa saluto tutti ,sono nuova nel forum,
ho già letto una discussione riguardo questo argomento ma non sono riuscita a risolvere il mio problema. Riporto il mio codice:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.Date;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import magazzino.ListaUtenteMap;
import magazzino.Utente;
public class FrameIniziale extends JFrame{
private JButton jButton1;
private JLabel jLabel1;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JLabel jLabel7;
private JPanel jPanel1;
private JPasswordField jPasswordField1;
private JTextField jTextField1;
static Utente utente1;
public static Utente getUt(){
return utente1;
}
public FrameIniziale() {
super();
this.setTitle("Inventario");
initComponents();
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setLocation(screenWidth / 4, screenHeight / 4);
Image img = kit.getImage("C:\\labpoo\\magazzino\\immagini\\logo.jpg");
setIconImage(img);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
}
private void initComponents() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
} catch (Exception e) { }
jPanel1 = new JPanel();
jTextField1 = new JTextField();
jPasswordField1 = new JPasswordField();
jButton1 = new JButton();
jLabel1 = new JLabel("",SwingConstants.CENTER);
jLabel3 = new JLabel("",SwingConstants.CENTER);
jLabel4 = new JLabel();
jLabel5 = new JLabel("",SwingConstants.CENTER);
jLabel6 = new JLabel("",SwingConstants.CENTER);
jLabel7 = new JLabel("",SwingConstants.CENTER);
jPanel1.setLayout(null);
jPanel1.setBackground(new Color(255, 255, 255));
jTextField1.setFont(new Font("Georgia", 0, 11));
jTextField1.setText("Inserisci user");
jPanel1.add(jTextField1);
jTextField1.setBounds(200, 130, 130, 30);
jTextField1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
jTextFieldMouseClicked(evt);
}
});
jPasswordField1.setText("Password");
jPanel1.add(jPasswordField1);
jPasswordField1.setBounds(200, 180, 130, 30);
jPasswordField1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
jPasswordFieldMouseClicked(evt);
}
});
jButton1.setFont(new Font("Georgia", 0, 12));
jButton1.setText("Login");
jButton1.setBounds(160, 250, 80, 30);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt){
jButtonActionPerformed(evt);
}
});
jPanel1.add(jButton1);
jLabel1.setIcon(new ImageIcon("C:\\labpoo\\magazzino\\immagini\\minilogo.jpg"));
jPanel1.add(jLabel1);
jLabel1.setBounds(0, 0, 96, 94);
jLabel4.setIcon(new ImageIcon("C:\\labpoo\\magazzino\\immagini\\minilogo2.jpg"));
jPanel1.add(jLabel4);
jLabel4.setBounds(305, 0, 96, 94);
jLabel3.setFont(new Font("Georgia", 1, 12));
jLabel3.setText("");
jPanel1.add(jLabel3);
jLabel3.setBounds(135, 220, 130, 30);
jLabel5.setFont(new Font("Chintzy CPU BRK", 0, 32));
jPanel1.add(jLabel5);
jLabel5.setBounds(100, 10, 210, 75);
jLabel5.setText("PC WORLD");
jLabel6.setFont(new Font("Georgia", 1, 13));
jPanel1.add(jLabel6);
jLabel6.setText("User");
jLabel6.setBounds(50, 135, 130, 20);
jPanel1.add(jLabel7);
jLabel7.setText("Password");
jLabel7.setBounds(50, 185, 130, 20);
jLabel7.setFont(new Font("Georgia", 1, 13));
this.getContentPane().add(jPanel1);
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
);
pack();
}
private void jButtonActionPerformed(ActionEvent evt){
String user=jTextField1.getText();
char []pass=jPasswordField1.getPassword();
String password="";
for(int i=0;i<pass.length;i++)
password+=pass
;
ListaUtenteMap map=new ListaUtenteMap();
try{
map.caricaUtenti("C:\\labpoo\\magazzino\\progetto\\ListaUtenteMap.lum");
}catch(IOException ioe){}
catch (ClassNotFoundException cnfe){}
Utente u=map.ricerca(user);
String user2=u.getUser();
String pass2=u.getPassword();
if(user.equals(user2) && password.equals(pass2) && u.getAmministratore()){
utente1=u;
new FrameAmministratore();
this.dispose();
}
else if(user.equals(user2) && password.equals(pass2) && !u.getAmministratore()){
utente1 = u;
new FrameCercaRicambioUtente();
this.dispose();
}
else{
jLabel3.setText("Dati non validi");
}
}
private void jTextFieldMouseClicked(MouseEvent evt) {
jTextField1.setText("");
}
private void jPasswordFieldMouseClicked(MouseEvent evt) {
jPasswordField1.setText("");
}
public static void main(String args[]) {
new FrameIniziale();
}
}
Non sono riuscita ad inserire un'immagine presa da pc e non web come sfondo...
Potete aiutarmi?