|
|
@ -0,0 +1,276 @@ |
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
import java.awt.EventQueue; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
import javax.swing.JTextArea; |
|
|
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
|
|
import javax.swing.table.DefaultTableModel; |
|
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
|
import javax.swing.JTextField; |
|
|
|
|
|
import javax.swing.JComboBox; |
|
|
|
|
|
import javax.swing.DefaultComboBoxModel; |
|
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
import java.awt.event.WindowAdapter; |
|
|
|
|
|
import java.awt.event.WindowEvent; |
|
|
|
|
|
import java.awt.event.WindowListener; |
|
|
|
|
|
import java.io.BufferedInputStream; |
|
|
|
|
|
import java.io.BufferedWriter; |
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.FileWriter; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.ObjectInputStream; |
|
|
|
|
|
import java.io.ObjectOutputStream; |
|
|
|
|
|
import java.sql.DriverManager; |
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
import java.sql.Statement; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
|
|
|
|
|
|
|
public class Ventana2 extends JFrame { |
|
|
|
|
|
|
|
|
|
|
|
private JPanel contentPane; |
|
|
|
|
|
static JTextField casilla; |
|
|
|
|
|
static JButton boton_FabricaCoche; |
|
|
|
|
|
static JComboBox comboBox_Marca; |
|
|
|
|
|
static JComboBox comboBox_Modelo; |
|
|
|
|
|
static JComboBox comboBox_Color; |
|
|
|
|
|
static JTextField textKm; |
|
|
|
|
|
static JLabel lblTexto; |
|
|
|
|
|
static JButton btnModificar; |
|
|
|
|
|
|
|
|
|
|
|
static ArrayList<Coche> arr = new ArrayList<Coche>(); |
|
|
|
|
|
static ArrayList<Integer> numeroCoches = new ArrayList<Integer>(5); |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
public void run() { |
|
|
|
|
|
try { |
|
|
|
|
|
Ventana2 frame = new Ventana2(); |
|
|
|
|
|
frame.setVisible(true); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Ventana2() { |
|
|
|
|
|
addWindowListener((WindowListener) new WindowAdapter() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void windowClosing(WindowEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
//Ventana vmenu = new Ventana(); |
|
|
|
|
|
//vmenu.setVisible(true); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
setTitle("CREACION DE COCHE"); |
|
|
|
|
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); |
|
|
|
|
|
setBounds(100, 100, 450, 332); |
|
|
|
|
|
contentPane = new JPanel(); |
|
|
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
|
|
|
|
setContentPane(contentPane); |
|
|
|
|
|
contentPane.setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lblNewLabel = new JLabel("Matricula"); |
|
|
|
|
|
lblNewLabel.setBounds(27, 97, 63, 14); |
|
|
|
|
|
contentPane.add(lblNewLabel); |
|
|
|
|
|
|
|
|
|
|
|
casilla = new JTextField(); |
|
|
|
|
|
casilla.setColumns(10); |
|
|
|
|
|
casilla.setBounds(100, 94, 113, 20); |
|
|
|
|
|
contentPane.add(casilla); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lblNewLabel_1 = new JLabel("Marca"); |
|
|
|
|
|
lblNewLabel_1.setBounds(27, 129, 46, 14); |
|
|
|
|
|
contentPane.add(lblNewLabel_1); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lblNewLabel_2 = new JLabel("Modelo"); |
|
|
|
|
|
lblNewLabel_2.setBounds(27, 162, 46, 14); |
|
|
|
|
|
contentPane.add(lblNewLabel_2); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lblNewLabel_3 = new JLabel("Color"); |
|
|
|
|
|
lblNewLabel_3.setBounds(27, 195, 46, 14); |
|
|
|
|
|
contentPane.add(lblNewLabel_3); |
|
|
|
|
|
|
|
|
|
|
|
comboBox_Marca = new JComboBox(); |
|
|
|
|
|
comboBox_Marca.setSelectedIndex(-1); |
|
|
|
|
|
comboBox_Marca.setBounds(100, 125, 113, 22); |
|
|
|
|
|
contentPane.add(comboBox_Marca); |
|
|
|
|
|
comboBox_Marca.setModel(new DefaultComboBoxModel(new String[] {"Ferrari", "Ford", "Lamborghini", "Audi", "Seat", "Mercedes", "Volkswagen"})); |
|
|
|
|
|
comboBox_Marca.setSelectedIndex(-1); |
|
|
|
|
|
|
|
|
|
|
|
comboBox_Modelo = new JComboBox(); |
|
|
|
|
|
comboBox_Modelo.setSelectedIndex(-1); |
|
|
|
|
|
comboBox_Modelo.setBounds(100, 158, 113, 22); |
|
|
|
|
|
contentPane.add(comboBox_Modelo); |
|
|
|
|
|
comboBox_Modelo.setModel(new DefaultComboBoxModel(new String[] {"3P", "AX", "4P", "8P", "AX"})); |
|
|
|
|
|
comboBox_Modelo.setSelectedIndex(-1); |
|
|
|
|
|
|
|
|
|
|
|
comboBox_Color = new JComboBox(); |
|
|
|
|
|
comboBox_Color.setSelectedIndex(-1); |
|
|
|
|
|
comboBox_Color.setBounds(100, 191, 113, 22); |
|
|
|
|
|
contentPane.add(comboBox_Color); |
|
|
|
|
|
comboBox_Color.setModel(new DefaultComboBoxModel(new String[] {"Rojo", "Blanco", "Azul", "Verde", "Negro"})); |
|
|
|
|
|
comboBox_Color.setSelectedIndex(-1); |
|
|
|
|
|
|
|
|
|
|
|
JButton boton_Aleatorio = new JButton("Random"); |
|
|
|
|
|
boton_Aleatorio.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
casilla.setText(matAleatoria()); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
boton_Aleatorio.setBounds(243, 93, 84, 23); |
|
|
|
|
|
contentPane.add(boton_Aleatorio); |
|
|
|
|
|
|
|
|
|
|
|
JPanel panel = new JPanel(); |
|
|
|
|
|
panel.setBounds(0, 0, 434, 293); |
|
|
|
|
|
contentPane.add(panel); |
|
|
|
|
|
panel.setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lblNewLabel_3_1 = new JLabel("Kilometros"); |
|
|
|
|
|
lblNewLabel_3_1.setBounds(23, 227, 70, 14); |
|
|
|
|
|
panel.add(lblNewLabel_3_1); |
|
|
|
|
|
|
|
|
|
|
|
textKm = new JTextField(); |
|
|
|
|
|
textKm.setColumns(10); |
|
|
|
|
|
textKm.setBounds(103, 224, 113, 20); |
|
|
|
|
|
panel.add(textKm); |
|
|
|
|
|
|
|
|
|
|
|
boton_FabricaCoche = new JButton("Fabrica coche"); |
|
|
|
|
|
boton_FabricaCoche.setBackground(Color.GRAY); |
|
|
|
|
|
boton_FabricaCoche.setBounds(246, 166, 178, 38); |
|
|
|
|
|
panel.add(boton_FabricaCoche); |
|
|
|
|
|
|
|
|
|
|
|
JButton botonRandomKm = new JButton("Random km"); |
|
|
|
|
|
botonRandomKm.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
String n = ""; |
|
|
|
|
|
n = n + ((int)Math.floor(Math.random()*(10000-0+1) + 0)); |
|
|
|
|
|
textKm.setText(n); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
botonRandomKm.setBounds(246, 223, 107, 23); |
|
|
|
|
|
panel.add(botonRandomKm); |
|
|
|
|
|
|
|
|
|
|
|
lblTexto = new JLabel(""); |
|
|
|
|
|
lblTexto.setBounds(32, 268, 392, 14); |
|
|
|
|
|
panel.add(lblTexto); |
|
|
|
|
|
|
|
|
|
|
|
JButton boton_AleatorioAll = new JButton("Random All"); |
|
|
|
|
|
boton_AleatorioAll.setBounds(246, 132, 107, 23); |
|
|
|
|
|
panel.add(boton_AleatorioAll); |
|
|
|
|
|
|
|
|
|
|
|
btnModificar = new JButton("Modificar"); |
|
|
|
|
|
btnModificar.setEnabled(false); |
|
|
|
|
|
btnModificar.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
String Marca = (String)comboBox_Marca.getSelectedItem(); |
|
|
|
|
|
String Modelo = (String)comboBox_Modelo.getSelectedItem(); |
|
|
|
|
|
String Color = (String)comboBox_Color.getSelectedItem(); |
|
|
|
|
|
int Km = Integer.parseInt(textKm.getText()); |
|
|
|
|
|
|
|
|
|
|
|
Coche c = arr.get(Ventana.table.getSelectedRow()); |
|
|
|
|
|
c.modificar(casilla.getText(), Marca, Modelo, Color, Km); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
btnModificar.setBounds(335, 93, 89, 23); |
|
|
|
|
|
panel.add(btnModificar); |
|
|
|
|
|
|
|
|
|
|
|
JButton botonListaCoches = new JButton("MOSTRAR TABLA"); |
|
|
|
|
|
botonListaCoches.setBounds(138, 21, 168, 47); |
|
|
|
|
|
panel.add(botonListaCoches); |
|
|
|
|
|
botonListaCoches.setForeground(Color.WHITE); |
|
|
|
|
|
botonListaCoches.setBackground(Color.DARK_GRAY); |
|
|
|
|
|
botonListaCoches.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
Ventana frame = new Ventana(); |
|
|
|
|
|
frame.setVisible(true); |
|
|
|
|
|
//Navegador.arr.add(frame); |
|
|
|
|
|
|
|
|
|
|
|
dispose(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
boton_AleatorioAll.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
int random1=(int)(Math.random()*(6-0+1)+0); |
|
|
|
|
|
int random2=(int)(Math.random()*(4-0+1)+0); |
|
|
|
|
|
int random3=(int)(Math.random()*(4-0+1)+0); |
|
|
|
|
|
|
|
|
|
|
|
comboBox_Marca.setSelectedIndex(random1); |
|
|
|
|
|
comboBox_Modelo.setSelectedIndex(random2); |
|
|
|
|
|
comboBox_Color.setSelectedIndex(random3); |
|
|
|
|
|
|
|
|
|
|
|
casilla.setText(matAleatoria()); |
|
|
|
|
|
|
|
|
|
|
|
String n = ""; |
|
|
|
|
|
n = n + ((int)Math.floor(Math.random()*(10000-0+1) + 0)); |
|
|
|
|
|
textKm.setText(n); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
boton_FabricaCoche.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
String Marca = (String)comboBox_Marca.getSelectedItem(); |
|
|
|
|
|
String Modelo = (String)comboBox_Modelo.getSelectedItem(); |
|
|
|
|
|
String Color = (String)comboBox_Color.getSelectedItem(); |
|
|
|
|
|
int Km = Integer.parseInt(textKm.getText()); |
|
|
|
|
|
|
|
|
|
|
|
lblTexto.setVisible(true); |
|
|
|
|
|
lblTexto.setText("Se ha fabricado un " + Marca); |
|
|
|
|
|
|
|
|
|
|
|
Coche c = new Coche(casilla.getText(), Marca, Modelo, Color, Km); |
|
|
|
|
|
arr.add(c); |
|
|
|
|
|
|
|
|
|
|
|
guarda_coche(c); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void guarda_coche(Coche c) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Class.forName(Conexion.driver); |
|
|
|
|
|
Conexion.con=DriverManager.getConnection(Conexion.url + Conexion.db, Conexion.user, Conexion.pass); |
|
|
|
|
|
|
|
|
|
|
|
Statement st = Conexion.con.createStatement(); |
|
|
|
|
|
|
|
|
|
|
|
st.executeUpdate("INSERT INTO COCHE VALUES(" + c.datos() + ")"); |
|
|
|
|
|
|
|
|
|
|
|
Conexion.con.close(); |
|
|
|
|
|
}catch (ClassNotFoundException e1) { |
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
}catch (SQLException e1) { |
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String matAleatoria() { |
|
|
|
|
|
String matricula = ""; |
|
|
|
|
|
String letras = "BCDFGHJKLMNPQRSTVWXYZ"; |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<4; i++) { |
|
|
|
|
|
matricula = matricula + ((int)Math.floor(Math.random()*(9-0+1) + 0)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
matricula = matricula + "-"; |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<3; i++) { |
|
|
|
|
|
matricula = matricula + "" + letras.charAt(((int)Math.floor(Math.random()*(20-0+1) + 0))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return matricula; |
|
|
|
|
|
} |
|
|
|
|
|
} |