I have been struggling with this problem for a while where I have two classes namely OrderSearch.java(main class) and CreateOrder.java. I have a JTable on my main class and when a row is doubleclicked it opens a new frame i.e CreateOrder.java with values from jTablein different textfields. I have a SaveButton in CreateOrder.java that saves the changes made in the class and shows it JTable again.
However the problem is I cannot perform refresh table operation i.e some sql queries when the SaveButton is clicked. I want the table in frame OrderSearch is refreshed when the savebutton on CreateOrder is clicked
Problems: Creating an object for class OrderSearch.java in CreateOrder.java gives me a stackoverflow error. Creating an object in the Savebutton opens a whole new frame again.
OrderSearch.java
public class OrderSearch extends CreateOrder{
//declarations for label,text, and buttons
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
OrderSearch window = new OrderSearch();
window.frmXraymanager.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public OrderSearch () { *Stack overflow error here*
initialize();
}
private void initialize() {
table = new JTable();
scrollPane.setViewportView(table);
table.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent e2) {
if (e2.getClickCount() == 2 && !e2.isConsumed()) {
e2.consume();
try{
int index = table.getSelectedRow();
String table_Click = table.getModel().getValueAt(table.convertRowIndexToModel(index), 0).toString();
String sql = "SELECT ID, Date, Place, UserName FROM TEST.dbo.Intern WHERE ID = '"+table_Click+"'";
PreparedStatement pst = connection.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
if(rs.next()){
String id = rs.getString("ID");
String date = rs.getString("Date").toString();
String place = rs.getString("Place");
String uname = rs.getString("UserName");
frameCreate.setVisible(true); //Frame from CreateOrder.java
Number.setText(id); // textfields from CreateOrder.java
String date1 = startDate;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date2 = df.parse(date1);
dateChooser.setDate(date2);
jobSite.setText(place);
uName.setText(uname);
Component.setText(component);
Remarks.setText(remarks);
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
});
}
public void refresh()
{
query1 = "SELECT * FROM Test.dbo.Intern;
try(PreparedStatement pst = connection.prepareStatement(query1);
ResultSet rs = pst.executeQuery();){
table.setModel(DbUtils.resultSetToTableModel(rs));
table.setRowHeight(40);
}
catch(Exception e){
e.printStackTrace();
}
}
}
CreateOrder.java
public class CreateOrder {
public CreateOrder () {
initialize();
}
OrderSearch one = new OrderSearch(); *Stack overflow error here*
private void initialize() {
button_Save = new JButton("Save");
button_Save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
*would like to add refresh() here*
}
});
}
}
How should I create an object of OrderSearch in CreateOrder to acces the method refresh() without opening the frame again?
Thanks in advance!
-Ajay
EDIT:
Actually the error is in
OrderSearch one = new OrderSearch();
and public OrderSearch () I totally understand it makes sense because it goes into infinite loop when I call an Object in CreateOrder.java. But is there any way to access the contents of OrderSearch.java in CreateOrder.java without getting the stackoverflow error or opening the whole new frame OrderSearch.java again?
No, there is no way to do it assuming your current setup. This leads us to the conclusion that you need to refactor the code. The main problem is that your code has no way to execute the required db command without creating a frame. You will need to separate the engine from the ui. You will need to be able to execute business logic without being tied to a UI event. The UI should be a user of the business logic, not its wrapper. You will need to move all your business logic into separate class(es) and call the relevant methods from the ui at the appropriate places and events.
Hello I'm having a little bit of a problem with my text editor like program. I would like to have my Save feature work only if Save As has been called, and if Save is called that it appends the text From a JTextArea to the file created by Save As. I am using ActionListeners from JMenuItems to call the Save and Save As Actions. Here's the code for Save As:
FileDialog fileDialogSave = new FileDialog(frame, "Save", FileDialog.SAVE);
fileDialogSave.setVisible(true);
String userProjectSavePath = fileDialogSave.getDirectory() + fileDialogSave.getFile();
File userProjectSave = new File(userProjectSavePath);
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(userProjectSave, true)))) {
userProjectSave.createNewFile();
String userProjectNameToSave = codeArea.getText();
out.println(userProjectNameToSave);
} catch (IOException e1) {
e1.printStackTrace();
}
Both the Save and Save As are nested inside static class ActionSaveAs implements ActionListener { public void actionPerformed(ActionEvent e) { ... } }
The problem is I can't access the String userProjectSavePath in the Save class so I can't append the new text to the same file as in the Save As.
Instead, let your notional saveDocument() method invoke saveDocumentAs() if currentFile is null. The following outline suggests the approach taken in Charles Bell's HTMLDocumentEditor, cited here.
public void saveDocument() {
if (currentFile != null) {
// Save in currentFile
} else {
saveDocumentAs();
}
}
public void saveDocumentAs() {
// Check before overwriting existing file
}
I'm having a little problem with my Java App. I have 2 frames, the mainframe is called MasterFrame. The MasterFrame contains a JList + 3 buttons.
Button 1 can add Block shapes to the JList, this will call the 2nd frame called BlockFrame. Block shapes are Objects stored in the ArrayList shapecollection.
The MasterFrame also contains a Save button which will store objects in a .txt file called "test.txt".
The MasterFrame also contains a Load button which will open the .txt file "test.txt", read the file for objects and set the objects back into the JList. That is what actually is going wrong. The save function works, i'm not quite sure about the load method. It seems that it's actually reading my .txt file for objects but it won't put it back in my Jlist.
The load method might be good, but than there might be a problem with reading the objects and setting them back into the JList. I'm glad if anyone off you guys could give me a hand :)
import java.io.*;
// My File IO Class
public class ShapeIOController {
private String filename;
public ShapeIOController(){
filename= "C:\\Users\\Lars\\Desktop\\test.txt";
}
// The Save method which will save all my created blocks in "test.txt" file
public void save(ShapeCollection shapecollection){
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
out.writeObject(shapecollection);
out.close();
}
catch( IOException e){
System.out.println("Error occured when trying to open file" + filename);
e.printStackTrace();
}
}
// The open file method which will open "test.txt" file,
// read it's objects and return a ArrayList of shapes "shapecollection"
public ShapeCollection open(ShapeCollection shapecollection){
try{
ObjectInputStream in = new ObjectInputStream(new FileInputStream(filename));
shapecollection= (ShapeCollection) in.readObject();
in.close();
}
catch (ClassNotFoundException e ) {
System.out.println("Unknown class by reading file" + filename);
}
catch ( IOException e ) {
System.out.println("Error occured when trying to open file " + filename);
e.printStackTrace();
}
shapecollection.giveCollection();
return shapecollection;
}
}
// The code for the save button which works
private void SaveShapeButtonActionPerformed(java.awt.event.ActionEvent evt) {
shapeiocontroller.save(shapecontroller.getShapeCollection());
}
// The code where it probably is going wrong
private void LoadShapeButtonActionPerformed(java.awt.event.ActionEvent evt) {
for(int i = 0; i < shapecontroller.getShapeCollection().giveCollection().size(); i++){
listModel.addElement(shapecontroller.getShapeCollection().giveShape(i).toString());
InfoShapeJList.setModel(listModel);
shapeiocontroller.open(shapecontroller.getShapeCollection());
}
}
// List of methods LoadShapeButtonActionPerformed is using:
// getShapeCollection()
public ShapeCollection getShapeCollection() {
return shapecollection;
}
// giveCollection()
public ArrayList<Shape> giveCollection(){
return shapecollection;
}
// giveShape()
public Shape giveShape(int index){
return shapecollection.get(index);
}
// toString()
public String toString(){
return "Block: " + length + " " + width + " " + height;
}
I made a simple program in Processing, and it works great. Im now attempting to bring my beginner Java skills to Eclipse to make the same program over again. The program takes a Rs232 string that comes from the Com port and sends it over Xmpp.
The issue I'm having is that i cant call newChat.sendMessage(message) like i can in processing from any of the Classes/Tabs. Can someone clue me in to what i should look for to fix this issue. I'm guessing Extending, or implementing the Xmpp class is what i need to do. I love how simple processing handles it..
Any help will be greatly appreciated.
Fyi: the Smack library's are in the code folder for processing.
Main Application:
import processing.net.*;
void setup() {
size(400, 200);
noStroke();
background(0);
LoadSerialPort();
OpenChatConnection();
setupFilterThread ();
}
void draw() {
}
String timestampTime() {
Calendar now = Calendar.getInstance();
return String.format("%1$tH:%1$tM:%1$tS", now);
}
String timestampDate() {
Calendar now = Calendar.getInstance();
return String.format("%1$tm/%1$td/%1$tY", now);
}
Filter Class/Tab:
FilterThread thread1;
List FilteredArchAddressList = new ArrayList();
ArrayList CallList = new ArrayList();
void setupFilterThread () {
thread1 = new FilterThread(100, "a");
thread1.start();
}
void checkForNewCalls() {
if (CallList.size() >=1) {
println("New Call In List, Size: "+CallList.size());
FilterComPortString((String) CallList.get(0));
CallList.remove(0);
}
}
void FilterComPortString(String s) {
Message message = new Message("icu1#broadcast.server", Message.Type.normal);
//message.setTo("icu1#broadcast.x-dev");
message.setSubject("MSG_TYPE_NORMAL");
message.setBody(s);
message.setProperty("systemID", "JS1");
message.setProperty("serverTime", trim(timestampTime()));
message.setProperty("serverDate", trim(timestampDate()));
try {
newChat.sendMessage(message);
}
catch (Exception e) {
println(e);
}
}
}
class FilterThread extends Thread {
boolean running; // Is the thread running? Yes or no?
int wait; // How many milliseconds should we wait in between executions?
String id; // Thread name
int count; // counter
// Constructor, create the thread
// It is not running by default
FilterThread (int w, String s) {
wait = w;
running = false ;
id = s;
count = 0;
}
int getCount() {
return count;
}
// Overriding "start()"
void start () {
// Set running equal to true
running = true ;
// Print messages
println ("Starting thread (will execute every " + wait + " milliseconds.)");
// Do whatever start does in Thread, don't forget this!
super .start();
}
// We must implement run, this gets triggered by start()
void run () {
while (running) {
checkForNewCalls();
// Ok, let's wait for however long we should wait
try {
sleep((long )(wait));
}
catch (Exception e) {
}
}
System.out.println (id + " thread is done!"); // The thread is done when we get to the end of run()
}
// Our method that quits the thread
void quit() {
System.out.println ("Quitting.");
running = false ; // Setting running to false ends the loop in run()
// IUn case the thread is waiting. . .
interrupt();
}
}
Rs232 Class/Tab:
import processing.serial.*;
Serial myPort; // Rs232, Serial Port
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
String SelectedCom;
void LoadSerialPort() {
println(Serial.list());
println("________________________________________________________");
try {
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(lf);
SelectedCom = Serial.list()[0];
println("Connected to Serial Port:");
println("________________________________________________________");
}
catch (ArrayIndexOutOfBoundsException e) {
String exception = e.toString();
if (exception.contains("ArrayIndexOutOfBoundsException: 0")) {
println("NO AVAILABLE COM PORT FOUND");
}
else {
println(e);
}
}
}
void serialEvent(Serial p) {
inString = p.readString();
CallList.add(new String(inString));
}
Xmpp Class/Tab:
String FromXmpp = "";
Chat newChat;
ChatManager chatmanager;
XMPPConnection connection;
public void OpenChatConnection() {
// This is the connection to google talk. If you use jabber, put other stuff in here.
ConnectionConfiguration config = new ConnectionConfiguration("192.168.0.103", 5222, "Jabber/XMPP");
config.setSASLAuthenticationEnabled(false);
configure(ProviderManager.getInstance());
connection = new XMPPConnection(config);
println("Connecting");
try {
//connection.DEBUG_ENABLED = true;
connection.connect();
println("Connected to: "+connection.getServiceName() );
}
catch (XMPPException e1) {
println("NOT Connected");
}
if (connection.isConnected()) {
try {
// This is the username and password of the chat client that is to run within Processing.
println("Connecting");
connection.login("System1", "test");
//connection.login("inside_processing_username#gmail.com", "yourpassword");
}
catch (XMPPException e1) {
// would probably be a good idea to put some user friendly action here.
e1.printStackTrace();
}
println("Logged in as: "+connection.getUser() );
}
chatmanager = connection.getChatManager();
// Eventhandler, to catch incoming chat events
newChat = chatmanager.createChat("icu#broadcast.server", new MessageListener() { //icu1#broadcast.x-dev //admin#x-dev
public void processMessage(Chat chat, Message message) {
// Here you do what you do with the message
FromXmpp = message.getBody();
// Process commands
//println(FromXmpp);
}
}
);
Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
System.out.println(entry);
}
}
public void configure(ProviderManager pm) {
// Private Data Storage
pm.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
// Time
try {
pm.addIQProvider("query", "jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
}
catch (ClassNotFoundException e) {
println(("TestClient "+" Can't load class for org.jivesoftware.smackx.packet.Time"));
}
// Roster Exchange
pm.addExtensionProvider("x", "jabber:x:roster", new RosterExchangeProvider());
// Message Events
pm.addExtensionProvider("x", "jabber:x:event", new MessageEventProvider());
// Chat State
pm.addExtensionProvider("active", "http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("composing", "http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
pm.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider());
// XHTML
pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
// Group Chat Invitations
pm.addExtensionProvider("x", "jabber:x:conference", new GroupChatInvitation.Provider());
// Service Discovery # Items
pm.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
// Service Discovery # Info
pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Data Forms
pm.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
// MUC User
pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
pm.addExtensionProvider("x", "jabber:x:delay", new DelayInformationProvider());
// Version
try {
pm.addIQProvider("query", "jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
}
catch (ClassNotFoundException e) {
// Not sure what's happening here.
}
// VCard
pm.addIQProvider("vCard", "vcard-temp", new VCardProvider());
// Offline Message Requests
pm.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
pm.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
// Last Activity
pm.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());
// User Search
pm.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
pm.addIQProvider("sharedgroup", "http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
pm.addExtensionProvider("addresses", "http://jabber.org/protocol/address", new MultipleAddressesProvider());
// FileTransfer
pm.addIQProvider("si", "http://jabber.org/protocol/si", new StreamInitiationProvider());
pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
// Privacy
pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
pm.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
pm.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
pm.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
pm.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
pm.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
pm.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
}
If you know your way around eclipse, first you need to create a new Java project and add Processing's core.jar to the build path and start by creating a sublcass of PApplet. If not, there's a really easy to work with eclipse plugin called Proclipsing and video guide to get started with it.
Bringing your code from Processing to eclipse:
You need to understand that all the code you have in a Processing sketch (including tabs) gets merged into a single .java file and the sketch name is the class name. Any classes you define in tabs in the sketch become nested classes in a main single class. Easiest way to see this is to export an applet and have a look in the generated folder for the SketchName.java file. Remember, a tab is not a class (although it can contain one).
So you've got a few options. Here are two basic approaches:
Create a new PApplet subclass and start pasting your whole code in it (including content of tabs). You will need to de explicit about accessors (e.g. public void setup() instead of just void setup()) and be careful with double/float values (e.g. if eclipse complains about 1.0, be explicit: 1.0f)
The other option is to create multiple classes, as I imagine you intend to do if you're using eclipse. The catch is, in Processing, variables defined in tabs are actually 'global' variables. Your code would work the same way if you declare those in the main tab at the top. Also, using PApplet functions needs to be refactored. Some functions can be called using Java's classes (not PApplet's) to break the dependency: e.g. System.out.println() instead of println(), but of others you might want your classes to have access to a PApplet instance:
e.g.
public class FilterThread extends Thread {
boolean running; // Is the thread running? Yes or no?
int wait; // How many milliseconds should we wait in between executions?
String id; // Thread name
int count; // counter
YourSketchClass parent;
// Constructor, create the thread
// It is not running by default
FilterThread (int w, String s,YourSketchClass p) {
wait = w;
running = false ;
id = s;
count = 0;
parent = p;
}
int getCount() {
return count;
}
// Overriding "start()"
public void start () {
// Set running equal to true
running = true ;
// Print messages
System.out.println ("Starting thread (will execute every " + wait + " milliseconds.)");
// Do whatever start does in Thread, don't forget this!
super .start();
}
// We must implement run, this gets triggered by start()
public void run () {
while (running) {
parent.checkForNewCalls();
// Ok, let's wait for however long we should wait
try {
sleep((long )(wait));
}
catch (Exception e) {
}
}
System.out.println (id + " thread is done!"); // The thread is done when we get to the end of run()
}
// Our method that quits the thread
void quit() {
System.out.println ("Quitting.");
running = false ; // Setting running to false ends the loop in run()
// IUn case the thread is waiting. . .
interrupt();
}
}
Every class which uses the chat-functionality, needs to know the chat-object. You can put all your variables and functions which are not in a separate class in the main source-file.
When you declare a variable in Processing, it can be used from any tab, in java global variables do not exist. You can get a similar functionality like this: Create a new file GlobalVars.java with this content:
public class GlobalVars {
public static Chat myChat;
}
Now everytime you want to access the Chat-functions, you have to write e.g. GlobalVars.myChat.sendMessage("Hi!");
Btw, You have to include the net.jar-file. On Mac this is located here:
Processing.app/Contents/Resources/Java/modes/java/libraries/net/library/net.jar
I'm developing an application in which I dynamically create forms by reading data from a database. What I want is the user to be able to update or delete the database by using the corresponding button in the database(I am allowing user to connect to almost any database so I have no idea about the type of columns, or whether an update will be supported). I've successfully created code to insert data in any database but I am struggling to figure out a way to update and delete records. This is the code snippet for the class for updating/deleting :
/* tflist contains the list of text fields(I used setName() to set their names to
the column names in the table) which I created dynamically
for allowing the user to enter new values and they already hold the
current values,panel contains all the labels and generated gui which is basically
column name in a label and text field,
e.g. Roll no(label) : 9(in a text field),
tablename has the name of the table,
jtable is the table on which event occurred
(you click on a row of table, and a form appears that gives you the option to
update or delete something),and rowno contains the row number of jtable on which
the user clicked */
private void update_buttonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String querypart2=" WHERE ";
for(int i=0;i<tflist.size();i++)
{
JTextField tf=tflist.get(i);
if(tf.getText()!=null&&!tf.getText().equals(""))
{
if(jtable.getValueAt(rowno, i)==null||jtable.getValueAt(rowno, i).equals(""))
{
querypart2=querypart2+"\""+tf.getName()+"\" IS NULL";
}
else
{
querypart2=querypart2+"\""+tf.getName()+"\"='"+jtable.getValueAt(rowno,i)+"'";
}
querypart2=querypart2+" AND ";
}
}
if(querypart2.equals(" WHERE "))
{
querypart2="";
}
else
{
querypart2=querypart2.substring(0, querypart2.length()-5);
}
try {
Statement statement = Aw_supersensible.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs=statement.executeQuery("SELECT * FROM \""+tablename+"\""+querypart2);
rs.absolute(1);
for(int i=0;i<tflist.size();i++)
{
JTextField tf=tflist.get(i);
rs.updateObject(tf.getName(), tf.getText());
}
Aw_supersensible.conn.commit();
for(int i=0;i<tflist.size();i++)
{
JTextField tf=tflist.get(i);
jtable.setValueAt( tf.getText(),rowno,i);
rs.updateRow();
}
central_window.cw.setEnabled(true);
dispose();
}
catch(final Exception e)
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new errorWindow(new javax.swing.JFrame(),e.toString()).setVisible(true);
}
});
}
}
private void delete_buttonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String querypart2=" WHERE ";
for(int i=0;i<tflist.size();i++)
{
JTextField tf=tflist.get(i);
if(tf.getText()!=null&&!tf.getText().equals(""))
{
if(jtable.getValueAt(rowno, i)==null||jtable.getValueAt(rowno, i).equals(""))
{
querypart2=querypart2+"\""+tf.getName()+"\" IS NULL";
}
else
{
querypart2=querypart2+"\""+tf.getName()+"\"='"+jtable.getValueAt(rowno,i)+"'";
}
querypart2=querypart2+" AND ";
}
}
if(querypart2.equals(" WHERE "))
{
querypart2="";
}
else
{
querypart2=querypart2.substring(0, querypart2.length()-5);
}
try {
Statement statement = Aw_supersensible.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs=statement.executeQuery("SELECT * FROM \""+tablename+"\""+querypart2);
rs.absolute(1);
rs.deleteRow();
((DefaultTableModel)jtable.getModel()).removeRow(rowno);
Aw_supersensible.conn.commit();
central_window.cw.setEnabled(true);
dispose();
}
catch(final Exception e)
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new errorWindow(new javax.swing.JFrame(),e.toString()).setVisible(true);
}
});
}
}
This is some pseudo code for your delete operation, to show you what I think a 'modular' approach would look like.
I am not an experienced developer (in fact I am not a developer), so there may be better ways.
private void delete_buttonActionPerformed(java.awt.event.ActionEvent evt) {
String tableName;
List<String> whereProperties;
List<String> whereValues;
// get your table name
// get your properties and values from the GUI in such a way that the property in whereProperties.get(n) corresponds to the value in whereValues(n)
// have a function in some class (I've called it SQL) that can take the following parameters and performs the delete operation.
SQL.delete(tableName, whereProperties, whereValues);
}