Is there is a way to display the data in specified format using RCAPI.
Pls find the code below.
ReportClientDocument boReportClientDocument = new ReportClientDocument();
boReportClientDocument.open("blankreport.rpt", 0);
public void displayReportData(ReportClientDocument document,ISection detailArea) {
int INSERT_AT_END = -1;
DBUtil dBUtil = new DBUtil();
Field field = null;
Fields fields = null;
FieldObject boFieldObject = null;
try {
document.getDatabaseController().addDataSource(dBUtil.getData());
// ISection detailArea = document.getReportDefController().getReportDefinition().getDetailArea().getSections().get(0);
Tables tables = document.getDatabaseController().getDatabase().getTables();
for (int i = 0; i < tables.size(); i++) {
fields = tables.getTable(i).getDataFields();
int leftInc = 0;
int topInc =0;
System.out.println("no of records iiii::::" + i);
for (int j = 0; j < fields.size(); j++) {
System.out.println("no of records jjjj::::" + j);
field = (Field) fields.get(j);
boFieldObject = new FieldObject();
boFieldObject.setDataSource(field.getFormulaForm());
boFieldObject.setFieldValueType(field.getType());
boFieldObject.setLeft(250 +leftInc);
boFieldObject.setTop(800);
boFieldObject.setWidth(3);
boFieldObject.setHeight(250);
// leftInc += 30;
//topInc += 50;
document.getReportDefController().getReportObjectController().add(boFieldObject,detailArea,-1);
}
}
} catch (ReportSDKException ex) {
Logger.getLogger(Report.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
System.out.println(ex);
}
}
Related
I have to merge a lot of pdf files, I get base64 coded from a SOAP Action, but the CSV files, from i, read the data for the Protokoll are sometimes not correct. It means, when the n^th data is not correct, it will nothing mergen. I need an option there, to ignore errors if it merges the files.
for(int i = 0; i<bm.size(); i++) {
String wert = leser.getBundlingWert(fileName, qeuecnt, bundling);
new Paket(fileName);
isNewPaket = true;
ut.addSource(Paket.outPutPdf);
if(leser.getPrintMode(fileName, i).equals("SIMPLEX")) {
for(int j = 0; j < bm.get(wert); j++) {
int pf = leser.getPageFrom(fileName, j);
int pt = leser.getPageTo(fileName, j);
seitecnt += (pt - pf) +1;
if(isNewPaket) {
seitecnt = 0;
isNewPaket = false;
}
else if(seitecnt>blattGrenze) {
new Paket(fileName);
ut.addSource(Paket.outPutPdf);
seitecnt = 0;
isNewPaket = false;
}
}
} else if(leser.getPrintMode(fileName, i).equals("DUPLEX")) {
for(int j = 0; j < bm.get(wert); j++) {
int pf = leser.getPageFrom(fileName, j);
int pt = leser.getPageTo(fileName, j);
seitecnt += ((pt - pf) +1)/2;
if(isNewPaket) {
seitecnt = 0;
isNewPaket = false;
}
else if(seitecnt>blattGrenze) {
new Paket(fileName);
ut.addSource(Paket.outPutPdf);
seitecnt = 0;
isNewPaket = false;
}
}
}
qeuecnt += bm.get(wert);
}
try {
ut.setDestinationFileName(path);
ut.mergeDocuments(null);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
If i let this code run and one of the files got data not correctly, it merges nothing, but i need an option, where it ignores the incorrect one.
Im having trouble with importing XLS data to jtable.
My program reads only the last row from XLS.
Here is my code:
JButton btnImportExcelFiles = new JButton("EXCEL FILES");
btnImportExcelFiles.setIcon(new ImageIcon(racunariAplikacija.class.getResource("/image/Excel-icon.png")));
btnImportExcelFiles.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
FileFilter filter = new FileNameExtensionFilter("Excel Files", "xls");
// here is my file chooser
JFileChooser jf = new JFileChooser();
jf.addChoosableFileFilter(filter);
int rezultat = jf.showOpenDialog(null);
if(rezultat == JFileChooser.APPROVE_OPTION)
{
String excelPath = jf.getSelectedFile().getAbsolutePath();
ArrayList<Stavka>lista = new ArrayList<>();
Stavka stavka = new Stavka();
File f = new File(excelPath);
Workbook wb = null;
try {
wb = Workbook.getWorkbook(f);
}
catch (BiffException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
// this is where i call for nested forloop
Sheet s = wb.getSheet(0);
int row = s.getRows();
int col = s.getColumns();
System.out.println("redovi" + row + "kolone" + col);
for (int i = 0; i < 18; i++) {
for (int j = 0; j < col; j++) {
Cell c = s.getCell(j,i);
if(j==0) {stavka.setStavkaID(Integer.parseInt(c.getContents().toString()));}
else if(j==1) {}
else if(j==2) {stavka.setSifraKomponente(c.getContents().toString());}
else if(j==3) {stavka.setOpis(c.getContents().toString());}
else if(j==4) {stavka.setVrednost(c.getContents().toString());}
else if(j==5) {stavka.setKuciste(c.getContents().toString());}
else if(j==6) {stavka.setSektor(c.getContents().toString());}
else if(j==7) {stavka.setRack(c.getContents().toString());}
else if(j==8) {stavka.setProizvodjac(c.getContents().toString());}
else if(j==9) {stavka.setKolicina(Integer.parseInt(c.getContents().toString()));}
//System.out.println(c.getContents());
}
// this is my tableModel
lista.add(stavka);
TabelaStavka stavka1 = new TabelaStavka(lista);
tblAzuriranjeMagacina.setModel(stavka1);
}
}
}
}
How can this be fixed?
I believe the error exists because you must create a new Stavka object for each line in your XLS, and then add it to 'lista'. Finally, I believe you also want to set the model (TabelaStavka) outside these for loops.
I don't have a full Java environment installed here, so forgive me if there is any syntax error below. The most important thing is that you understand what are the fixes you have to do in your code.
Also, never underestimate code formatting, you should consider using a better IDE, which helps out better formatting your source code.
JButton btnImportExcelFiles = new JButton("EXCEL FILES");
btnImportExcelFiles.setIcon(new ImageIcon(racunariAplikacija.class.getResource("/image/Excel-icon.png")));
btnImportExcelFiles.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
FileFilter filter = new FileNameExtensionFilter("Excel Files", "xls");
// here is my file chooser
JFileChooser jf = new JFileChooser();
jf.addChoosableFileFilter(filter);
int rezultat = jf.showOpenDialog(null);
if(rezultat == JFileChooser.APPROVE_OPTION)
{
String excelPath = jf.getSelectedFile().getAbsolutePath();
ArrayList<Stavka>lista = new ArrayList<>();
File f = new File(excelPath);
Workbook wb = null;
try
{
wb = Workbook.getWorkbook(f);
}
catch (BiffException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
// this is where i call for nested forloop
Sheet s = wb.getSheet(0);
int row = s.getRows();
int col = s.getColumns();
System.out.println("redovi" + row + "kolone" + col);
for (int i = 0; i < 18; i++)
{
Stavka stavka = new Stavka(); // new instance <<<<<<<<
for (int j = 0; j < col; j++)
{
Cell c = s.getCell(j,i);
if(j==0) {stavka.setStavkaID(Integer.parseInt(c.getContents().toString()));}
else if(j==1) {}
else if(j==2) {stavka.setSifraKomponente(c.getContents().toString());}
else if(j==3) {stavka.setOpis(c.getContents().toString());}
else if(j==4) {stavka.setVrednost(c.getContents().toString());}
else if(j==5) {stavka.setKuciste(c.getContents().toString());}
else if(j==6) {stavka.setSektor(c.getContents().toString());}
else if(j==7) {stavka.setRack(c.getContents().toString());}
else if(j==8) {stavka.setProizvodjac(c.getContents().toString());}
else if(j==9) {stavka.setKolicina(Integer.parseInt(c.getContents().toString()));}
}
lista.add(stavka); // inside second for loop <<<<<<<<
}
// outside the second for loop <<<<<<<<<<<<<<<<<<<<<<<<<<
// this is my tableModel
TabelaStavka stavka1 = new TabelaStavka(lista);
tblAzuriranjeMagacina.setModel(stavka1);
}
}
}
JButton calculateBtn = new JButton("Calculate");
calculateBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int iStart, fRate, gen;
try {
iStart = Integer.parseInt(startText.getText());
fRate = Integer.parseInt(fixedText.getText());
gen = Integer.parseInt(genText.getText());
if(FixedRad.isSelected()) {
for(int a = 0; a < gen; a++) {
iStart += iStart*fRate/100;
}
} else {
int vara, varb, varc, vard, vare, varf, varg, varh, vari, varj;
vara = Integer.parseInt(var1.getText());
varb = Integer.parseInt(var2.getText());
varc = Integer.parseInt(var3.getText());
vard = Integer.parseInt(var4.getText());
vare = Integer.parseInt(var5.getText());
varf = Integer.parseInt(var6.getText());
varg = Integer.parseInt(var7.getText());
varh = Integer.parseInt(var8.getText());
vari = Integer.parseInt(var9.getText());
varj = Integer.parseInt(var10.getText());
int[] iaGrowthRate = {vara, varb, varc, vard, vare, varf, varg, varh, vari, varj};
for( int a = 0; a < 10; a++) {
iStart += iStart*iaGrowthRate[a]/100;
}
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, "Plese enter a Valid Number");
}
}
});
The first button works perfectly (FixedRad) but when I try with the Variable Button selected it does not work and the message "Please enter a valid number appears"
Thanks!
I have a system so that you can press space to pause the simulation, and then arrows move the camera etc. and then if you press e, a JFrame pops up with a JTable inside it with the results from a SQL search of a connected database.
This works fine, I can close the JFrame and carry on running the simulation as usual, all the buttons and functions work.
The problem is after 20 seconds, the system takes the collected data and writes this data to the end of the database, which is fine, that works it writes to the end if the data is not already their. However if I press e to open the table, and then close the table, when returning to the simulation screen whatever button I press that has a listener attached to it, will just keep opening new tables, and I am stumped as to the reason why.
Any solution that would allow for when I close this JFrame for my key's to begin to function the way they did before writing to the file, would be greatly appreciated.
Here are the relevant pieces of code (let me know if there is any more you may need)
public void databaseConnector(boolean read){
try{
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/Outputs", "Sam", "sam");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT INDEX FROM SHM";
ResultSet rs = st.executeQuery(sql);
int len = 0;
while(rs.next()) {
len++;
}
if (read){
databaseReader(st, len);
} else {
double data[] = {modulus[0] , natural[0], modulus[1], natural[1], length, startPosition, endPosition, amplitude, equilibrium};
for (int i = 4; i < data.length; i++){
data[i] /= 100;
}
PreparedStatement sqls = con.prepareStatement( "SELECT * FROM SHM WHERE " + columnNames[1] + " = " + data[0] + " AND " + columnNames[2] + " = " + data[1] + " AND "
+ columnNames[3] + " = " + data[2] + " AND " + columnNames[4] + " = " + data[3] + " AND "
+ columnNames[5] + " = " + data[4] + " AND " + columnNames[6] + " = " + data[5]);
databaseWriter(st, len, sqls, data);
}
st.close();
con.close();
} catch (Exception e){
e.printStackTrace();
}
}
public void databaseReader(Statement st, int len){
try{
Object[][] data;
//Get data from table and convert to 2D array
data = new Object[len][columnNames.length];
String sql = "SELECT * FROM SHM";
ResultSet rs = st.executeQuery(sql);
int x = 0;
while (rs.next()){
for(int i = 0; i < columnNames.length; i++){
data[x][i] = new Double(rs.getDouble(columnNames[i]));
}
x++;
}
rs.close();
//Output data
JFrame frame = new JFrame("Table");
TableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable(model);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.add(new JScrollPane(table));
frame.setAlwaysOnTop(true);
frame.pack();
frame.setVisible(true);
} catch (Exception e){
System.err.println(e.getMessage());
}
}
public void databaseWriter(Statement st, int len, PreparedStatement sql, double[] data){
try{
//checker
ResultSet rs = sql.executeQuery();
if (!rs.next()){ //if not empty then
rs = st.executeQuery("SELECT * FROM SHM");
rs.moveToInsertRow();
rs.updateInt(columnNames[0],len + 1);
for (int i = 0; i < data.length; i++) {
rs.updateDouble(columnNames[i+1],data[i]);
}
rs.insertRow();
}
rs.close();
} catch (Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
public void gravity(){
if (moving){
double force = tension();
Player.ha = force / Player.mass;
Player.hSpeed += Player.ha * delta / 60;
//}
Player.vSpeed += Player.va;
Player.move(1, (int) (Player.hSpeed * delta));
if (milliSecondTimer < 20){
calculationChecker();
}
if (milliSecondTimer > 20 && !hasWritten){
endPosition = (int) (maxX - rect.get(0).getMaxX());
databaseConnector(false);
hasWritten = true;
}
} else {
milliSecondTimer = 0;
hasWritten = false;
amplitude = 0;
equilibrium = 0;
MaxX = new ArrayList<Integer>();
MinX = new ArrayList<Integer>();
Equilibrium = new ArrayList<Integer>();
Player.hSpeed = 0;
Player.ha = 0;
}
}
public class MyKeyListener implements KeyListener{
public void action(){
int s = 4;
if (keysDown.contains(KeyEvent.VK_SHIFT)){
s = 10;
} else {
s = 4;
}
if (keysDown.contains(KeyEvent.VK_UP) /*|| keysDown.contains(KeyEvent.VK_W)*/){
scaleChange = true;
moverY += 10;
}
if (keysDown.contains(KeyEvent.VK_RIGHT) /*|| keysDown.contains(KeyEvent.VK_D)*/){
if (!moving) {
Player.move(1,s);
right = true;
} else {
moverX -= 10;
}
}
if (keysDown.contains(KeyEvent.VK_DOWN) /*|| keysDown.contains(KeyEvent.VK_S)*/){
scaleChange = true;
moverY -= 10;
}
if (keysDown.contains(KeyEvent.VK_LEFT) /*|| keysDown.contains(KeyEvent.VK_A)*/){
if (!moving) {
Player.move(3,s);
right = false;
} else {
moverX += 10;
}
}
if (keysDown.contains(KeyEvent.VK_E)){
databaseConnector(true);
}
if (keysDown.contains(KeyEvent.VK_SPACE)){
Player.ha = 0;
Player.va = 0;
Player.vSpeed = 0;
Player.hSpeed = 0;
if (!moving){
modulus[0] = mod1.getValue();
modulus[1] = mod2.getValue();
natural[0] = len1.getValue();
natural[0] /= 10;
natural[1] = len2.getValue();
natural[1] /= 10;
setRectangles();
startPosition = (int) (Player.getCenterX() - rect.get(0).getMaxX());
}
moving = !moving;
}
if (keysDown.contains(KeyEvent.VK_EQUALS)){
scaleScreen += 1;
scaleChange = true;
}
if (keysDown.contains(KeyEvent.VK_SLASH)){
scaleScreen -= 1;
if(scaleScreen == 0){
scaleScreen = 1;
}
}
}
#Override
public void keyTyped(KeyEvent e) {
}
#Override
public void keyPressed(KeyEvent e) {
if (!keysDown.contains(e.getKeyCode())){
keysDown.add(e.getKeyCode());
}
action();
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
#Override
public void keyReleased(KeyEvent e) {
keysDown.remove(new Integer(e.getKeyCode()));
}
}
I have a problem with java program, in which i'm using sobel operator for edge detection, but when I'm trying to use that funcion, console says:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 262144
at sun.awt.image.ByteInterleavedRaster.getPixels(ByteInterleavedRaster.java:1015)
at Obrazek.jButtonSobelActionPerformed(Obrazek.java:566)
And the code for that is:
FileInputStream inFile = null;
try {
long beginTime = (new java.util.Date()).getTime();
int i, j;
double Gx[][], Gy[][], G[][];
inFile = new FileInputStream("D://lenacsmall.bmp");
BufferedImage bi = ImageIO.read(inFile);
int width = bi.getWidth();
int height = bi.getHeight();
int[] pixels = new int[width * height];
int[][] output = new int[width][height];
int[] raster = bi.getRaster().getPixels(0,0,width,height,pixels);
int counter = 0;
for(i = 0 ; i < width ; i++ )
{
for(j = 0 ; j < height ; j++ )
{
output[i][j] = pixels[counter];
counter = counter + 1;
}
}
Gx = new double[width][height];
Gy = new double[width][height];
G = new double[width][height];
for (i=0; i<width; i++) {
for (j=0; j<height; j++) {
if (i==0 || i==width-1 || j==0 || j==height-1)
Gx[i][j] = Gy[i][j] = G[i][j] = 0;
else{
Gx[i][j] = output[i+1][j-1] + 2*output[i+1][j] + output[i+1][j+1] -
output[i-1][j-1] - 2*output[i-1][j] - output[i-1][j+1];
Gy[i][j] = output[i-1][j+1] + 2*output[i][j+1] + output[i+1][j+1] -
output[i-1][j-1] - 2*output[i][j-1] - output[i+1][j-1];
G[i][j] = Math.abs(Gx[i][j]) + Math.abs(Gy[i][j]);
}
}
}
counter = 0;
for(int ii = 0 ; ii < width ; ii++ )
{
for(int jj = 0 ; jj < height ; jj++ )
{
pixels[counter] = (int) G[ii][jj];
counter = counter + 1;
}
}
BufferedImage outImg = new BufferedImage(width,height,BufferedImage.TYPE_BYTE_GRAY);
outImg.getRaster().setPixels(0,0,width,height,pixels);
FileOutputStream outFile = null;
try {
outFile = new FileOutputStream("D://copyTop.bmp");
} catch (FileNotFoundException ex) {
}
try {
ImageIO.write(outImg,"BMP",outFile);
} catch (IOException ex) {
}
JFrame TheFrame = new JFrame("obrazek " + width + " " + height);
JLabel TheLabel = new JLabel(new ImageIcon(outImg));
TheFrame.getContentPane().add(TheLabel);
TheFrame.setSize(600, 600);
TheFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
TheFrame.setVisible(true);
} catch (FileNotFoundException ex) {
Logger.getLogger(Obrazek.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Obrazek.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
inFile.close();
} catch (IOException ex) {
Logger.getLogger(Obrazek.class.getName()).log(Level.SEVERE, null, ex);
}
}
I'm really need some help. I hope someone will answer for that post, thank you.
Greetings :)
Try this, edge detection using sobel approach, I just did this yesterday.
`
static BufferedImage inputImg,outputImg;
static int[][] pixelMatrix=new int[3][3];
public static void main(String[] args) {
try {
inputImg=ImageIO.read(new File("your input image"));
outputImg=new BufferedImage(inputImg.getWidth(),inputImg.getHeight(),TYPE_INT_RGB);
for(int i=1;i<inputImg.getWidth()-1;i++){
for(int j=1;j<inputImg.getHeight()-1;j++){
pixelMatrix[0][0]=new Color(inputImg.getRGB(i-1,j-1)).getRed();
pixelMatrix[0][1]=new Color(inputImg.getRGB(i-1,j)).getRed();
pixelMatrix[0][2]=new Color(inputImg.getRGB(i-1,j+1)).getRed();
pixelMatrix[1][0]=new Color(inputImg.getRGB(i,j-1)).getRed();
pixelMatrix[1][2]=new Color(inputImg.getRGB(i,j+1)).getRed();
pixelMatrix[2][0]=new Color(inputImg.getRGB(i+1,j-1)).getRed();
pixelMatrix[2][1]=new Color(inputImg.getRGB(i+1,j)).getRed();
pixelMatrix[2][2]=new Color(inputImg.getRGB(i+1,j+1)).getRed();
int edge=(int) convolution(pixelMatrix);
outputImg.setRGB(i,j,(edge<<16 | edge<<8 | edge));
}
}
File outputfile = new File("your output image");
ImageIO.write(outputImg,"jpg", outputfile);
} catch (IOException ex) {System.err.println("Image width:height="+inputImg.getWidth()+":"+inputImg.getHeight());}
}
public static double convolution(int[][] pixelMatrix){
int gy=(pixelMatrix[0][0]*-1)+(pixelMatrix[0][1]*-2)+(pixelMatrix[0][2]*-1)+(pixelMatrix[2][0])+(pixelMatrix[2][1]*2)+(pixelMatrix[2][2]*1);
int gx=(pixelMatrix[0][0])+(pixelMatrix[0][2]*-1)+(pixelMatrix[1][0]*2)+(pixelMatrix[1][2]*-2)+(pixelMatrix[2][0])+(pixelMatrix[2][2]*-1);
return Math.sqrt(Math.pow(gy,2)+Math.pow(gx,2));
}
`
In your for loops when you check
if (i==0 || i==width-1 || j==0 || j==height-1)
you should probably be checking for i >= width-2 rather than i==width-1.
For example, if width is 10 it falls into the statement if i == 9.
you want to catch if i == 8 since you later check [i+1], which in your code would be out of the bounds of your image array, since the maximum you can have is 9 (width-1).
Obviously the same applies for j.