codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  I NEED HELP!!!!!!!!  mengvue at 17:27 on Tuesday, February 28, 2006
 

I don't know how to make my buttons work and connect to my database.
I'm suppose to be able to add, modify, and delete from my database.
if anyone can help it would be really nice. Thank you





//Car.java
//
//
//
//
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;


public class Car
{
static JFrame frame = new JFrame("Car Information");

JLabel Model = new JLabel("Model");
JLabel Color = new JLabel("Color ");
JLabel Year = new JLabel("Year");
JLabel Type = new JLabel("Type");

JTextField modelt = new JTextField();
JTextField colort = new JTextField();
JTextField yeart = new JTextField();
JTextField typet = new JTextField();

JButton add = new JButton("Add");
JButton cha = new JButton("Modify");
JButton del = new JButton("Delete");

public Car()
{
setUpWindow();
}

public void setUpWindow()
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds((screenSize.width-500)/2, (screenSize.height-400)/2, 500, 400);
frame.setLayout(new BorderLayout());

JPanel topPanel = new JPanel();
JPanel buttonPanel = new JPanel();

frame.add(topPanel, (BorderLayout.CENTER));
frame.add(buttonPanel, (BorderLayout.SOUTH));

buttonPanel.add(add);
buttonPanel.add(cha);
buttonPanel.add(del);

topPanel.setBorder(BorderFactory.createEmptyBorder(40, 40, 40, 40));
topPanel.setLayout(new GridLayout(4, 2));
topPanel.add(Model);
topPanel.add(modelt);
topPanel.add(Color);
topPanel.add(colort);
topPanel.add(Year);
topPanel.add(yeart);
topPanel.add(Type);
topPanel.add(typet);

frame.pack();
frame.setVisible(true);
}







public static void main(String Args[])
{
Car at = new Car();
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
}
}



This is my connection I know it's not done because thats all I know. If someone knows the rest please let me know.




//PConnection.java
//
//
//
//
//
import java.awt.*;
import java.sql.*;

public class PConnection
{
String JDBC_DRIVER = "org.postgresql.Driver";
String DATABASE_URL = "jdbc:postgresql://127.0.0.1:5432/Car";
String USERNAME = "postgres";
String PASSWORD = "051103";

private Connection connection;
private Statement statement ;
private ResultSet results;


private void connect() throws Exception
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
statement = connection.createStatement();

System.err.println(connection);
}




}


  Re: I NEED HELP!!!!!!!!  crwood at 00:40 on Wednesday, March 01, 2006
 

Here's the button and listener part; I changed the name so you can run it as–is:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

public class CarRx implements ActionListener
{
JFrame frame = new JFrame("Car Information");

JLabel Model = new JLabel("Model");
JLabel Color = new JLabel("Color ");
JLabel Year = new JLabel("Year");
JLabel Type = new JLabel("Type");

JTextField modelt = new JTextField();
JTextField colort = new JTextField();
JTextField yeart = new JTextField();
JTextField typet = new JTextField();

JButton add = new JButton("Add");
JButton cha = new JButton("Modify");
JButton del = new JButton("Delete");

public CarRx()
{
setUpWindow();
}

public void setUpWindow()
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds((screenSize.width-500)/2, (screenSize.height-400)/2, 500, 400);
frame.setLayout(new BorderLayout());

JPanel topPanel = new JPanel();
JPanel buttonPanel = new JPanel();

frame.add(topPanel, (BorderLayout.CENTER));
frame.add(buttonPanel, (BorderLayout.SOUTH));

add.addActionListener(this);
cha.addActionListener(this);
del.addActionListener(this);

buttonPanel.add(add);
buttonPanel.add(cha);
buttonPanel.add(del);

topPanel.setBorder(BorderFactory.createEmptyBorder(40, 40, 40, 40));
topPanel.setLayout(new GridLayout(4, 2));
topPanel.add(Model);
topPanel.add(modelt);
topPanel.add(Color);
topPanel.add(colort);
topPanel.add(Year);
topPanel.add(yeart);
topPanel.add(Type);
topPanel.add(typet);

frame.pack();
frame.setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
String caller = "";
if(button == add)
caller = "add";
if(button == cha)
caller = "cha";
if(button == del)
caller = "del";
System.out.println("caller = " + caller);
}

public static void main(String Args[])
{
CarRx at = new CarRx();
at.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Maybe this will help with the database part Lesson: JDBC Basics.

  Re: I NEED HELP!!!!!!!!  tanyujie at 04:35 on Wednesday, March 01, 2006
 

ok








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: need help in applet communication
•  Re: MS Access connection in JSP
•  Highlight a DataGrid Row and Stay there -
•  Numeric field
•  Re: visible/invisible divs
•  radio buttons questionnaire
•  Re: Splitter in DHTML, no frames
•  Re: how to set value to texbox
•  Re: IE page Redirect


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006