Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Old stuff contaminates newly input code files.(corruption latency retained-error frustrations)
Old stuff contaminates newly input code files. [message #1785011] Sat, 07 April 2018 04:13 Go to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 62
Registered: March 2018
Member
When the kind of failure of Windowbuilder reported by Peter Reams occurs, it not only impedes progress for the moment but can also can corrupt the software. In one period of frustration with this system, it objected to some unknown feature of a new version of code and as I tried to get back to the source code and then debug it, I found that more and more of the predecessor files in the same directory had their icons turn red. Luckily I did not delete them, because the next time I rebooted the computer most of them had returned to being "normal."

Eclipse seems to keep a record of the attempts that have failed disastrously, and in one case my only recourse was to copy out the code, open up a new work area, and recreate the files using Windowbuilder to give me a skeleton on which I could copy in the txt documents.

It seems advisable to change to a new work area every time some degree of success is obtained. Eclipse seems to keep a common cache of information regarding all the projects in the same work area.

Is there any document that discusses pitfalls of the system and how to avoid them?

Here is a copy of what I was working on when everything went nasty. I don't claim it is right. I was working on some warnings and some other problems while expending the program to later parts of the ProgrammingKnowledge tutorials.
===========


import java.awt.BorderLayout; //This is based on and extends Ream's version.
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FocusTraversalPolicy;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import net.proteanit.sql.DbUtils;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
//import java.sql.PreparedStatement;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JComboBox;

public class EmployeeInfo extends JFrame {

private JPanel contentPane;
private JTable table;
private JComboBox comboBoxName;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
EmployeeInfo frame = new EmployeeInfo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

Connection connection = null;
private JTextField textFieldEID;
private JTextField textFieldName;
private JTextField textFieldSurname;
private JTextField textFieldAge;
private String query;

public void refreshTable()
{
try
{
query = "select * from EmployeeInfo";
// String query = "select EID, Name, Surname, Age from EmployeeInfo";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
pst.close();

}
catch (Exception e1)
{
e1.printStackTrace();
}
}


/* ==================-------========================================================*/
public void fillComboBox()
{ //1
try { //2

// query = "select EID, Name, Surname, Age from EmployeeInfo";
query = "select * from EmployeeInfo";

PreparedStatement pst = connection.prepareStatement (query);
ResultSet rs = pst.executeQuery ();

while(rs.next())
{ // 3
comboBoxName.addItem(rs.getString("Name"));
}//3

/*2*/ }catch (Exception e){ //4
e.printStackTrace();
} //4

} //1

/* ==================-------========================================================*/
/**
* Create the frame.
*/
public EmployeeInfo()
{
// connect to data base
connection = sqliteConnection.dbConnector();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 655, 418);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JButton btnLoadTable = new JButton("Load Employee Data");
btnLoadTable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
query = "select * from EmployeeInfo";
// String query = "select EID, Name, Surname, Age from EmployeeInfo";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
pst.close();

}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
btnLoadTable.setBounds(392, 48, 206, 29);
contentPane.add(btnLoadTable);

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(304, 100, 345, 275);
contentPane.add(scrollPane);

table = new JTable();
scrollPane.setViewportView(table);

// added for grid lines, default is white
table.setGridColor(Color.black);

comboBoxName = new JComboBox();//
comboBoxName.setBounds(31, 35, 216, 55);//
contentPane.add(comboBoxName);//
refreshTable();//
fillComboBox();//

JLabel lblNewLabel = new JLabel("EID");
lblNewLabel.setBounds(24, 168, 61, 16);
contentPane.add(lblNewLabel);

JLabel lblName = new JLabel("Name");
lblName.setBounds(24, 196, 61, 16);
contentPane.add(lblName);

JLabel lblSurname = new JLabel("Surname");
lblSurname.setBounds(24, 224, 61, 16);
contentPane.add(lblSurname);

JLabel lblAge = new JLabel("Age");
lblAge.setBounds(24, 252, 61, 16);
contentPane.add(lblAge);

textFieldEID = new JTextField();
textFieldEID.setBounds(113, 157, 134, 28);
contentPane.add(textFieldEID);
textFieldEID.setColumns(10);

textFieldName = new JTextField();
textFieldName.setBounds(113, 190, 134, 28);
contentPane.add(textFieldName);
textFieldName.setColumns(10);

textFieldSurname = new JTextField();
textFieldSurname.setBounds(113, 218, 134, 28);
contentPane.add(textFieldSurname);
textFieldSurname.setColumns(10);

textFieldAge = new JTextField();
textFieldAge.setBounds(113, 246, 134, 28);
contentPane.add(textFieldAge);
textFieldAge.setColumns(10);

// Vector<Component> order = new Vector<Component>(5);
// order.add(textFieldEID);
// order.add(textFieldName);
// order.add(textFieldSurname);
// order.add(textFieldAge);
// order.add(table);
// newPolicy = new MyOwnFocusTraversalPolicy(order);

// MyOwnFocusTraversalPolicy newPolicy = new MyOwnFocusTraversalPolicy();
// contentPane.setFocusTraversalPolicy(newPolicy);

JButton btnSave = new JButton("Save");
btnSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
try
{
query = "insert into EmployeeInfo (EID, Name, Surname, Age) values(?, ?, ?, ?)";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, textFieldEID.getText());
pst.setString(2, textFieldName.getText());
pst.setString(3, textFieldSurname.getText());
pst.setString(4, textFieldAge.getText());
// ResultSet rs = pst.executeQuery(); Was wrong on the video.
//JOptionPane.showMessageDialog(null, "Data saved");

pst.execute();
JOptionPane.showMessageDialog(null, "Data saved");

pst.close();
}
catch (Exception e1)
{
JOptionPane.showMessageDialog(null, "Something went wrong in the save routine.");
}
//refreshTable();
}
});
btnSave.setBounds(64, 292, 117, 29);
contentPane.add(btnSave);

JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
query = "update EmployeeInfo set EID='"+textFieldEID.getText()+"',name='"+textFieldName.getText()+"',Name ='"+ textFieldSurname.getText()+"', Age ='"+textFieldAge.getText()+"' where EID='"+textFieldEID.getText()+ "'";
// up to tutorial #12 https://www.youtube.com/watch?v=ocRJ2UPKGRU

PreparedStatement pst = connection.prepareStatement(query);

pst.execute();
JOptionPane.showMessageDialog(null, "Data updated");

pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
refreshTable();
}
});
btnUpdate.setBounds(64, 325, 117, 29);
contentPane.add(btnUpdate);

JButton btnDelete = new JButton("Delete");
btnDelete.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{

PreparedStatement pst = connection.prepareStatement(query);

pst.execute();
JOptionPane.showMessageDialog(null, "Data deleted");

pst.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
refreshTable();
btnDelete.setBounds(64, 361, 117, 29);
contentPane.add(btnDelete);
}



}



);
}
}

Re: Old stuff contaminates newly input code files. [message #1785013 is a reply to message #1785011] Sat, 07 April 2018 04:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29555
Registered: July 2009
Senior Member
It's probably better to ask about this on the WindowBuilder forum: https://www.eclipse.org/forums/index.php/f/214/
Previous Topic:How to Always Show Scrollbars in Eclipse Oxygen
Next Topic:Cloud workspace
Goto Forum:
  


Current Time: Wed Sep 26 07:09:47 GMT 2018

Powered by FUDForum. Page generated in 0.03594 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top