Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to reflect the changes made in an inner class in main

 
cindrella cradford
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I am trying to connect a C code to a java GUI through JNI.I am defining an array 'test'in the outermost class imagescan....now the array is initialized in the actionperformed of class OpenAction...i want this array in the main function so that this can be passed to the native C function i am trying to connect...but the problem is that the change made to the array are not reflected in the main function ...please help me..I am pasting the relevant portion of the code.....


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.io.*;
import java.util.*;
import java.awt.image.*;

public class imagescan extends JFrame
{ static int hHisto[] =new int[10];
static int lineHeight[] =new int[100];
private native int ImageScan(int test[] );
// Instance variables
JTextField m_fileNameTF = new JTextField(15);int ss[][]=new int[100][100];
JFileChooser m_fileChooser = new JFileChooser();int flag2=0;int t=0;int subcount[];
DrawingPanel imagepanel;
private JMenuItem menu;
Image img;int arr[];
int pixels[];
int pix[][];
static int test[]=new int[10];
int w,h;
int height,width,hcount,vcount,flag=3,click,clear;
JavaFilter fJavaFilter;
int mouseX,mouseY,mx,my,l_del;int flag3=0;
int varr[]=new int[1000];
int harr[]=new int[1000];
static int checkflag=0;
public static void main(String[] args)
{
imagescan window = new imagescan();

try
{for(int m=0;m<10;m++)
{System.out.println(test[m]);
System.out.println("yo yo");
}
}
catch(NullPointerException ne){}
/*try{ for(int kk=0;kk<10;kk++)
{

hHisto[kk]=kk;
System.out.println(hHisto[kk]);

}
}
catch(NullPointerException ne) {} */
if(checkflag==1)
{System.out.println("in main after openaction");
for(int kk=0;kk<10;kk++)
{
test[kk]=kk;
System.out.println(test[kk]);
}

//int count=window.ImageScan(hHisto);
// System.out.println(count);
}

window.setVisible(true);
}
static
{System.loadLibrary("ONLYIMGSCAN");
}

// constructor
imagescan()
{

// set the Text field to Read Only mode
m_fileNameTF.setEditable(false);

// Choose only files, not directories
m_fileChooser.setFileSelectionMode ( JFileChooser.FILES_ONLY);

// Set filter for Java source files.
fJavaFilter = new JavaFilter();
m_fileChooser.setFileFilter (fJavaFilter);

//... create Button and its listeners
JButton openButton = new JButton("Open");
JButton lineButton = new JButton("line segment");

JButton wordButton=new JButton("word segment");
JButton clearButton=new JButton("clear");
//setting tool tips for various buttons
openButton.setToolTipText("click here to choose a file");
lineButton.setToolTipText("click here for line segmentation");
wordButton.setToolTipText("click here for word segmentation");
clearButton.setToolTipText("click here to clear the panel");
//adding mouse listener to various buttons
openButton.addActionListener(new OpenAction());
lineButton.addActionListener(new LineAction());
wordButton.addActionListener(new wordAction());
clearButton.addActionListener(new clearAction());
//... Create contant pane, layout components
JPanel content = new JPanel();
JMenuBar bar=new JMenuBar();
setJMenuBar(bar);
JMenu helpmenu=new JMenu("Help ...Alt+H");
helpmenu.setMnemonic('H');
JMenuItem aboutopen=new JMenuItem("About open. A.");
JMenuItem lineseg=new JMenuItem("Line segmentation L");

aboutopen.setMnemonic('A');
lineseg.setMnemonic('L');
aboutopen.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e )
{JOptionPane.showMessageDialog(null,"To load an image,click open");
}
}
);
lineseg.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e )
{JOptionPane.showMessageDialog(null,"To perform line segmentation:\nclick Line segment\nYou may draw lines by clicking\n You may delete lines by clicking on a particular line\n you may also drag lines");
}
}
);







helpmenu.add(aboutopen);
helpmenu.add(lineseg);


content.setLayout(new BorderLayout());
JPanel buttonpanel=new JPanel();
buttonpanel.add(openButton);

buttonpanel.add(m_fileNameTF);
buttonpanel.add(lineButton);

buttonpanel.add(wordButton);
buttonpanel.add(clearButton);
content.add(helpmenu,"North");
content.add(buttonpanel,"South");
bar.add(helpmenu);

// Create JPanel canvas to hold the picture
imagepanel = new DrawingPanel();
//imagepanel.addMouseListener(new MouseClickListener());


// Create JScrollPane to hold the canvas containing the picture
JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroller.setPreferredSize(new Dimension(500,300));
scroller.setViewportView(imagepanel);
scroller.setViewportBorder(
BorderFactory.createLineBorder(Color.black));
// Add scroller pane to Panel
content.add(scroller,"Center");

//Set window characteristics
this.setTitle("File Browse and View");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(content);
this.pack();
}


class OpenAction implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{checkflag=1;
//... Open a file dialog.
clear=0;
int retval = m_fileChooser.showOpenDialog(imagescan.this);
if (retval == JFileChooser.APPROVE_OPTION)
{
//... The user selected a file, process it.
File file = m_fileChooser.getSelectedFile();
// store the file path in a string and send to JNI
String fPath = file.getPath();
System.out.println("The Path is:\n" + fPath);
//... Update user interface.
img = Toolkit.getDefaultToolkit().getImage(file.getPath());

m_fileNameTF.setText(file.getName());
imagepanel.repaint();
}

System.out.println("making test array");
for(int kk=0;kk<10;kk++)
{
test[kk]=kk;
System.out.println(test[kk]);
}


}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic