• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

I'm stuck at these errors for long .. can anyone please tell me where I am wrong?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}
}







 
Ankita Karande
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ankita Karande
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Saloon Keeper
Posts: 7324
170
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Several issues in no particular order:

  • Your list of imports looks fishy. You're importing a class you're not using (DefaultComponentFactory), but you're not importing a class (SwingAction) that you are using. The latter is what the first error message is about. The only reference to SwingAction a quick search brings up is https://support.sas.com/rnd/javadoc/93/Components/com/sas/actionprovider/SwingAction.html - is that what you're trying to use? If so, you need to import it (and put the relevant jar files in the classpath). On the other hand, the code does not use the "action" variable at all, so you could just delete line 48 instead.


  • As to "btnInsert", you're defining it in line 172, but you're already using it in line 94. You need to define it before you can use it.


  • The code uses absolute positioning rather than nested layouts - that makes for brittle layouts that will likely not react well to changes. I advise strongly to use the layouts that come with Swing instead: https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html


  • The code uses Statement rather than PreparedStatement. While desktop apps don't suffer from the same SQL injection problems web apps do, it is still good practice to us prepared statements which make for easier to write queries, because you don't need to worry about escaping characters, enclosing quotes and such.
  •  
    Ankita Karande
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    now i have properly arranged the imports and removed the unwanted. my code looks less messy, Thanks a lot Tim Moores !
     
    I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic