Olá Rodrigo!
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author Lucas
*/
public class Entrada_dados extends javax.swing.JFrame {
/**
* Creates new form Entrada_dados1
*/
public Entrada_dados() {
initComponents();
setIcon();
this.EntradadadosPerfil.removeAllItems();
try {
Class.forName(driver);
Connection con = DriverManager.getConnection(url, user, pass);
Statement Sent = con.createStatement();
ResultSet rs = Sent.executeQuery("Select * from Cadastro_Testes");
while (rs.next()) {
this.EntradadadosPerfil.addItem(rs.getString("TCPERFIL"));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://VARWSQL1;databaseName=DADOSPROD";
String user = "PROD";
String pass = "";
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
EntradadadosVoltar = new javax.swing.JButton();
EntradadadosPerfil = new javax.swing.JComboBox<>();
EntradadadosData = new javax.swing.JFormattedTextField();
EntradadadosHora = new javax.swing.JFormattedTextField();
EntradadadosRegistro = new javax.swing.JTextField();
EntradadadosIr = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Perfil:");
jLabel2.setText("Data:");
jLabel3.setText("Hora:");
jLabel4.setText("Registro:");
EntradadadosVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Back_16px_521260_easyicon.net.png"))); // NOI18N
EntradadadosVoltar.setText("Voltar");
EntradadadosVoltar.setMaximumSize(new java.awt.Dimension(83, 25));
EntradadadosVoltar.setMinimumSize(new java.awt.Dimension(83, 25));
EntradadadosVoltar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradadadosVoltarActionPerformed(evt);
}
});
EntradadadosPerfil.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
EntradadadosPerfil.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradadadosPerfilActionPerformed(evt);
}
});
try {
EntradadadosData.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
EntradadadosData.setHorizontalAlignment(javax.swing.JTextField.CENTER);
EntradadadosData.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradadadosDataActionPerformed(evt);
}
});
try {
EntradadadosHora.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
EntradadadosHora.setHorizontalAlignment(javax.swing.JTextField.CENTER);
EntradadadosHora.setText("");
EntradadadosHora.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradadadosHoraActionPerformed(evt);
}
});
EntradadadosIr.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/navigate_next_24px_1182069_easyicon.net.png"))); // NOI18N
EntradadadosIr.setText("Ir");
EntradadadosIr.setMaximumSize(new java.awt.Dimension(83, 25));
EntradadadosIr.setMinimumSize(new java.awt.Dimension(83, 25));
EntradadadosIr.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradadadosIrActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(EntradadadosPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(EntradadadosRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(EntradadadosHora, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(EntradadadosData, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(EntradadadosVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
.addComponent(EntradadadosIr, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(EntradadadosPerfil, 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.LEADING)
.addComponent(jLabel2)
.addComponent(EntradadadosData, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(EntradadadosHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(EntradadadosRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(EntradadadosVoltar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(EntradadadosIr, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void EntradadadosVoltarActionPerformed(java.awt.event.ActionEvent evt) {
Menu tela = new Menu();
tela.setVisible(true);
dispose();
}
private void EntradadadosIrActionPerformed(java.awt.event.ActionEvent evt) {
if(EntradadadosData.getText().trim().length() < 8) {
JOptionPane.showMessageDialog(null, "Por favor, informar campo Data", "Informação", JOptionPane.INFORMATION_MESSAGE);
EntradadadosData.requestFocusInWindow();
EntradadadosData.setText(null);
} else if(EntradadadosHora.getText().trim().length() < 4) {
JOptionPane.showMessageDialog(null, "Por favor, informar campo Hora", "Informação", JOptionPane.INFORMATION_MESSAGE);
EntradadadosHora.requestFocusInWindow();
EntradadadosHora.setText(null);
} else if (EntradadadosRegistro.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "Por favor, informar campo Registro", "Informação", JOptionPane.INFORMATION_MESSAGE);
EntradadadosRegistro.requestFocus();
EntradadadosRegistro.setText(null);
} else {
CadResultado tela = new CadResultado(EntradadadosPerfil.getSelectedItem().toString(), EntradadadosData.getText(), EntradadadosHora.getText(), EntradadadosRegistro.getText());
tela.setVisible(true);
dispose();
}
Esse é o código, mas ele é apenas uma tela para chamar outra tela.
quando eu deixo apenas isso
CadResultado tela = new CadResultado ();
tela.setVisible(true);
dispose();
ele abre normalmentee com as alterações que fiz, mas quando deixo assim
CadResultado tela = new CadResultado(EntradadadosPerfil.getSelectedItem().toString(), EntradadadosData.getText(), EntradadadosHora.getText(), EntradadadosRegistro.getText());
tela.setVisible(true);
dispose();
ele abre sem as alterações