java - GUI not showing up initially (netbeans) -


i'm new java , newer netbeans.. cannot figure out how fix issue..

when run project gui doesn't show up. there should menu bar drop down opening , saving file, , exiting program. there should 3 buttons towards bottom of window can used display data within file (images in case). instead, window blank when run program, nothing shows @ all.

when click on top left hand corner, 'file' resides on menu bar.. shows , top button shows @ point too. second 2 buttons should greyed out , become click-able after you've clicked first button , displayed first image.

i've tried searching solution, , fiddling netbeans settings can't seem solve this. i'm assuming it's stuff being incorrectly placed in foreground or background i'm unsure.

also, i've discovered if remove drawimage bit of code ((public void paint (graphics g) {g.drawimage(imagetopaint, 50, 70, this);}) gui shows i'm guessing conflicting something.. somewhere?!

thanks in advance if can shed light on this!

package final_project;  import java.awt.*; import java.awt.event.*; import java.awt.image.memoryimagesource; import java.util.*; import javax.swing.*; import javax.swing.filechooser.filefilter; import javax.swing.filechooser.filenameextensionfilter;   public abstract class analyst extends javax.swing.jframe    implements actionlistener {  double heights[][] = new double [300][300]; double grads[][] = new double [300][300]; double tempg[] = new double [8]; double wgrads[][] = new double [300][300];  image imagetopaint;  public boolean shouldcolourheights = false;  int blue = 1; int green = 1; int red = 1;  public analyst() {     initcomponents(); }  public double [][] convertfromstring(string[] starray){     double[][] data = new double [300][300];     int lines = starray.length;     (int = 0; i<lines; i++){         stringtokenizer st = new stringtokenizer(starray[i]," ");         int j=0;         while (st.hasmoretokens()){             data[i][j]=double.parsedouble(st.nexttoken());             j++;         }     }     return data; }   double[] get1darray (double[][] twodarray) {      double[] temparray = new double[twodarray.length * twodarray[0].length];      (int = 0; < twodarray.length; i++) {         (int j = 0; j < twodarray[i].length; j++) {             temparray[(i * twodarray[0].length) + j] = twodarray[i][j];         }     }     return temparray; }  public double getmaxgrad (int bound){     double maxgrad = 0.0;     (int k=0; k<bound; k++){         if (tempg[k]>maxgrad){             maxgrad=tempg[k];         }     }     return maxgrad; }   public image getimage (double [][] array) {     int arrayw = array[0].length;     int [] pixels = new int [array.length * arrayw];     double [] onedim = get1darray(array);     (int = 0; < pixels.length; i++) {         int value = (int) onedim[i];         if (value > 255){             value = 255;         }         if (shouldcolourheights){             int newi = (int) math.floor(i/300);             int newj = (int) i-(newi*300);             if (grads[newi][newj] < 1.0){                 blue=1; green=1; red=1;             } else if (grads[newi][newj] <=1.5) {                 blue=0; red=0; green=1;             } else if (grads[newi][newj] <=3.0) {                 blue=1; red=0; green=0;             } else {blue=0; red=1; green=0;}         }         color pixel;         pixel = new color(value * red, value * green, value * blue, 255);            pixels[i] = pixel.getrgb();            }     memoryimagesource memimage = new memoryimagesource(arrayw,arrayw,pixels,0,arrayw);     panel p = new panel();     image image = p.createimage(memimage);     return image; }  /**  * method called within constructor initialize form.  * warning: not modify code. content of method  * regenerated form editor.  */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code">                           private void initcomponents() {      fc = new javax.swing.jfilechooser();     btnheights = new javax.swing.jbutton();     btngradients = new javax.swing.jbutton();     btncolourh = new javax.swing.jbutton();     jmenubar = new javax.swing.jmenubar();     jmenu = new javax.swing.jmenu();     jmenuopen = new javax.swing.jmenuitem();     jmenusave = new javax.swing.jmenuitem();     jseparator = new javax.swing.jpopupmenu.separator();     jmenuexit = new javax.swing.jmenuitem();      setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);      btnheights.settext("heights");     btnheights.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             btnheightsactionperformed(evt);         }     });      btngradients.settext("gradients");     btngradients.setenabled(false);     btngradients.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             btngradientsactionperformed(evt);         }     });      btncolourh.settext("colour heights");     btncolourh.setenabled(false);     btncolourh.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             btncolourhactionperformed(evt);         }     });      jmenu.settext("file");      jmenuopen.setaccelerator(javax.swing.keystroke.getkeystroke(java.awt.event.keyevent.vk_o, java.awt.event.inputevent.ctrl_mask));     jmenuopen.settext("open");     jmenuopen.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             jmenuopenactionperformed(evt);         }     });     jmenu.add(jmenuopen);      jmenusave.setaccelerator(javax.swing.keystroke.getkeystroke(java.awt.event.keyevent.vk_s, java.awt.event.inputevent.ctrl_mask));     jmenusave.settext("save");     jmenusave.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             jmenusaveactionperformed(evt);         }     });     jmenu.add(jmenusave);     jmenu.add(jseparator);      jmenuexit.settext("exit");     jmenuexit.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             jmenuexitactionperformed(evt);         }     });     jmenu.add(jmenuexit);      jmenubar.add(jmenu);      setjmenubar(jmenubar);      javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane());     getcontentpane().setlayout(layout);     layout.sethorizontalgroup(         layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(layout.createsequentialgroup()             .addgap(39, 39, 39)             .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading, false)                 .addcomponent(btncolourh, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value)                 .addcomponent(btngradients, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value)                 .addcomponent(btnheights, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value))             .addcontainergap(258, short.max_value))     );     layout.setverticalgroup(         layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(javax.swing.grouplayout.alignment.trailing, layout.createsequentialgroup()             .addcontainergap(381, short.max_value)             .addcomponent(btnheights)             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)             .addcomponent(btngradients)             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)             .addcomponent(btncolourh)             .addgap(27, 27, 27))     );      pack(); }// </editor-fold>                          private void jmenuopenactionperformed(java.awt.event.actionevent evt) {                                               filefilter ft = new filenameextensionfilter("text files", "txt");     fc.addchoosablefilefilter(ft);     int returnval = fc.showopendialog(this);     if (returnval==javax.swing.jfilechooser.approve_option) {         java.io.file file = fc.getselectedfile();         string file_name = file.tostring();         try {             readfile file_read = new readfile(file_name);             string [] arraylines = file_read.openfile();             heights = convertfromstring(arraylines);             }         catch (java.io.ioexception e) {            joptionpane.showmessagedialog(analyst.this, "file not exist");             }     } }                                           private void jmenusaveactionperformed(java.awt.event.actionevent evt) {                                               string tempstr = "";     filefilter ft = new filenameextensionfilter("text files", "txt");     fc.addchoosablefilefilter(ft);     int returnval = fc.showsavedialog(this);     if (returnval==javax.swing.jfilechooser.approve_option) {         java.io.file saved_file = fc.getselectedfile();         string file_name = saved_file.tostring();         try {             writefile dataout = new writefile(file_name, true);             (int i=0; i<grads.length; i++) {                 (int j=0; j<grads[i].length; j++){                     double rgrad = math.floor(grads[i][j] * 10) / 10;                     tempstr = tempstr + string.valueof(rgrad) +" ";                 }                 dataout.writetofile(tempstr);                 tempstr = "";             }         }         catch (java.io.ioexception e) {            joptionpane.showmessagedialog(analyst.this, "file not written");             }     }     repaint(); }                                           private void jmenuexitactionperformed(java.awt.event.actionevent evt) {                                               system.exit(0); }                                            private void btnheightsactionperformed(java.awt.event.actionevent evt) {                                                shouldcolourheights=false;     red=1; blue=1; green=1;     imagetopaint = getimage(heights);     repaint();     btngradients.setenabled(true); }                                            private void btngradientsactionperformed(java.awt.event.actionevent evt) {                                                  double root2 = math.sqrt(2.0);     double scaling = 1.0;                  //cells of 1m assumed     double weighting = 40.0;               //to give more defined image     //the 8 neighbour cells     (int i=1; i<299; i++) {         (int j=1; j<299; j++){           tempg[0] = math.abs(heights[i-1][j-1]-heights[i][j])/root2;           tempg[1] = math.abs(heights[i-1][j+1]-heights[i][j])/root2;           tempg[2] = math.abs(heights[i+1][j-1]-heights[i][j])/root2;           tempg[3] = math.abs(heights[i+1][j+1]-heights[i][j])/root2;           tempg[4] = math.abs(heights[i][j-1]-heights[i][j]);           tempg[5] = math.abs(heights[i-1][j]-heights[i][j]);           tempg[6] = math.abs(heights[i][j+1]-heights[i][j]);           tempg[7] = math.abs(heights[i+1][j]-heights[i][j]);           grads[i][j] = getmaxgrad(8)/scaling;         }     }     //the 5 neighbour cells     int i=0;     (int j=1; j<299; j++) {          tempg[0] = math.abs(heights[i][j-1]-heights[i][j]);         tempg[1] = math.abs(heights[i+1][j-1]-heights[i][j])/root2;         tempg[2] = math.abs(heights[i+1][j]-heights[i][j]);         tempg[3] = math.abs(heights[i+1][j+1]-heights[i][j])/root2;         tempg[4] = math.abs(heights[i][j+1]-heights[i][j]);                            grads[i][j] = getmaxgrad(5)/scaling;          }      i=299;     (int j=1; j<299; j++){          tempg[0] = math.abs(heights[i][j-1]-heights[i][j]);         tempg[1] = math.abs(heights[i-1][j-1]-heights[i][j])/root2;         tempg[2] = math.abs(heights[i-1][j]-heights[i][j]);         tempg[3] = math.abs(heights[i-1][j+1]-heights[i][j])/root2;         tempg[4] = math.abs(heights[i][j+1]-heights[i][j]);         grads[i][j] = getmaxgrad(5)/scaling;     }     int j=0;     (i=1; i<299; i++){         tempg[0] = math.abs(heights[i-1][j]-heights[i][j]);         tempg[1] = math.abs(heights[i-1][j+1]-heights[i][j])/root2;         tempg[2] = math.abs(heights[i][j+1]-heights[i][j]);         tempg[3] = math.abs(heights[i+1][j+1]-heights[i][j])/root2;         tempg[4] = math.abs(heights[i+1][j]-heights[i][j]);         grads[i][j] = getmaxgrad(5)/scaling;     }        j=299;     (i=1; i<299; i++){         tempg[0] = math.abs(heights[i+1][j]-heights[i][j]);         tempg[1] = math.abs(heights[i+1][j-1]-heights[i][j])/root2;         tempg[2] = math.abs(heights[i][j-1]-heights[i][j]);         tempg[3] = math.abs(heights[i-1][j-1]-heights[i][j])/root2;         tempg[4] = math.abs(heights[i-1][j]-heights[i][j]);         grads[i][j] = getmaxgrad(5)/scaling;     }        //the 3 neighbour cells     i=0; j=0;     tempg[0] = math.abs(heights[i+1][j]-heights[i][j]);     tempg[1] = math.abs(heights[i+1][j+1]-heights[i][j])/root2;     tempg[2] = math.abs(heights[i][j+1]-heights[i][j]);      grads[i][j] = getmaxgrad(3)/scaling;      i=299; j=0;     tempg[0] = math.abs(heights[i-1][j]-heights[i][j]);     tempg[1] = math.abs(heights[i-1][j+1]-heights[i][j])/root2;     tempg[2] = math.abs(heights[i][j+1]-heights[i][j]);      grads[i][j] = getmaxgrad(3)/scaling;      i=0; j=299;     tempg[0] = math.abs(heights[i][j-1]-heights[i][j]);     tempg[1] = math.abs(heights[i+1][j-1]-heights[i][j])/root2;     tempg[2] = math.abs(heights[i+1][j]-heights[i][j]);      grads[i][j] = getmaxgrad(3)/scaling;      i=299; j=299;     tempg[0] = math.abs(heights[i][j-1]-heights[i][j]);     tempg[1] = math.abs(heights[i-1][j-1]-heights[i][j])/root2;     tempg[2] = math.abs(heights[i-1][j]-heights[i][j]);      grads[i][j] = getmaxgrad(3)/scaling;     //grads holds actual 'd8' gradients , written     //a file.  in order display greyscale image values need     //weighted (grads left unchanged).     //     (i=0; i<300; i++) {         (j=0; j<300; j++){             wgrads[i][j] = grads[i][j] * weighting;         }          }     shouldcolourheights=false;     red=1; blue=1; green=1;     imagetopaint = getimage(wgrads);      repaint();     jmenusave.setenabled(true);     btncolourh.setenabled(true); }                                              public void paint (graphics g) {         g.drawimage(imagetopaint, 50, 70, this); }   /**  * redraws height image colour represent gradients.  * @param evt   */ private void btncolourhactionperformed(java.awt.event.actionevent evt) {                                                shouldcolourheights=true;     imagetopaint = getimage(heights);     repaint(); }                                              /**  * @param args command line arguments  */  public static void main(string args[]) {     /* create , display form */     java.awt.eventqueue.invokelater(new runnable() {         public void run() {             new analyst() {                  public void actionperformed(actionevent e) {                     throw new unsupportedoperationexception("not supported yet.");                 }              } .setvisible(true);         }      }); }  // variables declaration - not modify                      private javax.swing.jbutton btncolourh; private javax.swing.jbutton btngradients; private javax.swing.jbutton btnheights; private javax.swing.jfilechooser fc; private javax.swing.jmenu jmenu; private javax.swing.jmenubar jmenubar; private javax.swing.jmenuitem jmenuexit; private javax.swing.jmenuitem jmenuopen; private javax.swing.jmenuitem jmenusave; private javax.swing.jpopupmenu.separator jseparator; // end of variables declaration                    } 

add super.paint(g).

@override public void paint(graphics g) {     super.paint(g);     g.drawimage(imagetopaint, 50, 70, this); } 

also can use system.arraycopy speed copying.

double[] get1darray(double[][] twodarray) {     double[] temparray = new double[twodarray.length * twodarray[0].length];     int jdim = twodarray[0].length;     (int = 0; < twodarray.length; i++) {         system.arraycopy(twodarray[i], 0, temparray, * jdim, jdim);     }     return temparray; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -