Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Ankita Karande

Greenhorn
+ Follow
since Mar 22, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ankita Karande

now i have properly arranged the imports and removed the unwanted. my code looks less messy, Thanks a lot Tim Moores !
8 months ago
I forgot to describe the obstacle for me. errors are:
1. "SwingAction cannot be resolved to a type  " (Line 48)
2. "btnInsert cannot be resolved to a variable" (Line 94)
8 months ago
8 months ago
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import java.awt.Button;
import javax.swing.JToggleButton;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JSlider;
import javax.swing.JRadioButton;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import java.lang.NumberFormatException;

import java.sql.*;
import javax.swing.JSeparator;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.BorderLayout;
import javax.swing.AbstractAction;
import javax.swing.Action;
public class hotelmanagement {

private JFrame frame;
private JTextField txtCname;
private JTextField txtBudget;
private JTextField txtvehinum;
private JTextField txtIDtype;

/**
* Launch the application.
*/
private static Connection con;
private JTextField txtroom;
private JTextField txtgender;
private JTextField txtvehi;
private JTextField txtcustsearch;
private JTextField txtIDsearch;
private JTextField txtcid;
private JTextField txtidnum;
private JTextField txtvehisearch;
private final Action action = new SwingAction();
private JTextField txtparkingarea;
public static void main(String[] args) {

try {
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres", "12345");
if (con != null) {
       System.out.println("Connected");
}
String sql = "select * from public.customer_details";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
System.out.println(rs);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}

EventQueue.invokeLater(new Runnable() {
public void run() {
try {
hotelmanagement window = new hotelmanagement();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});

}

/**
* Create the application.
*/
public hotelmanagement() {
initialize();

}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 1006, 611);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.getContentPane().add(btnInsert);
frame.getContentPane().setLayout(null);

JLabel lblCloudHotel = new JLabel("CLOUD HOTEL");
lblCloudHotel.setBounds(319, 0, 118, 25);
lblCloudHotel.setLabelFor(lblCloudHotel);
lblCloudHotel.setFont(new Font("Calibri", Font.BOLD, 13));
lblCloudHotel.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblCloudHotel);

JLabel lblCustomerDetails = new JLabel("Customer Details :");
lblCustomerDetails.setBounds(0, 42, 140, 25);
lblCustomerDetails.setLabelFor(lblCustomerDetails);
lblCustomerDetails.setFont(new Font("Calibri", Font.BOLD, 14));
lblCustomerDetails.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblCustomerDetails);

JLabel lblcustname = new JLabel("Customer Name :");
lblcustname.setBounds(0, 160, 124, 25);
lblcustname.setLabelFor(lblcustname);
lblcustname.setFont(new Font("Calibri", Font.PLAIN, 15));
lblcustname.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblcustname);

txtCname = new JTextField();
txtCname.setBounds(134, 162, 96, 20);
frame.getContentPane().add(txtCname);
txtCname.setColumns(10);

JLabel lblrooms = new JLabel("Rooms :");
lblrooms.setBounds(0, 196, 86, 23);
lblrooms.setHorizontalAlignment(SwingConstants.CENTER);
lblrooms.setLabelFor(lblrooms);
lblrooms.setFont(new Font("Calibri", Font.PLAIN, 14));
frame.getContentPane().add(lblrooms);

JLabel lblbudg = new JLabel("BUDGET");
lblbudg.setBounds(0, 220, 86, 25);
lblbudg.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblbudg);

txtBudget = new JTextField();
txtBudget.setBounds(144, 222, 86, 20);
txtBudget.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(txtBudget);
txtBudget.setColumns(10);

JLabel lblGender = new JLabel("Gender:");
lblGender.setBounds(22, 245, 64, 26);
lblGender.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblGender);

JLabel lblvehicle = new JLabel("Vehicle :");
lblvehicle.setBounds(531, 200, 88, 14);
lblvehicle.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblvehicle);

JLabel lblvehinum = new JLabel("vehicle no.:");
lblvehinum.setBounds(554, 220, 69, 25);
lblvehinum.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblvehinum);

txtvehinum = new JTextField();
txtvehinum.setBounds(633, 222, 86, 20);
frame.getContentPane().add(txtvehinum);
txtvehinum.setColumns(10);

