实际上我不知道该方法在哪里起作用,但是在编程时间的某个时刻getText()
停止了工作。
与数据库的连接有效,但是我需要做一些咨询。
我尝试在其他框架和代码中完成
String Example = jTextField1.getText();
jLabel1.setText(Example);
正在工作,所以如果我用它的话有什么区别。
String Placas = tfPlacas.getText();
tfMarca.setText(Placas);
代码
package interfaces;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.sql.*;
import javax.swing.JOptionPane;
public class Ingresar_Vehiculo extends javax.swing.JFrame {
private Connection conexion;
private Statement enunciado;
private ResultSet resultado;
public void connectarBD(){
try{
Class.forName("com.mysql.jdbc.Driver");
conexion=DriverManager.getConnection("jdbc:mysql://localhost:3306/estacionamiento","root","");
if(conexion!=null){
enunciado=conexion.createStatement();
JOptionPane.showMessageDialog(null,"Conexion Realizada");
}
} catch(ClassNotFoundException e){
JOptionPane.showMessageDialog(null,"No se pudo realizar la conexion");
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"No se pudo realizar la conexion");
}
}
int timeRun =0;
public Ingresar_Vehiculo() {
initComponents();
setSize(1060,666);
initComponents();
new Thread()
{
public void run()
{
while(timeRun == 0)
{
Calendar cal = new GregorianCalendar();
int hour = cal.get(Calendar.HOUR);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
int AM_PM = cal.get(Calendar.AM_PM);
int año = cal.get(Calendar.YEAR);
int mes = cal.get(Calendar.MONTH);
int dia = cal.get(Calendar.DAY_OF_MONTH);
String dia_Noche="";
if(AM_PM == 1)
{
dia_Noche = "PM";
}
else
{
dia_Noche = "AM";
}
String time = dia + "/" + mes + "/" + año + " " + hour + ":" + min + ":" + sec + " " + dia_Noche;
reloj.setText(time);
}
}
}.start();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Tipo = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
btnSalir = new javax.swing.JButton();
lbLogotipo = new javax.swing.JLabel();
regresar = new javax.swing.JButton();
reloj = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
lbTipoServicio = new javax.swing.JLabel();
estacionamiento = new javax.swing.JRadioButton();
jRadioButton1 = new javax.swing.JRadioButton();
lbplasas = new javax.swing.JLabel();
tfPlacas = new javax.swing.JTextField();
lbmodelo = new javax.swing.JLabel();
tfModelo = new javax.swing.JTextField();
lbcolor = new javax.swing.JLabel();
tfMarca = new javax.swing.JTextField();
tfColor = new javax.swing.JTextField();
lbmarca1 = new javax.swing.JLabel();
btguardar = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
btnSalir.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
btnSalir.setText("SALIR");
btnSalir.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnSalirMouseClicked(evt);
}
});
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(evt);
}
});
lbLogotipo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaces/Motor Park logo ver1.jpg"))); // NOI18N
lbLogotipo.setText("jLabel2");
regresar.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
regresar.setText("REGRESAR");
regresar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
regresarMouseClicked(evt);
}
});
reloj.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
reloj.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
reloj.setText("RELOJ");
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
jLabel1.setText("Introdusca los Datos Solicitados");
lbTipoServicio.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbTipoServicio.setText("Tipo de servicio");
estacionamiento.setBackground(new java.awt.Color(255, 255, 255));
Tipo.add(estacionamiento);
estacionamiento.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
estacionamiento.setText("Estacionamiento");
jRadioButton1.setBackground(new java.awt.Color(255, 255, 255));
Tipo.add(jRadioButton1);
jRadioButton1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jRadioButton1.setText("Pension");
lbplasas.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbplasas.setText("Placas");
tfPlacas.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbmodelo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbmodelo.setText("Modelo");
tfModelo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbcolor.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbcolor.setText("Color");
tfMarca.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
tfColor.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbmarca1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lbmarca1.setText("Marca");
btguardar.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
btguardar.setText("BUSCAR PLACAS");
btguardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btguardarActionPerformed(evt);
}
});
jButton1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jButton1.setText("INGRESAR VEHICULO");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jButton2.setText("SALIDA DE VEHICULO");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbTipoServicio)
.addComponent(lbplasas)
.addComponent(lbmodelo))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(estacionamiento)
.addGap(18, 18, 18)
.addComponent(jRadioButton1))
.addComponent(tfPlacas)
.addComponent(tfModelo))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbcolor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbmarca1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tfColor, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
.addComponent(tfMarca)))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(reloj, javax.swing.GroupLayout.PREFERRED_SIZE, 423, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 295, Short.MAX_VALUE)
.addComponent(lbLogotipo, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(regresar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(53, 53, 53)
.addComponent(btguardar)
.addGap(187, 187, 187)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(53, 53, 53))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lbLogotipo, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(reloj, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbTipoServicio)
.addComponent(estacionamiento)
.addComponent(jRadioButton1))
.addGap(41, 41, 41)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbplasas)
.addComponent(tfPlacas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbmarca1))
.addGap(23, 23, 23)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbmodelo)
.addComponent(tfModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbcolor))
.addGap(88, 88, 88)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btguardar)
.addComponent(jButton1)
.addComponent(jButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnSalir)
.addComponent(regresar))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnSalirMouseClicked(java.awt.event.MouseEvent evt) {
System.exit(0);
}
private void regresarMouseClicked(java.awt.event.MouseEvent evt) {
Principal regresar= new Principal();
regresar.setVisible(true);
this.dispose();
}
private void btguardarActionPerformed(java.awt.event.ActionEvent evt) {
String Placas = tfPlacas.getText();
tfMarca.setText(Placas);
connectarBD();
try{
resultado=enunciado.executeQuery("SELECT * FROM vehiculos WHERE placas='"+ Placas +"'");
if(resultado.next()){
JOptionPane.showMessageDialog(null,"Se encontraron datos"+ Placas);
}else{
JOptionPane.showMessageDialog(null,"No se encontraron datos"+ Placas);
}
enunciado.close();
conexion.close();
} catch(SQLException ex) {
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Ingresar_Vehiculo().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup Tipo;
private javax.swing.JButton btguardar;
private javax.swing.JButton btnSalir;
private javax.swing.JRadioButton estacionamiento;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JLabel lbLogotipo;
private javax.swing.JLabel lbTipoServicio;
private javax.swing.JLabel lbcolor;
private javax.swing.JLabel lbmarca1;
private javax.swing.JLabel lbmodelo;
private javax.swing.JLabel lbplasas;
private javax.swing.JButton regresar;
private javax.swing.JLabel reloj;
public javax.swing.JTextField tfColor;
public javax.swing.JTextField tfMarca;
public javax.swing.JTextField tfModelo;
private javax.swing.JTextField tfPlacas;
// End of variables declaration
}