Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bruno.javaserialgui.ventanas;
- @SuppressWarnings("serial")
- public class ventanaPrincipal extends JFrame implements ActionListener{
- JPanel jpanel;
- JFrame ventanaPrincipal;
- Dimension d;
- ImageIcon im;
- public static JTextField numSerial;
- JButton bt;
- @SuppressWarnings("unused")
- public static void main(String[] args){
- ventanaPrincipal ventanaPrincipal = new ventanaPrincipal("Java Serial Gui");
- }
- public ventanaPrincipal(String titulo){
- jpanel = new JPanel();
- jpanel.setLayout(null);
- jpanel.setBackground(Color.lightGray);
- ventanaPrincipal = new JFrame(titulo);
- d = new Dimension(); //Objeto para obtener el tamaño de la ventana
- //im = new ImageIcon("ruta");
- numSerial = new JTextField();
- numSerial.setBounds(new Rectangle(25, 15, 230, 21));
- numSerial.setText("Ingrese el serial");
- numSerial.setEditable(true);
- numSerial.setHorizontalAlignment(JTextField.LEFT);
- bt = new JButton("Comprobar serial");
- bt.setLayout(null);
- bt.setBounds(50, 50, 160, 30);
- bt.addActionListener(this);
- bt.setEnabled(true);
- ventanaPrincipal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //ventanaPrincipal.setIconImage(im.getImage()); //Añadimos un icono a la ventan
- ventanaPrincipal.setResizable(true); //Configuramos si se puede redimensionar la ventana
- ventanaPrincipal.setLocation((int) ((d.getWidth()/2)+290), 50); //para ubicar inicialmente donde se muestra la ventana (x,y)
- ventanaPrincipal.setSize(290, 150); //Configurando el tamaño de la ventana
- ventanaPrincipal.setVisible(true);
- ventanaPrincipal.add(jpanel);
- ventanaPrincipal.getContentPane();
- jpanel.add(numSerial, null);
- jpanel.add(bt, null);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == bt){
- comprobarSerial.main();
- }else{
- JOptionPane.showMessageDialog(null, "Error");
- }
- }
- }
- package com.bruno.javaserialgui;
- public static void main(){
- String numSerial = ventanaPrincipal.numSerial.getText();
- //A este if no entra el programa
- if(numSerial == "test"){
- System.out.println("hola");
- VentanaAceptado.init();
- }
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost/seriales","root","");
- PreparedStatement ps = con.prepareStatement(
- "SELECT usado FROM serial WHERE serial = ?",
- ResultSet.TYPE_SCROLL_SENSITIVE, // Esto asegura que el ResultSet pueda ser recorrido en cualquier dirección (adelante o atrás)
- ResultSet.CONCUR_READ_ONLY // Esto asegura que el ResultSet sea de sólo lectura
- );
- ps.setString(1, numSerial);
- ResultSet rs = ps.executeQuery();
- rs.beforeFirst(); // Coloca el cursor ANTES de la primera fila del ResultSet
- // (para esto es que se requiere la opción TYPE_SCROLL_SENSITIVE)
- if(rs.first()){
- if(rs.getInt("usado") == 0){ //0 no usado 1 usado
- VentanaAceptado.init();
- }else if(rs.getInt("usado") == 1) {
- VentanaDenegado.init();
- }else{
- Exception ex = new Exception("Error");
- throw ex;
- }
- }
- }catch(Exception ex){
- JOptionPane.showMessageDialog(null, ex);
- ex.printStackTrace(System.out);
- }
- }
- package com.bruno.javaserialgui.ventanas;
- @SuppressWarnings("serial")
- public class VentanaAceptado extends JFrame{
- JPanel jpanel;
- JFrame ventanaAceptado;
- Dimension d;
- JComboBox<String> cb;
- JTextField tf;
- public static void init(){
- @SuppressWarnings("unused")
- VentanaAceptado ventanaAceptado = new VentanaAceptado("Serial aceptado");
- }
- public VentanaAceptado(String titulo){
- jpanel = new JPanel();
- jpanel.setLayout(null);
- jpanel.setBackground(Color.lightGray);
- cb.setBounds(HEIGHT, WIDTH, SOMEBITS, HEIGHT);
- cb.addItem("Opcion 1");
- cb.addItem("Opcion 2");
- cb.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e){
- tf.setText(cb.getSelectedItem().toString());
- }
- });
- ventanaAceptado = new JFrame(titulo);
- d = new Dimension(); //Objeto para obtener el tamaño de la ventana
- ventanaAceptado.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //ventanaPrincipal.setIconImage(im.getImage()); //Añadimos un icono a la ventan
- ventanaAceptado.setResizable(true); //Configuramos si se puede redimensionar la ventana
- ventanaAceptado.setLocation((int) ((d.getWidth()/2)+290), 50); //para ubicar inicialmente donde se muestra la ventana (x,y)
- ventanaAceptado.setSize(290, 150); //Configurando el tamaño de la ventana
- ventanaAceptado.setVisible(true);
- ventanaAceptado.add(jpanel);
- ventanaAceptado.getContentPane();
- jpanel.add(cb, null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement