java - Why my list is not getting updated when I select a new file and scan it? -
i doing project need parse file , show required words , manipulation of output. here happens. when provide input file document folder below:
input [5:0] gre1; input wire clock, reset; input [3:0] req3, req2; input [3:0] req4, req5; input req1; input req0; output reg gnt3, gnt2, gnt1; output [7:0] req43, req53; output gnt0;
and click start scan, scans file , stores required words in array, when select "clock" in "specify clock" , "reset" in "specify reset signal", reading , click start button, output, when want repeat same procedure again clicking "go back" , take file has different input like:
input [5:0] gre2; input wire clk, rst; input [3:0] req31, req22; input [3:0] req42, req25; input req12; input req02; output reg gnt23, gnt22, gnt12; output [7:0] req423, req523; output gnt03;
then click "start scan", shows me correct output, when select "clk" in specify clock , "rst" in specify reset signal, still showing me previous list of signals/words want words/signals latest selected file.
my entire code given below:
/** * * @author mitesh khadgi */ public class main { private int maxfields = 52; // max number of fields allowed in dialog int count = 0; jcombobox relationcombo[] = new jcombobox[maxfields]; string signals[] = {"1", "2", "3", "4", "5"}; jpanel combopanel; jlabel opt; jlabel selsignal; jcombobox numofsignals; string[] numsignals = {"1", "2"}; jlabel handlelabel; jtextfield handle; jcombobox signal; jframe guiframe; private static final int pref_w = 450; private static final int pref_h = 450; //note: typically main method in //separate class. simple 1 class //example it's in 1 class. public static void main(string[] args) { new main(); } public main() { guiframe = new jframe(); //make sure program exits when frame closes guiframe.setdefaultcloseoperation(jframe.exit_on_close); guiframe.settitle("assertion-based gui"); guiframe.setsize(500,500); //this center jframe in middle of screen guiframe.setlocationrelativeto(null); // panel handle textfield option jpanel combopanelnew = new jpanel(); jtextfield handlenew = new jtextfield(30); combopanelnew.add(handlenew); // panel input file , select , scan options. jpanel showpanel = new jpanel(); jtextarea inoutlist = new jtextarea(5, 30); inoutlist.seteditable(false); inoutlist.setlinewrap(true); jscrollpane scrollingareanew = new jscrollpane(inoutlist); showpanel.add(scrollingareanew); // panel clock, reset combobox options jpanel showpanelnew = new jpanel(); opt = new jlabel("specify signal: "); signal = new jcombobox(signals); // adding panel clock, reset combobox options in showpanelnew. showpanelnew.add(opt); showpanelnew.add(signal); jbutton selectbutton = new jbutton( "select file"); jbutton scanbutton = new jbutton( "start scan"); selectbutton.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { jfilechooser filechooser = new jfilechooser(); int returnvalue = filechooser.showopendialog(null); if (returnvalue == jfilechooser.approve_option) { file selectedfile = filechooser.getselectedfile(); system.out.println(selectedfile.getname()); handlenew.settext(filechooser.getselectedfile().getabsolutepath()); } } }); scanbutton.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { list<string> listinputreal = new arraylist<string>(); // store file elements in array called listinputreal. system.out.println("listinputreal: " + arrays.tostring(listinputreal.toarray())); // clock signal combobox listener remove clock signal inputsignallist. signal.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { // list not getting updated, when click go , select signal. string[] inputsignallist = new string[] {}; for(int j = 0; j < listinputreal.size(); j++) { inputsignallist[j] = listinputreal.tostring(); } system.out.println(arrays.tostring(inputsignallist)); } }); string str = "qwerty1qwerty2"; str = str.replaceall("[^0-9]+", " "); inoutlist.settext("output"); } }); //the first jpanel contains jlabel , jcombobox combopanel = new jpanel(); selsignal = new jlabel("select number of signals: "); numofsignals = new jcombobox(numsignals); handlelabel = new jlabel("type handle name: "); handle = new jtextfield(20); //create second jpanel. add jlabel , jlist , //make use jpanel not visible. final jpanel listpanel = new jpanel(); listpanel.setvisible(false); jlabel listlbl = new jlabel("generated code:"); jtextarea vegs = new jtextarea(5, 30); vegs.seteditable(false); vegs.setlinewrap(true); listpanel.add(listlbl); jscrollpane scrollingarea = new jscrollpane(vegs); listpanel.add(scrollingarea, borderlayout.center); // adding new combopanelnew, select, scan, textarea , clock, reset comboboxes existing combopanel. combopanel.add(combopanelnew); combopanel.add(selectbutton); combopanel.add(scanbutton); combopanel.add(showpanel); combopanel.add(showpanelnew); // adding selsignal label, numofsignals combobox, handlelabel , handle textfield combopanel. combopanel.add(selsignal); combopanel.add(numofsignals); combopanel.add(handlelabel); combopanel.add(handle); // adding scrollpane combopanel or guiframe. jscrollpane scrollpane = new jscrollpane(combopanel); scrollpane.setpreferredsize(new dimension(pref_w, pref_h)); combopanel.setlayout(new boxlayout(combopanel, boxlayout.y_axis)); jbutton startbutton = new jbutton( "start"); //the actionlistener class used handle //event happens when user clicks button. //as there not lot needs happen can //define anonymous inner class make code simpler. startbutton.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { //when fruit of veg button pressed //the setvisible value of listpanel , //combopanel switched true //value or vice versa. count++; // when user clicks go button, refreshes new except fileread , clock, reset options. if(count %2 == 0) { startbutton.settext("start"); } else { startbutton.settext("go back"); } } }); //the jframe uses borderlayout layout manager. //put 2 jpanels , jbutton in different areas. guiframe.add(scrollpane, borderlayout.north); guiframe.add(listpanel, borderlayout.center); guiframe.add(startbutton,borderlayout.south); //make sure jframe visible guiframe.setvisible(true); } }
Comments
Post a Comment