JLabel lblIdType = new JLabel("ID Type:");
lblIdType.setBounds(294, 184, 46, 14);
frame.getContentPane().add(lblIdType);

txtIDtype = new JTextField();
txtIDtype.setBounds(362, 182, 97, 20);
txtIDtype.setHorizontalAlignment(SwingConstants.CENTER);
txtIDtype.setFont(new Font("Calibri", Font.PLAIN, 11));
frame.getContentPane().add(txtIDtype);
txtIDtype.setColumns(10);

JButton btnInsert = new JButton("INSERT");
btnInsert.setBounds(434, 353, 105, 39);
btnInsert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int cid = Integer.parseInt(txtcid.getText());
String cname = txtCname.getText();
int room = Integer.parseInt(txtroom.getText());
int budget = Integer.parseInt(txtBudget.getText());
String gender = txtgender.getText();
int id = Integer.parseInt(txtidnum.getText());
String idtype = txtIDtype.getText();
String vehicletype = txtvehi.getText();
int vehiclenum = Integer.parseInt(txtvehinum.getText());

try {
Statement stmt = con.createStatement();
String qry = "insert into customer_details values('"+cid+"','"+cname+"','"+room+"','"+budget+"','"+gender+"')";
stmt.executeQuery(qry);
stmt.close();

}
catch(Exception e) {
System.out.print(e.getMessage());
}

try {
Statement stmt = con.createStatement();
String qry2 = "insert into ID_details values('"+id+"','"+idtype+"')";
stmt.executeQuery(qry2);
stmt.close();

}
catch(Exception e) {
System.out.print(e.getMessage());
}

try {
Statement stmt = con.createStatement();
String qry3 = "insert into vehicle_details values('"+vehicletype+"','"+vehiclenum+"')";
stmt.executeQuery(qry3);
stmt.close();

}
catch(Exception e) {
System.out.print(e.getMessage());
}
}
});
frame.getContentPane().add(btnInsert);

txtroom = new JTextField();
txtroom.setBounds(144, 196, 86, 20);
txtroom.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(txtroom);
txtroom.setColumns(10);

txtgender = new JTextField();
txtgender.setBounds(142, 248, 86, 20);
txtgender.setText("");
frame.getContentPane().add(txtgender);
txtgender.setColumns(10);

txtvehi = new JTextField();
txtvehi.setBounds(633, 194, 86, 20);
frame.getContentPane().add(txtvehi);
txtvehi.setColumns(10);

JLabel lblIdDetails = new JLabel("ID details:");
lblIdDetails.setBounds(294, 53, 111, 14);
lblIdDetails.setFont(new Font("Calibri", Font.BOLD, 15));
lblIdDetails.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(lblIdDetails);

JLabel lblVehicleDetails = new JLabel("vehicle details");
lblVehicleDetails.setBounds(582, 53, 118, 14);
lblVehicleDetails.setHorizontalAlignment(SwingConstants.CENTER);
lblVehicleDetails.setFont(new Font("Calibri", Font.BOLD, 15));
frame.getContentPane().add(lblVehicleDetails);

JLabel lblCid = new JLabel("CID");
lblCid.setBounds(22, 135, 46, 14);
frame.getContentPane().add(lblCid);

txtcid = new JTextField();
txtcid.setBounds(117, 132, 86, 20);
frame.getContentPane().add(txtcid);
txtcid.setColumns(10);

JLabel lblidnum = new JLabel("ID number");
lblidnum.setBounds(271, 225, 69, 14);
frame.getContentPane().add(lblidnum);

txtidnum = new JTextField();
txtidnum.setBounds(354, 220, 105, 25);
frame.getContentPane().add(txtidnum);
txtidnum.setColumns(10);

JButton btnNewButton = new JButton("UPDATE");
btnNewButton.setBounds(283, 353, 89, 39);
frame.getContentPane().add(btnNewButton);

JLabel lblparkingarea = new JLabel("Parking area:");
lblparkingarea.setBounds(548, 251, 86, 14);
frame.getContentPane().add(lblparkingarea);

txtparkingarea = new JTextField();
txtparkingarea.setBounds(633, 251, 86, 20);
frame.getContentPane().add(txtparkingarea);
txtparkingarea.setColumns(10);

}
}







8 months ago