Posted By:
Akansha_Srivastva
Posted On:
Saturday, May 25, 2002 05:47 AM
This is what my code looks like: import javax.swing.*; import java.awt.event.*; import java.sql.*; import java.awt.*; import java.io.*; public class MyTest2 extends JApplet { JPanel panel; JLabel labelGRNDate; JLabel labelRefFrom; JTextField textGRNDate; JTextField textRefFrom; JButton buttonAccept; GridBagLayout gl; GridBagConstraints gbc; public void init() { gl = new GridBagLayout(); gbc = new GridBagConstraints(); panel = (JPanel)getContentPane(); panel.
More>>
This is what my code looks like:
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.*;
import java.io.*;
public class MyTest2 extends JApplet
{
JPanel panel;
JLabel labelGRNDate;
JLabel labelRefFrom;
JTextField textGRNDate;
JTextField textRefFrom;
JButton buttonAccept;
GridBagLayout gl;
GridBagConstraints gbc;
public void init()
{
gl = new GridBagLayout();
gbc = new GridBagConstraints();
panel = (JPanel)getContentPane();
panel.setLayout(gl);
labelGRNDate = new JLabel("GRN Date");
labelRefFrom = new JLabel("Ref From");
buttonAccept = new JButton("Accept");
textGRNDate = new JTextField(6);
textRefFrom = new JTextField(4);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 1;
gl.setConstraints(labelGRNDate,gbc);
panel.add(labelGRNDate);
gbc.gridx = 2;
gbc.gridy = 1;
gl.setConstraints(textGRNDate,gbc);
panel.add(textGRNDate);
gbc.gridx = 1;
gbc.gridy = 2;
gl.setConstraints(labelRefFrom,gbc);
panel.add(labelRefFrom);
gbc.gridx = 2;
gbc.gridy = 2;
gl.setConstraints(textRefFrom,gbc);
panel.add(textRefFrom);
gbc.gridx = 9;
gbc.gridy =10;
gl.setConstraints(buttonAccept,gbc);
panel.add(buttonAccept);
buttonAccept.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Writer out1 = null;
Writer out2 = null;
try
{
out1 = new BufferedWriter(new FileWriter(textGRNDate.getText()));
out2 = new BufferedWriter(new FileWriter(textRefFrom.getText()));
JOptionPane.showMessageDialog(MyTest2.this, "Save Happened");
}
catch(SecurityException se)
{
JOptionPane.showMessageDialog (MyTest2.this,
"Security Violation Happened",
"Security Violation",
JOptionPane.ERROR_MESSAGE);
}
catch (IOException ie)
{
JOptionPane.showMessageDialog(
MyTest2.this,
"IOException Happened",
"IO Problems",
JOptionPane.WARNING_MESSAGE);
}
finally
{
if (out1 != null)
{
try
{
out1.close();
}
catch (IOException ignored)
{
}
}
if (out2 != null)
{
try
{
out2.close();
}
catch (IOException ignored)
{
}
}
}
}
});
String url = "jdbc:odbc:Noorderwind";
Connection con;
Statement stmt;
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException a)
{
System.err.print("ClassNotFoundException:");
System.err.print(a.getMessage());
}
try
{
con = DriverManager.getConnection(url);
stmt = con.createStatement();
stmt.executeUpdate("insert into MyTable" + "values(textGRNDate.getText(), textRefFrom.getText())");
stmt.close();
con.close();
}
catch(SQLException exception)
{
System.out.println("Error Encountered while entering data in the database: "+exception.getMessage());
}
}
}
}
<<Less