Stuart Hoffman

Greenhorn
+ Follow
since Feb 13, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stuart Hoffman

In case anyone looks at this I found a work around.
The JApplet was not refreshing, possibly due to my JTable which on
doing come summation interupted the paint process.
I added a mouseMotionListener to the Container for the panels in my
JApplet and that worked.
to add the listener I added it to the JApplet
public void init()
{
addMouseMotionListener(this);
...

to avoid making my JApplet abstract I added the following:
public void mouseMoved(MouseEvent event)
{
//System.out.println("Mouse Moved");
container.paintComponents(getGraphics());
}
public void mouseDragged(MouseEvent event)
{
super.repaint(1);
}
the line container.paintComponents.. fires whenever the user moves
their mouse over the JApplet and forces an immediate repaint.
16 years ago
I'm having trouble with my Applet.
When I open up a new window or even pop up a dialog to get input from a user the Applet does not refresh so the screen looks all screwed up.
I sure could use help on this.
Oh yeah, the Applet has a JTable in it as well if that makes a difference.
Thanks
Stuart
16 years ago
Yes,
That was only my thrashing , trying several different datatypes in order to see what worked. Notice that long sum calculation was commented out?
That was the only way I could get it to compile.
Any ideas?
Can't can it and start over though
16 years ago
The column types are
Integer, Varchar2(30),float,float,float,float,float,float,float,float
0 1 2 3 4 5 6 7 8 9
Cols 0 and 9 are not editable.
cols 2-8 will be summed into 9.
Thanks
16 years ago
No I was not aware, thanks.
I changed that line as follows:
try
{
newVector = bottomPanel.getAModel().getDataVector();
newVector.trimToSize();
newString = new String[newVector.size()];
stupidString = newString[1];
//newString[1] = (String)newVector.elementAt(2);
//NEW line below
newString[1] = (String)(((Vector)newVector.elementAt(1)).elementAt(0));
//newString = newVector.toString();
}
and I get the following error:
--
java.lang.ClassCastException: java.math.BigDecimal
void SwingTimeSheet.saveData()
SwingTimeSheet.java:193
--
line 193 is the change in the code. The column
I'm getting back would be an int so what did I do wrong?
16 years ago
I'm having trouble trying to sum values accross the rows in a JTable.
I extended DefaultTableModel for my tableModel then returned a ResultSet via SQLJ to populate the table. The data displays when I run the Applet and I have overridden isCellEditable making cells 1 to 8 editable. Structure of the table is as follows:
ID, Project, hrsMon hrsSun,.................................total hrs
int, String, float, float, float, float, float, float, float, float
The first(0) and last(9) columns are not editable. The last column(9) a float is the total. So when a user puts a value in 2-8 and presses enter
the total should be calculated anew.
currently I have something like this:
public Object getValueAt(Float newVal,int row, int col)
{
BigDecimal sum = new BigDecimal(1);
if(col == 9) // Total column
{
try
{

//sum = new BigDecimal(Float.parseFloat((String)getValueAt(row, 2)) + Float.parseFloat((String)getValueAt(row, 3))
// + Float.parseFloat((String)getValueAt(row, 4)) + Float.parseFloat((String)getValueAt(row, 5))
// + Float.parseFloat((String)getValueAt(row, 6)) + Float.parseFloat((String)getValueAt(row, 7))
// + Float.parseFloat((String)getValueAt(row, 8)));


//sum = BigDecimal.valueOf(Long.parseLong((String)getValueAt(row,2)));
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
// sum = new BigDecimal(0);
}

setValueAt(sum,row,9);

return sum;
}
else
{
return super.getValueAt(row, col);
}

}

-----
I finally had to comment out the calculation because i could not get it to compile. I've changed it so many times that I cannot get the code to work. I don't know if BigDecimal is what I want to return or maybe Object or Float? Float makes sense to my newbie mind as that is the type of the field in the database.
Any help is greatly appreciated.
Thanks
Stuart
16 years ago
Having great difficulty getting the data out of my JTable once it is populated and then the data is changed by the user. I extended DefaultTableModel for my tableModel then returned a ResultSet via SQLJ to populate the table. The data displays when I run the Applet and I have overridden isCellEditable making cells 1 to 8 editable. Structure of the table is as follows:
ID, Project, hrsMon hrsSun,total hrs
int, String, float, float, float, float, float, float, float, float
When I call getDataVector and try to display the data (for debug, what I really need to do is post changes to the db: oracle by the way) I get back null.
Code Snippet for accessing getDataVector:
private void saveData()
{
Vector newVector;
String newString[];// = new String[10];
String stupidString;
try
{
newVector = aModel.getDataVector();
newVector.trimToSize();
newString = new String[newVector.size()];
//just testing to see if I can show one element from the Vector. What
//I'll really do is pass the Vector to a SQLJ servlet then parse the data
//out and insert into the db.
stupidString = newString[1];
//newString[1] = (String)newVector.elementAt(2);
//newString = newVector.toString();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
newString = new String[10];
stupidString ="err";
}
JOptionPane.showMessageDialog(null,"Record = "+stupidString);
//return newString;
}
As you can see I tried a couple different ways of getting the data out of the Vector but have met with defeat.
Tried the tutorial using tables and this part seems to be assumed that we'd know how to do it.
Any help will be greatly appreciated.
Thanks
Stuart
16 years ago
Amy, I'm a newbie but is it possible in this piece of the code that the for loop is executed too many times since it is inside of a while loop?
while(rs.next()){Object[] row = new Object[cols];for (int j = 0; j < row.length; j++){row[j] = rs.getObject(j + 1);cache.add(row);}}

Hope that helps
Stuart
16 years ago