|
@ -0,0 +1,207 @@ |
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
import java.awt.EventQueue; |
|
|
|
|
|
import java.sql.DriverManager; |
|
|
|
|
|
import java.sql.ResultSet; |
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
import java.sql.Statement; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
|
|
import javax.swing.JScrollPane; |
|
|
|
|
|
import javax.swing.JTable; |
|
|
|
|
|
import javax.swing.table.DefaultTableModel; |
|
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
|
import javax.swing.JTextField; |
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
|
|
|
|
|
|
public class VentanaHoteles extends JFrame { |
|
|
|
|
|
|
|
|
|
|
|
private JPanel contentPane; |
|
|
|
|
|
private JTable hotel; |
|
|
|
|
|
private JLabel lblNewLabel; |
|
|
|
|
|
private JLabel lblNewLabel_1; |
|
|
|
|
|
private JLabel lblNewLabel_2; |
|
|
|
|
|
private JButton botoInsertar; |
|
|
|
|
|
private JTextField casillaNombre; |
|
|
|
|
|
private JTextField casillaCiudad; |
|
|
|
|
|
private JTextField CasillaEstrellas; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
public void run() { |
|
|
|
|
|
try { |
|
|
|
|
|
VentanaHoteles frame = new VentanaHoteles(); |
|
|
|
|
|
frame.setVisible(true); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public VentanaHoteles() { |
|
|
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
|
setBounds(100, 100, 450, 451); |
|
|
|
|
|
contentPane = new JPanel(); |
|
|
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
|
|
|
|
setContentPane(contentPane); |
|
|
|
|
|
contentPane.setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
JPanel panel = new JPanel(); |
|
|
|
|
|
panel.setBounds(0, 0, 434, 412); |
|
|
|
|
|
contentPane.add(panel); |
|
|
|
|
|
panel.setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
JScrollPane scrollPane = new JScrollPane(); |
|
|
|
|
|
scrollPane.setBounds(53, 48, 324, 151); |
|
|
|
|
|
panel.add(scrollPane); |
|
|
|
|
|
|
|
|
|
|
|
hotel = new JTable(); |
|
|
|
|
|
hotel.setModel(new DefaultTableModel( |
|
|
|
|
|
new Object[][] { |
|
|
|
|
|
}, |
|
|
|
|
|
new String[] { |
|
|
|
|
|
"ID", "Nombre", "Ciudad", "Estrellas" |
|
|
|
|
|
} |
|
|
|
|
|
)); |
|
|
|
|
|
scrollPane.setViewportView(hotel); |
|
|
|
|
|
|
|
|
|
|
|
lblNewLabel = new JLabel("Nombre"); |
|
|
|
|
|
lblNewLabel.setBounds(53, 233, 46, 14); |
|
|
|
|
|
panel.add(lblNewLabel); |
|
|
|
|
|
|
|
|
|
|
|
lblNewLabel_1 = new JLabel("Ciudad"); |
|
|
|
|
|
lblNewLabel_1.setBounds(53, 275, 46, 14); |
|
|
|
|
|
panel.add(lblNewLabel_1); |
|
|
|
|
|
|
|
|
|
|
|
lblNewLabel_2 = new JLabel("Estrellas"); |
|
|
|
|
|
lblNewLabel_2.setBounds(53, 323, 65, 14); |
|
|
|
|
|
panel.add(lblNewLabel_2); |
|
|
|
|
|
|
|
|
|
|
|
botoInsertar = new JButton("Insertar"); |
|
|
|
|
|
botoInsertar.addActionListener(new ActionListener() { |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
String Nombre = casillaNombre.getText(); |
|
|
|
|
|
String Ciudad = casillaCiudad.getText(); |
|
|
|
|
|
int Estrellas = Integer.parseInt(CasillaEstrellas.getText()); |
|
|
|
|
|
|
|
|
|
|
|
Hotel h = new Hotel(Nombre, Ciudad, Estrellas); |
|
|
|
|
|
Hotel.lista.add(h); |
|
|
|
|
|
|
|
|
|
|
|
guarda_hotel(h); |
|
|
|
|
|
|
|
|
|
|
|
casillaNombre.setText(""); |
|
|
|
|
|
casillaCiudad.setText(""); |
|
|
|
|
|
CasillaEstrellas.setText(""); |
|
|
|
|
|
|
|
|
|
|
|
carga_Array(); |
|
|
|
|
|
|
|
|
|
|
|
//Hotel.lista.clear(); |
|
|
|
|
|
|
|
|
|
|
|
int numCols = hotel.getModel().getColumnCount(); |
|
|
|
|
|
|
|
|
|
|
|
Object[] fila = new Object[numCols]; |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<Hotel.lista.size();i++) { |
|
|
|
|
|
fila[0] = i; |
|
|
|
|
|
fila[1]= Hotel.lista.get(i).getNombre(); |
|
|
|
|
|
fila[2]= Hotel.lista.get(i).getCiudad(); |
|
|
|
|
|
fila[3]= Hotel.lista.get(i).getEstrellas(); |
|
|
|
|
|
((DefaultTableModel) hotel.getModel()).addRow(fila); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
botoInsertar.setBounds(53, 373, 89, 23); |
|
|
|
|
|
panel.add(botoInsertar); |
|
|
|
|
|
|
|
|
|
|
|
casillaNombre = new JTextField(); |
|
|
|
|
|
casillaNombre.setBounds(128, 230, 86, 20); |
|
|
|
|
|
panel.add(casillaNombre); |
|
|
|
|
|
casillaNombre.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
casillaCiudad = new JTextField(); |
|
|
|
|
|
casillaCiudad.setBounds(128, 272, 86, 20); |
|
|
|
|
|
panel.add(casillaCiudad); |
|
|
|
|
|
casillaCiudad.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
CasillaEstrellas = new JTextField(); |
|
|
|
|
|
CasillaEstrellas.setBounds(128, 320, 86, 20); |
|
|
|
|
|
panel.add(CasillaEstrellas); |
|
|
|
|
|
CasillaEstrellas.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
Hotel.lista.clear(); |
|
|
|
|
|
|
|
|
|
|
|
carga_Array(); |
|
|
|
|
|
|
|
|
|
|
|
int numCols = hotel.getModel().getColumnCount(); |
|
|
|
|
|
|
|
|
|
|
|
Object[] fila = new Object[numCols]; |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<Hotel.lista.size();i++) { |
|
|
|
|
|
fila[0] = i; |
|
|
|
|
|
fila[1]= Hotel.lista.get(i).getNombre(); |
|
|
|
|
|
fila[2]= Hotel.lista.get(i).getCiudad(); |
|
|
|
|
|
fila[3]= Hotel.lista.get(i).getEstrellas(); |
|
|
|
|
|
((DefaultTableModel) hotel.getModel()).addRow(fila); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void guarda_hotel(Hotel h) { |
|
|
|
|
|
|
|
|
|
|
|
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 HOTEL VALUES(DEFAULT," + h.datos() + ")"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Conexion.con.close(); |
|
|
|
|
|
}catch (ClassNotFoundException e1) { |
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
}catch (SQLException e1) { |
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void carga_Array() { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Class.forName(Conexion.driver); |
|
|
|
|
|
Conexion.con=DriverManager.getConnection(Conexion.url + Conexion.db, Conexion.user, Conexion.pass); |
|
|
|
|
|
|
|
|
|
|
|
Statement st = Conexion.con.createStatement(); |
|
|
|
|
|
|
|
|
|
|
|
//Coche c1 = new Coche("333CCC","Ferrari","F40","Rojo",99999); |
|
|
|
|
|
//st.executeUpdate("INSERT INTO COCHE VALUES(" + c1.datos() + ")"); |
|
|
|
|
|
|
|
|
|
|
|
ResultSet res = st.executeQuery("SELECT * FROM hotel"); |
|
|
|
|
|
|
|
|
|
|
|
while(res.next()) { |
|
|
|
|
|
String nombre = res.getString("Nombre"); |
|
|
|
|
|
String ciudad = res.getString("Ciudad"); |
|
|
|
|
|
int estrellas=res.getInt("Estrellas"); |
|
|
|
|
|
|
|
|
|
|
|
//System.out.println(matricula + "\t\t" + marca + "\t\t" + modelo + "\t\t" + color + "\t\t" + km); |
|
|
|
|
|
Hotel h = new Hotel(nombre, ciudad, estrellas); |
|
|
|
|
|
Hotel.lista.add(h); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
Conexion.con.close(); |
|
|
|
|
|
}catch (ClassNotFoundException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
}catch (SQLException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |