Meu código todo é esse:
package fármacos;
import javax.swing.JOptionPane;
public class Usuário extends javax.swing.JFrame {
public Usuário() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jLabel1 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
usuario = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
senha = new javax.swing.JPasswordField();
acessar = new javax.swing.JButton();
cancelar = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 48)); // NOI18N
jLabel1.setForeground(new java.awt.Color(51, 255, 51));
jLabel1.setText(" Fármacos");
jLabel5.setIcon(new javax.swing.ImageIcon("C:\\xti\\farmaco3.jpg")); // NOI18N
jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 0, 0));
jLabel7.setText("Login:");
jLabel8.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 0, 0));
jLabel8.setText("Usuário:");
usuario.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
usuarioActionPerformed(evt);
}
});
jLabel9.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
jLabel9.setForeground(new java.awt.Color(255, 0, 0));
jLabel9.setText("Senha:");
senha.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
senhaActionPerformed(evt);
}
});
acessar.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
acessar.setForeground(new java.awt.Color(51, 255, 51));
acessar.setText("Acessar");
acessar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acessarActionPerformed(evt);
}
});
cancelar.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
cancelar.setForeground(new java.awt.Color(0, 0, 255));
cancelar.setText("Cancelar");
cancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelarActionPerformed(evt);
}
});
jLabel2.setText(" Todos os direitos reservados @ Joaquim Neto S/A ");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(acessar)
.addGap(18, 18, 18)
.addComponent(cancelar))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel9)
.addGap(18, 18, 18)
.addComponent(senha))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 47, Short.MAX_VALUE))
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(usuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(senha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(acessar)
.addComponent(cancelar))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void senhaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void acessarActionPerformed(java.awt.event.ActionEvent evt) {
if (usuario.getText().equals(“teste”) && senha.getText().equals(“123”)){
Prinipal prinipal = new Prinipal();
prinipal.setVisible(true);
this.dispose();
JOptionPane.showMessageDialog(null, “Acesso Garantido!”);
}else{
JOptionPane.showMessageDialog(null, "Acesso Negado!");
}
}
private void cancelarActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void usuarioActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(() -> {
new Usuário().setVisible(true);
});
}
// Variables declaration - do not modify
private javax.swing.JButton acessar;
private javax.swing.JButton cancelar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPasswordField senha;
private javax.swing.JTextField usuario;
// End of variables declaration
}
O error agora que esta dando é só em executar depois testar projeto:
No tests executed.
test-report:
test:
CONSTRUÍDO COM SUCESSO (tempo total: 4 segundos)