Int/Double Workaround for an imported class
Hi,
I've been having a heck of a time trying to figure something out. I have a bunch of data that is in double format (eg 10.351). However, I'm importing a class awt.Polygon for a bunch of reasons, and one of it's key methods (addPoints();) only accepts integers.
What I would like to do is take my double value, multiply it by enough so that it can be cast into an int without losing an data, than manipulate it with the addPoint function.
I was thinking it would look something like:
public class chsShape extends Polygon{
public void addPointDoub(Double x, Double y)
int xi =(int)(x*1000);
int yi =(int)(y*1000);
addPoint( xi, yi);
} Obviously, this doesn't work (or I wouldn't be posting). It gives me "java.lang.NoSuchMethodError:chsShape.addPointDoub".
Anyone have any suggestions? Thanks!
Double posted and answered.
http://forum.java.sun.com/thread.jspa?threadID=5253042&tstart=0
Similar Messages
-
Int/Double workaround with an imported class.
Hi,
I've been having a heck of a time trying to figure something out. I have a bunch of data that is in double format (eg 10.351). However, I'm importing a class awt.Polygon for a bunch of reasons, and one of it's key methods (addPoints();) only accepts integers.
What I would like to do is take my double value, multiply it by enough so that it can be cast into an int without losing an data, than manipulate it with the addPoint function.
I was thinking it would look something like:
public class chsShape extends Polygon{
public void addPointDoub(Double x, Double y)
int xi =(int)(x*1000);
int yi =(int)(y*1000);
addPoint( xi, yi);
} Obviously, this doesn't work (or I wouldn't be posting). It gives me "java.lang.NoSuchMethodError:chsShape.addPointDoub".
Anyone have any suggestions? Thanks!Here is a demo using the PathIterator:
import java.awt.geom.*;
public class GeneralPathExample {
public static void main(String[] args) {
GeneralPath p = new GeneralPath();
p.moveTo(1,1);
p.lineTo(1,2);
p.lineTo(2,2);
p.lineTo(2,1);
p.closePath();
double[] coords = new double[6];
for (PathIterator i = p.getPathIterator(null);!i.isDone(); i.next()) {
switch(i.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
System.out.format("moveTo(%f,%f)%n", coords[0], coords[1]);
break;
case PathIterator.SEG_LINETO:
System.out.format("lineTo(%f,%f)%n", coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE:
System.out.println("closePath()");
break;
default:
System.out.println("too lazy to code other cases...");
}Perhaps what may prove more useful to you is to have a shape, GeneralPath, plus maintain a separate list of points, for easy access. The thing is, a GeneralPath is more than a list of points: it can include curved segments and gaps, etc... -
Compilation Error for import classes not found in generated Proxy Class
Hi,
We are generating java classes for the COM dll using JCOM com2java compiler.
We are getting a compilation error for import class not found when compiling the
generated Proxy java source code. It can't find the com.bea.jcom.Dispatch class that
the generated Proxy java source code extends. It also can't find com.bea.jcom.Variant
or com.bea.jcom.Param. These are interfaces or data types or classes used by COM
library.
I added weblogic.jar to my class path and the only Dispatch class i found inside
the weblogic.jar is com.linar.jintegra.Dispatch;
We have com objects for which we want to develop an EJB client to interface with
the COM object using JCOM with Native Mode disabled.
Any help on the compilation error..I tried changing the extends for Dispatch to com.linar.jintegra.Dispatch
but the other errors are still there.
To begin with, I think the generated code should not refer to any of the COM data
types.
Any help please.
Thank you in advance,
Regards,
Rahul Srivastava
[email protected]Hi,
I resolved the other errors by changing all references from com.bea.jcom.Variant
etc to com.linar.jintegra.class name..all were present under the com.linar.jintegra
package.
Thank you all anyways,
Regards,
rahul
"Rahul Srivastava" <[email protected]> wrote:
>
Hi,
We are generating java classes for the COM dll using JCOM com2java compiler.
We are getting a compilation error for import class not found when compiling
the
generated Proxy java source code. It can't find the com.bea.jcom.Dispatch
class that
the generated Proxy java source code extends. It also can't find com.bea.jcom.Variant
or com.bea.jcom.Param. These are interfaces or data types or classes used
by COM
library.
I added weblogic.jar to my class path and the only Dispatch class i found
inside
the weblogic.jar is com.linar.jintegra.Dispatch;
We have com objects for which we want to develop an EJB client to interface
with
the COM object using JCOM with Native Mode disabled.
Any help on the compilation error..I tried changing the extends for Dispatch
to com.linar.jintegra.Dispatch
but the other errors are still there.
To begin with, I think the generated code should not refer to any of the
COM data
types.
Any help please.
Thank you in advance,
Regards,
Rahul Srivastava
[email protected] -
How can I use a 1 double array for this
I would like to use one double array where I am using 2 single arrays, can this be done?
thanks
import java.text.NumberFormat;
import java.util.Locale;
class Mortgage3
public static void main(String[]argv)
//Variables
//allows for currency format
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);
double prin;
double month_payments;
double monthlyinterest;
//standard integer
int months;
//array for the different interest rates
double[] interest = {0.0535,0.055,0.0575};
//array for the different terms
int[] term = {7, 15, 30};
for (int i = 0; i < 3; i++)
//values for the variables
prin = 200000; //principle amount of the mortgage
monthlyinterest = (interest[i] / 12); //monthly interest
months = (term[i] * 12); //total amount of months in the 30 yr term
//monthly payment calculation
month_payments = (prin * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));
System.out.println("\n\n\t For a loan amount of " + formatter.format(prin));
System.out.println("\t With an annual interest rate of " +interest[i] * 100+ "%,");
System.out.println("\t your payments will be " +formatter.format(month_payments)+ " per month");
System.out.println("\t for a term of "+term[i]+ " years or " +months+" months.");
}I would like to use one double array where I am using 2 single arrays, can this be done?It can, but why not write a Rate class or other data structure more suited to the purpose?
-
Importing classes in Jsdk 1.4.2
Hi,
I have two swing applications that run perfectly well when compiled and run. But then I am trying to include these two programs as two tabbed panes in a third program.
I try to import classes from the other two programs using a simple import statement. But when I compile it the compiler return an error statement.
I tried putting a package line in both the programs and tried importing it as a package in the third one and it says invalid package name.
Can anybody help.
Thanks in advance.OK here is the code. This is a example code from the book Java2 from scratch
First file
PortfoilioTotalsPanel.java
// Import the packages used by this class
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
// PortfolioTotalsPanel Class
public class PortfolioTotalsPanel extends JPanel
// Define the dark green color
public final static Color darkGreen = new Color( 0, 150, 40 );
// Create our labels
JLabel lblDollarChange = new JLabel( "Dollar Change:", JLabel.CENTER );
JLabel lblPercentChange = new JLabel( "Percent Change:", JLabel.CENTER );
// Constructor
public PortfolioTotalsPanel()
// Set the layout manager
setLayout( new GridLayout( 2, 1 ) );
// Add the labels to the JPanel
add( lblDollarChange );
add( lblPercentChange );
// setDollarChange( fDollarChange )
// Set the Dollar Change label to the dollar amount in fDollarChange
public void setDollarChange( Float fDollarChange )
// Set color based off of value
if( fDollarChange.floatValue() > 0 )
// Green for positive
lblDollarChange.setForeground( darkGreen );
else if( fDollarChange.floatValue() < 0 )
// Red for negative
lblDollarChange.setForeground( Color.red );
else
// Black for no change
lblDollarChange.setForeground( Color.black );
// Set the label text
lblDollarChange.setText( "Dollar Change: $" + fDollarChange.toString() );
// setPercentChange( fPercentChange )
// Set the Percent Change label to the percent in fDollarChange
public void setPercentChange( Float fPercentChange )
// Set color based off of value
if( fPercentChange.floatValue() > 0 )
// Green for positive
lblPercentChange.setForeground( darkGreen );
else if( fPercentChange.floatValue() < 0 )
// Red for negative
lblPercentChange.setForeground( Color.red );
else
// Black for no change
lblPercentChange.setForeground( Color.black );
// Set the label text
lblPercentChange.setText( "Percent Change: " + fPercentChange.toString() + "%" );
// Main application entry point into this class
public static void main( String[] args )
// Create a JFrame object
JFrame frame = new JFrame( "Portfolio Totals" );
// Create an PortfolioTotalsPanel Object
PortfolioTotalsPanel app = new PortfolioTotalsPanel();
// Set the values of the labels
app.setDollarChange( new Float( "-150.50" ) );
app.setPercentChange( new Float( "15" ) );
// Add our PortfolioTotalsPanel Object to the JFrame
frame.getContentPane().add( app, BorderLayout.CENTER );
// Resize our JFrame
frame.setSize( 600, 100 );
// Make our JFrame visible
frame.setVisible( true );
// Create a window listener to close our application when we
// close our application
frame.addWindowListener
new WindowAdapter()
public void windowClosing( WindowEvent e )
System.exit( 0 );
Second Program
// ===========================================================================
// File: StockTablePanel.java
// Description: Sample file for Java 2 From Scratch
// ===========================================================================
// Import the libraries this application will use
import javax.swing.JTable;
import javax.swing.table.*;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
// Main application class: StockTablePanel
public class StockTablePanel extends JPanel
// Create a new Stock Table Model object
StockTableModel stockTableModel = new StockTableModel();
// Create a new JTable and associate it with the StockTableModel
JTable stockTable = new JTable( stockTableModel );
// Constructor
public StockTablePanel()
// Set the size of the table
stockTable.setPreferredScrollableViewportSize( new Dimension(620, 350) );
// Set the column widths for the table
TableColumn column = null;
for (int i = 0; i < 5; i++)
column = stockTable.getColumnModel().getColumn( i );
column.setPreferredWidth( stockTableModel.getColumnWidth( i ) );
// Create a scroll pane and add the stock table to it
JScrollPane scrollPane = new JScrollPane( stockTable );
// Add the scroll pane to our panel
add( scrollPane, BorderLayout.CENTER );
// float getDollarChange()
// Computes the total dollar change for the current portfolio
public float getDollarChange()
// Create a variable to hold the total change for all stocks
float fTotal = 0;
// Loop through all rows in the table
for( int i=0; i<stockTable.getRowCount(); i++ )
// Retrieve the dollar change for this stock
Float f = ( Float )stockTable.getValueAt( i, 10 );
// Add that value to our total
fTotal = fTotal + f.floatValue();
// Return the total value
return fTotal;
// float getPercentChange()
// Computes the total percentage change for the current portfolio
public float getPercentChange()
// Create a couple variables to hold the total the user spent
// on the stocks and the current value of those stocks
float fMoneySpent = 0;
float fMoneyWorth = 0;
// Loop through all rows in the table
for( int i=0; i<stockTable.getRowCount(); i++ )
// Extract some pertinent information for the computations
Float fLastSale = ( Float )stockTable.getValueAt( i, 2 );
Float fNumberOfShares = ( Float )stockTable.getValueAt( i, 6 );
Float fPricePaidPerShare = ( Float )stockTable.getValueAt( i, 7 );
// Add the amount of money the user spent on this stock
// to the total spent
fMoneySpent += fNumberOfShares.floatValue() * fPricePaidPerShare.floatValue();
// Add the value of this stock to the total value of the
// stock
fMoneyWorth += fNumberOfShares.floatValue() * fLastSale.floatValue();
// Compute the percentage change:
// TotalValue/TotalSpent * 100% - 100%
float fPercentChange = ( (fMoneyWorth / fMoneySpent) * 100 ) - 100;
// Return the percentage change
return fPercentChange;
// Main entry point into the StockTableApplication class
public static void main( String[] args )
// Create a frame to hold us and set its title
JFrame frame = new JFrame( "StockTablePanel Application" );
// Create an instance of our stock table panel
StockTablePanel stockTablePanel = new StockTablePanel();
// Add our tab panel to the frame
frame.getContentPane().add( stockTablePanel, BorderLayout.CENTER );
// Resize the frame
frame.setSize(640, 480);
// Make the windows visible
frame.setVisible( true );
// Set up a window listener to close the application window as soon as
// the application window closes
frame.addWindowListener
new WindowAdapter()
public void windowClosing( WindowEvent e )
System.exit( 0 );
// Table Model Class - holds all of our row and column information
class StockTableModel extends AbstractTableModel
// Create the columns for the table
final String[] strArrayColumnNames =
"Sym",
"Company Name",
"Last",
"Hi",
"Lo",
"Vol",
"#Shares",
"$Shares",
"Total",
"%Change",
"$Change"
// Create the rows for the table - hard coded for now!!
final Object[][] obArrayData =
// Row One
"SAMS", // Symbol
"Sams Publishing", // Company Name
new Float( 10 ), // Last Sale
new Float( 12 ), // High
new Float( 8 ), // Low
new Double( 2000000 ), // Volume
new Float( 100 ), // Number of Shares Owned
new Float( 7.5 ), // Purchase price per share
new Float( 1000 ), // Total Holdings
new Float( 33 ), // Percent change (increase!)
new Float( 250 ) // Dollar change
// Row Two
"Good", // Symbol
"Good Company", // Company Name
new Float( 50 ), // Last Sale
new Float( 52 ), // High
new Float( 45 ), // Low
new Double( 4000000 ), // Volume
new Float( 100 ), // Number of Shares Owned
new Float( 30 ), // Purchase price per share
new Float( 5000 ), // Total Holdings
new Float( 33 ), // Percent change (increase!)
new Float( 250 ) // Dollar change
// Row Three
"BAD", // Symbol
"Bad Company", // Company Name
new Float( 20 ), // Last Sale
new Float( 22 ), // High
new Float( 18 ), // Low
new Double( 2000000 ), // Volume
new Float( 500 ), // Number of Shares Owned
new Float( 50 ), // Purchase price per share
new Float( 10000 ), // Total Holdings
new Float( -60 ), // Percent change (increase!)
new Float( -25000 ) // Dollar change
// Return the number of columns in the table
public int getColumnCount()
return strArrayColumnNames.length;
// Return the number of rows in the table
public int getRowCount()
return obArrayData.length;
// Get the column name from the strArrayColumnNames array for the "col"-th
// item
public String getColumnName( int col )
return strArrayColumnNames[col];
// Return the value, in the form of an Object, from the obArrayData object
// array at position (row, col)
public Object getValueAt( int row, int col )
// We will compute columns 8, 9, and 10, so if the column number is
// below eight, we can just return it without computing or retrieving
// anything.
if( col < 8 )
return obArrayData[row][col];
// Retrive the necessary values from the object array to compute all
// of the remaining columns
Float fLastSale = ( Float )obArrayData[row][2];
Float fNumberOfShares = ( Float )obArrayData[row][6];
Float fPurchasePrice = ( Float )obArrayData[row][7];
switch( col )
// Total Holdings = Last Sale(2) * Number of Shares Owned(6)
case 8:
// Build a new Float object with the product of the two
Float fTotal = new Float
// Note, these have to be converted to type "float" to
// perform the multiplication
fLastSale.floatValue() * fNumberOfShares.floatValue()
// Return the result
return( fTotal );
// Percent change =
// (Last Sale Price (2) / Purchase Price (7)) * 100% - 100 %
case 9:
Float fPercentChange = new Float
((fLastSale.floatValue() / fPurchasePrice.floatValue ()) * 100) - 100
return fPercentChange;
// Dollar Change =
// LastSale*NumberOfShares - PurchasePrice * NumberOfShares
case 10:
Float fDollarChange = new Float
( fLastSale.floatValue() * fNumberOfShares.floatValue() )
( fPurchasePrice.floatValue() * fNumberOfShares.floatValue() )
return fDollarChange;
// We have included every case so far, but in case we add another
// column and forget about it, let's just return its value
default:
return obArrayData[row][col];
// Return the class type, in the form of a Class, for the c-th column in
// the first (0-th indexed) element of the obArrayData object array
public Class getColumnClass( int c )
return getValueAt(0, c).getClass();
// Return true if the "col"-th column of the table is editable, false
// otherwise. The following columns are editable:
// Cell Description
// 0 Symbol
// 6 Number of Shares Owned
// 7 Purchase Price per Share
public boolean isCellEditable(int row, int col)
// Check the column number
if( col == 0 || col == 6 || col == 7 )
return true;
else
return false;
// Set the value of the (row, col) element of the obArrayData to value
public void setValueAt(Object value, int row, int col)
// Symbol
if( col == 0 )
// We need a string value - we can convert any
// value to a string, so just assign it
obArrayData[row][col] = value;
// Number of Shares owned
else if( col == 6 )
// We need a number - either float or int
obArrayData[row][col] = new Float( getNumberString( value.toString() ) );
// Purchase Price per share
else if( col == 7 )
// We need a float
obArrayData[row][col] = new Float( getNumberString( value.toString() ) );
// Cell is not editable
else
return;
// Notify our parent of the change
fireTableCellUpdated(row, col);
// String getNumberString( String str )
// Read through str and return a new string with the numbers and decimal
// points contained in str
public String getNumberString( String str )
// Get str as a character array
char[] strSource = str.toCharArray();
// Create a buffer to copy the results into
char[] strNumbers = new char[strSource.length];
int nNumbersIndex = 0;
// Boolean to ensure we only have one decimal value
// in our number
boolean bFoundDecimal = false;
// Loop through all values of str
for( int i=0; i<strSource.length; i++ )
// Check for a digit or decimal point
if( Character.isDigit( strSource[i] ) )
strNumbers[nNumbersIndex++] = strSource;
else if( strSource[i] == '.' && !bFoundDecimal )
// Append the character to the String
strNumbers[nNumbersIndex++] = strSource[i];
// Note that we found the decimal value
bFoundDecimal = true;
// Build a new string to return to our caller
String strReturn = new String( strNumbers, 0, nNumbersIndex );
// Return our string
return strReturn;
// Return the column width of the column at index nCol
public int getColumnWidth( int nCol )
switch( nCol )
case 0:
case 2:
case 3:
case 4:
case 6:
case 7:
case 9:
return 50;
case 1:
return 125;
default:
return 75;
Third one that imports the previous two programs Classes
// Import the packages used by this class
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
// Import our other components
import StockTablePanel;
import PortfolioTotalsPanel;
// StockTableTabPanel
public class StockTableTabPanel extends JPanel implements TableModelListener
// Create our panels
StockTablePanel stockTablePanel = new StockTablePanel();
PortfolioTotalsPanel portfolioTotalsPanel = new PortfolioTotalsPanel();
// Constructor
public StockTableTabPanel()
// Set our layout
setLayout( new BorderLayout() );
// Initialize the portfolio panel
updatePortfolioTotals();
// Add the child panels to our JPanel
add( stockTablePanel );
add( portfolioTotalsPanel, BorderLayout.SOUTH );
// Add our class as a table model listener for the stock table
// model so that we can update the portfolio totals panel
// whenever the table changes.
stockTablePanel.stockTableModel.addTableModelListener( this );
// TableModelListener: tableChanged
public void tableChanged(TableModelEvent e)
// Make sure it is our table that changed
if( e.getSource() == stockTablePanel.stockTableModel )
// Call our method to update the portfolio totals
updatePortfolioTotals();
// public updatePortfolioTotals
// Updates the portfolio totals panel labels based off of the values
// in the stockTablePanel
public void updatePortfolioTotals()
// Get the values from the stockTablePanel and send them
// to the portfolioTotalsPanel
portfolioTotalsPanel.setDollarChange( new Float( stockTablePanel.getDollarChange() ) );
portfolioTotalsPanel.setPercentChange( new Float( stockTablePanel.getPercentChange() ) );
// Main application entry point into this class
public static void main( String[] args )
// Create a JFrame object
JFrame frame = new JFrame( "Stock Table Tab" );
// Create an StockTableTabPanel Object
StockTableTabPanel app = new StockTableTabPanel();
// Add our StockTableTabPanel Object to the JFrame
frame.getContentPane().add( app, BorderLayout.CENTER );
// Resize our JFrame
frame.setSize( 640, 440 );
// Make our JFrame visible
frame.setVisible( true );
// Create a window listener to close our application when we
// close our application
frame.addWindowListener
new WindowAdapter()
public void windowClosing( WindowEvent e )
System.exit( 0 ); -
Using double/floats for co ordinates?
hi is it possible to use float/double values for the following code or simlar?
g.drawImage(cards, 0.5, 0.8, this);
does the drawimage on support ints?Update and demo: Am I the only one who is forever tweaking rendering hints
to get the right effect? Anyhowdy, I think INTERPOLATION was the hint I needed
to tweak to get subpixel shifting of images:
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
public class ShiftyExample extends JPanel {
private BufferedImage image;
private float delta;
public ShiftyExample(BufferedImage image, float delta) {
this.image = image;
this.delta = delta;
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawRenderedImage(image, null);
g2.drawRenderedImage(image, AffineTransform.getTranslateInstance(delta, 0));
g2.dispose();
public static void main(String[] args) {
EventQueue.invokeLater(new GuiBuilder());
static class GuiBuilder implements Runnable {
public void run() {
BufferedImage image = createImage();
JPanel cp = new JPanel(new GridLayout(1,0));
cp.add(new ShiftyExample(image, 0f));
cp.add(new ShiftyExample(image, 0.5f));
cp.add(new ShiftyExample(image, 1f));
cp.add(new ShiftyExample(image, 1.5f));
cp.add(new ShiftyExample(image, 2f));
JFrame f = new JFrame("ShiftyExample");
f.setContentPane(cp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,200);
f.setLocationRelativeTo(null);
f.setVisible(true);
BufferedImage createImage() {
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.BLACK);
g.drawLine(10,0,10,100);
g.dispose();
return image;
}Explanation: the image is a vertical black line on a clear background.
What you see on the frame are five versions of the image displayed
against a shifted copy of itself, shift 0, 0.5, 1, 1.5 and 2 units. If you really stare at the
fractional examples, you will see gray pixels being used instead of just black
and white. Woop-de-doo... -
Apache POI Word support - workaround for a write bug
Hi all,
Just finished battling with the bugs in POI HWPF component. When searching forums, I found more questions than answers so I wanted to save others a significant effort until POI guys implement all the fixes.
Basically, the synopsis is, all the delete() methods are broken and replacing a string with a string of a different size corrupts the document. But insertAfter and insertBefore methods are mostly working.
I did not want to add a method to their class, because it will probably be overwritten. On the other hand, it is unknown when it will be fixed. Therefore, I had to go via reflection.
Here's the method, just attach it to your class and it's ready to use:
* Replaces text in the paragraph by a specified new text.
* @param r A paragraph to replace.
* @param newText A new text.
* @throws Exception if anything goes wrong
protected void setParagraphText(Paragraph r, String newText) throws Exception {
int length = r.text().length() - 1;
Class clRange = Range.class;
Field fldText = clRange.getDeclaredField("_text");
fldText.setAccessible(true);
Field fldTextEnd = clRange.getDeclaredField("_textEnd");
fldTextEnd.setAccessible(true);
Field fldStart = clRange.getDeclaredField("_start");
fldStart.setAccessible(true);
List textPieces = (List)fldText.get(r);
int _textEnd = fldTextEnd.getInt(r);
TextPiece t = (TextPiece)textPieces.get(_textEnd - 1);
StringBuffer sb = t.getStringBuffer();
int offset = fldStart.getInt(r);
int diff = newText.length() - length;
if (diff <= 0) {
// delete doesn't work properly yet, corrupting the documents.
// Therefore a quick and ugly workaround is to pad the new text with spaces
for (int i = 0; i < -diff; i++)
newText += " ";
sb.replace(offset, offset + length, newText);
} else {
// when the new text is longer, the old one must be replaced
// character by character, and the difference is added using
// insertAfter method
if (r.isInTable()) {
// more obstacles when working with tables though.
// Not only the regular insertAfter does not work,
// but also insertAfter called from a cell overruns cell delimiters.
// Needless to say, getTable(r) does not return the required table.
// Fortunately, there's a workaround
TableIterator ti = new TableIterator(range);
TableCell tc;
while (ti.hasNext()) {
Table tbl = ti.next();
for (int i = 0; i < tbl.numRows(); i++) {
TableRow tr = tbl.getRow(i);
for (int j = 0; j < tr.numCells(); j++) {
tc = tr.getCell(j);
if (tc.text().startsWith(sb.substring(offset, offset + length))) {
sb.replace(offset, offset + length,
newText.substring(newText.length() - length));
// only like this, otherwise cell delimiter will be run over
tc.insertBefore(newText.substring(0, newText.length() - length));
return;
sb.replace(offset, offset + length, newText.substring(0, length));
} else {
sb.replace(offset, offset + length, newText.substring(0, length));
r.insertAfter(newText.substring(length));
}user8984775 wrote:
My requirement is I need to apply this formula for Entire column to achieve the need like
When user enters data in col2 (B) of greater than the number specified in col1 (A) and then show the ErrorBox.
I am able to get the formula working through code only for first cell as per below code... I want it to dynamically apply for the entire column. Well I'm certainly no expert on POI, but that looks like a very odd formula to me.
When you "pull" a formula down a column, Excel automatically changes the formula for each row, but because you've fixed both the column AND the row ($A$1), it'll be the same in all cases.
I don't know if POI allows that sort of "auto-generate" for formulas, but if so try something like $A1 instead; otherwise I suspect you'll need a different formula for each row.
Winston -
I was reading the tutorial on importing class's. This is what
I read
Importing classes
To reference a class in another script, you must prefix the
class name with the class's package path. The combination of a
class's name and its package path is the class's fully qualified
class name. If a class resides in a top-level classpath
directory--not in a subdirectory in the classpath directory--then
its fully qualified class name is its class name.
To specify package paths, use dot (.) notation to separate
package directory names. Package paths are hierarchical, where each
dot represents a nested directory. For example, suppose you create
a class named Data that resides in a com/xyzzycorporation/ package
in your classpath. To create an instance of that class, you could
specify the fully qualified class name, as shown in the following
example:
var dataInstance = new com.xyzzycorporation.Data();
My Question is about com/xyzzycorporation/ . would the full
class parth be c:/com/xyzzycorporation/ . Why do they never state
the drive letter when teaching about directories.Because there is no need. you don't need to reference the
drive letter.
Here's the basic jist of what they are saying....
Single Class File...
If you create your own custom class and want to use it in
your flash file, save it into the same directory as the fla file
and call the classes constructor. By default flash will look inside
the folder where the fla resides in for the class files if it
cannot find it inside the default directory.
Multiple Class Files - 1 Project (often referred to as
packages)
Use your qualified domain name but backwards.....
my domain is www.sd-dezign.com so if I was going to include a
package of utility class files in my document I would do the
following
Create a folder in the same folder with my fla name it com
and inside that a folder called sddezign and inside that utils and
all my as files would be in there...the folder structure might look
like this....
myfile.fla
com
>sddezign
>>utils
>>>box.as
>>>circle.as
To call the constructor for each class, I have two options.
The first which is by far the easiest looks like this
In whatever frame you need to call that class constructor
include "com.sddezign.utils.*";
var myBox:Box = new Box();
The second method requires more typing and can get tedious
var myBox = new com.sddezign.utils.Box();
Hope this helps you a bit better. -
Not allowed to import classes without package names?
Hi,
I have a few questions on Packages and importing?
1. Is the following true that it is illegal to import classes in the same package as the current class, will this cause a comilation error? If this is the case where in the Java Language specification is this actually written as I could not find it?
2. This has probably been answered by question 1 but if I have 2 classes in the same package and if I import 1 of the classes into the other class, is it illegal to import it by just using the class name and not the package name as well, ie
if the package name is ie.tcd
and the 2 class names are exp1.class and exp2.class, can I do this in class 2
package ie.tcd;
import exp1;
public class exp2 {
3. Is it illegal to import classes that are not explicitly part of any package or must a class be part of a package to be imported. I read somewhere that while this was always illegal it is only after jdk 1.4.2 that this is being enforced? If this is the case where in the Java Language specification is this actually written as I could not find it either?
Thanks very much for any help,
JohnWas just also wondering, 1 other thing, I am looking
at someone elses code they have 2 classes (Class A
and Class B) in the same package (pkg). The person
imports class A into B:
package pkg;
import A;
public class B {
Is this legal code (or was it ever)?Not if A is really in pkg.A. If there is an A in the unnamed package it was legal, or at least it was understood by the compiler, and now it isn't (to both).
Can you import or is there a point in importing a class in the same
package?Only by naming the package in the import statement. If the current and the import statement are in the same package the import is redundant.
If there is a point would you import just be
using the class name (this would be illegal after jdk
1.4) or should you use the whole package name even
though it is in the package anyways?As I understand it you must always use the whole package name in imports. -
Final Cut Pro X 10.2 crashes when I try to convert old libraries for use in the new software. Is there a workaround for this? Or will I have to continue using the previous version to complete older projects? the only foreseeable solution is to begin any new projects on 10.2 or importing footage on 10.2 and starting form scratch--which is something i definitely don't want to do or have time to do. ANY advice, thoughts, or opinions would be greatly appreciated! Thank you!
Running 10.10.3 // MacBook Pro (Retina, 15-inch, Early 2013) // 2.4 GHz Intel Core i7 // 8 GB 1600 MHz DDR3Exactly the same problem with me.
Some other threads advice to remove fonts, clean the caches, remove add ins but nothing works consistenty, for some it looks like it works, for me it failed.
What I did not try yet, was to move the Render files out of the malicious library to trash. -
Inner class vs. imported class
Hi everyone,
I have entitiy beans created for a client's web app I'd like to use in the
web service using WebLogic Workshop 7.0. Say the classes are imported like
this in the services:
import com.hoike.clientname.ap.bean.Invoice
import com.hoike.clientname.ap.bean.Vendor
Instances of these classes are used in callback methods and some of the
service methods.
When I generate the CTRL file, it actually adds those imported classes as
inner class of the service defined.
The problem is that when I try to used these services from another service,
I cannot use the imported classes (as Invoice or Vendor), but instead I have
to use the inner class (InvoiceService.Invoice or VendorService.Vendor)
Does WebLogic Workshop 7.0 only allow you to use inner classes? Is there a
way to use custom classes as method parameters?
Thanks in advance!
Makotohow do you declare your inner class?
Is it (public)
public static class MyInnerClassor (private)
private static class MyInnerClassor (package)
static class MyInnerClassor (protected)
protected static class MyInnerClassTry to change the way you declare the inner class. Use protected or package or public instead. -
Problem importing classes and beans
Hey there. Im having one major fustrating problem! When I code supporting classes and beans for my JSPs I get a code 500 internal server error when trying to import (via <%@ page import="class" %> and <jsp:useBean/>) Im storing my classes and beans in the WEB-INF folder and the calling JSPs are located in /ROOT/tests/8/jsp.jsp. Im using the following to import a class or bean:
<%@ import="aClass" %>
Seen as tho its in the WEB-INF folder I won't have to explicitly refer to where the class is located, just the class name.
I never had this problem when I was using my hosting service. Its only on my localhost server in which I get the Internal Server error.
Help appreciated, thx.
PS: Im quite new to JSP/Java Servlet.import (via <%@ page import="class" %> and
<jsp:useBean/>) Im storing my classes and beans in the
WEB-INF folder try put your class file in WEB-INF/classes.
or first put bean in the package, like WEB-INF/classes/packagename/beanclass
in jsp page:
<jsp:useBean id="Mybean" class="packagename.beanclass" scope="request" />
Question: is /ROOT a context entry in your server.xml?
Which JSP Container (version) you use? Maybe your localhost server's set up is different with your hosting. -
Hi, new to 3D, doubt in importing class
hi all,
i m new to JAVA 3D, i currrently hv a simple example source which i try to compile it, it just can't, saying that class not found, but i m sure i hv download and install the JAVA 3D for DirectX 1.3.1, also i hv the following code
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Label;
import java.awt.GraphicsConfiguration;
// below having importing class problem
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;can anyone guide me, thank youThat is the way I understand it. Here is the information from the documentation.
The version of the Export utility must be equal to the version of either the source or target database, whichever is earlier.
For example, to create an export file for an import into a later release database, use a version of the Export utility that equals the source database. Conversely, to create an export file for an import into an earlier release database, use a version of the Export utility that equals the version of the target database.
In general, you can use the Export utility from any Oracle8 release to export from an Oracle9i server and create an Oracle8 export file.
Then further down is this handy table:
Table 21-5 Using Different Releases of Export and Import
Export from Import to Use Export Release Use Import Release
10.1.0 9.0.2 9.0.2 9.0.2
So, that is the way I understand this. I have not done this, but this is how I undertand it to work.
Please correct me if I am wrong.
Thanks
Dean -
i am currently developing a flash movie with no graphics at
the moment. It is being done with a lot of classes and packages,
many of the AS classes import the same packages as well. I have
many linked movie clips to those classes.
The problem is that when i compile it takes quite a long
time. I want to know if there is a way to have a single file for
all my classes (like an include file) as opposed to having a dozen
import lines of code in each AS script.I'm a newbie too, but I thought I would give you this URL. It was extremely helpful when I began using packages. I hope it helps.
http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1/page9.jsp -
Hi,
I'm new to Eclipse and need help.
I have been given a folder with 5 classes and 1 class with a main method.
My first question is: Is there a way to import these classes into eclipse and run the main class with main method? I don't have any java files.
What I have to do is basically write a java source file for the main class, but without decompiling it.
My second question: Is there a way to import the 5 classes to my workspace so that I can use them when I recreate the java file for the main class?
I have tried searching everywhere, but could not find a solution that worked.
Thanksbizso wrote:
Hi,
I'm new to Eclipse and need help.
I have been given a folder with 5 classes and 1 class with a main method.
My first question is: Is there a way to import these classes into eclipse and run the main class with main method? I don't have any java files.
What I have to do is basically write a java source file for the main class, but without decompiling it.
My second question: Is there a way to import the 5 classes to my workspace so that I can use them when I recreate the java file for the main class?
I have tried searching everywhere, but could not find a solution that worked.
ThanksI don't believe you... look at the eclipse help... it's really rather good... you need to add the directory containing those five classes to the classpath... I don't know how to do that.
AND... This is a Java forum, not the Eclipse Help Desk... Go ask in an Eclipse forum... You're likely to get better answers, and if this forum ever started to act as an "all IDE's helpdesk" then we'd buried in irrelvant gumby posts within days... so we actively try to resist the temptation to help with IDE questions... comprende?
There's a place for this, and a place for that... programmers tend to be anal about stuff like this and that.
Cheers. Keith.
Maybe you are looking for
-
Is there a way to stop Firefox from suggesting to add new search engines to my search bar?
Is there a way to stop Firefox from suggesting to add new search engines to my search bar whenever I visit websites that suggest to us to add their search engines? I searched a lot and couldn't find any help. How to stop websites from suggesting to m
-
Who's going to jump first? Follow the links in this [thread|http://discussions.apple.com/thread.jspa?threadID=1829276&tstart=0] as it appears, at least at this point in time, that Software Update does not have this current version. As always, ask you
-
Problems installing LR4.1 RC2
I have tried several times to install LR4.1 rc2 and it fails because it cannot find the .msi file....never had this problem before and a search on the computer does not show it as well....I simply download for Windows and extract. thoughts?
-
Dummy category group for chart
Hi, I'm creating a stacked column chart where I'm getting data from an MDX query that has three measures. I want to have a separate stacked column for each of the measures but I can't figure out how to do this. If I were able to get the measures on s
-
Podcast page doesn't show all episodes???
Hi, I maintain a video-podcast for a Dutch bookshop. A while ago I updated the RSS-feed with new episodes. However, they won't show up in the list of my podcast: http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=130908598 When you subs