Disappearing Graphics in Jpanels!
Hi all,
I am new to java and have a slight problem. I have two forms, one is my main form and the other is used for a settings option for changing various aspects of my program such as colours etc.
On my main form I have 2 jPanels - one that shows my main image (it's a graph that I've created and used BufferImage to then draw it on the jPanel. The other shows a smaller version of this using similar method but scale the original image to make it smaller.
I have a function called drawStuff which draws all the main graphs, one called drawScales which draws all the axis labels and small graphs. I called upon these when I want them to be drawn. I don't use paint() or paintcomponent() etc.
My problem is that whenever I open my settings menu, the settings form appears over my jpanel, like it should, but all of a sudden all the images on both jpanels dissapear! so when I exit the settings menu both panels are empty! I want them to stay the way they are until I redraw them!
public void drawStuff()
Graphics2D l = (Graphics2D)g;
if (window==0){
if ((mpress=true)| (bpre==1)){
bpre=0;
h.setColor(Color.white);
h.fillRect(0,0,661,352);
h.setColor(Color.white);
h.fillRect(0,0,661,352);
h.setColor(Color.black);
h.drawLine(0,0,0,351); // draw graph axis
h.drawLine(0,351,661,351);
h.setColor(jPanel9.getBackground());
h.fillRect(1,0,660,351);
h.setColor(jPanel10.getBackground());
int temp=scalep;
while (1+scalep+swp<661){
h.fillRect((1+scalep),0,swp,351);
scalep=scalep+swp+swp;
if (1+scalep<661){
h.fillRect(scalep,0,660,351);
scalep=temp;
GetCols(5);
int psize=jSlider8.getValue();
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
zdata[o][1][zomlev+1]=0;
h.fillRect(660-test1[o][1],0+test1[o][2],psize,psize);
g.drawImage(Buffer,75,30,this);
xl=0;
xr=0;
yl=0;
yr=0;
if (mdrag==true){
g.drawImage(Buffer,75,30,this);
g.setColor(Color.black);
l.setColor (Color.black);
l.setStroke(dashed);
//bottom right
if ((selx1 < selx2) & (sely1 < sely2)){
//g.setColor(Color.black);
//g.drawRect(selx1, sely1, selx2-selx1, sely2-sely1);
g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
//l.draw(rectangle);
xl=selx1;
xr=selx2;
yl=sely1;
yr=sely2;
//bottom left
if ((selx1 > selx2) & (sely1 < sely2)){
g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
xl=selx2;
xr=selx1;
yl=sely1;
yr=sely2;
//top left
if ((selx1 > selx2) & (sely1 > sely2)){
g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
xl=selx2;
xr=selx1;
yl=sely2;
yr=sely1;
//top right
if ((selx1 < selx2) & (sely1 > sely2)){
g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
xl=selx1;
xr=selx2;
yl=sely2;
yr=sely1;
GetCols(4);
int psize=jSlider8.getValue();
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((735-test1[o][1]>xl) & (735-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
g.fillRect(735-test1[o][1],30+test1[o][2],psize,psize);
zdata[o][1][zomlev+1]=1;
sxl=xl;
sxr=xr;
syl=yl;
syr=yr;
l.setStroke(stroke);
/*if ((nbox==1) | (red==0)){
g.setColor(Color.white);
g.fillRect(3,16, 764, 401);
g.setColor(Color.black);
g.drawLine(75,380,725,380); // draw graph axis
g.drawLine(75,380,75,30);
//timescale();
//timetwofour();
g.drawString(twofours,50,400);
String minyS=String.valueOf(miny);
g.drawString(minyS,10,380);
g.drawString(twofoure,705,400);
String maxyS=String.valueOf(maxy);
g.drawString(maxyS,10,40);
g.drawString("Peak Energy",5,205);
g.drawString("Time of Signal",400,400);
if (nbox==1){
g.setColor(Color.white); // clear previous box
g.fillRect(xl, yl, xr-xl+1, yr-yl+1);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
nbox=0;
xl=0;
xr=0;
yl=0;
yr=0;
if (red==1){
g.setColor(Color.black);
g.drawLine(75,380,725,380); // draw graph axis
g.drawLine(75,380,75,30);
//bottom right
if ((selx1 < selx2) & (sely1 < sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-3) & (725-test1[o][1]<sxr+3) & (30+test1[o][2]>syl-3) & (30+test1[o][2]<syr+3)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
g.setColor(Color.white);
g.fillRect(selx1+1, sely1+1, selx2-selx1-1, sely2-sely1-1);
xl=selx1;
xr=selx2;
yl=sely1;
yr=sely2;
//bottom left
if ((selx1 > selx2) & (sely1 < sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (725-test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
g.setColor(Color.white);
g.fillRect(selx2+1, sely1+1, selx1-selx2-1, sely2-sely1-1);
xl=selx2;
xr=selx1;
yl=sely1;
yr=sely2;
//top left
if ((selx1 > selx2) & (sely1 > sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
g.setColor(Color.white);
g.fillRect(selx2+1, sely2+1, selx1-selx2-1, sely1-sely2-1);
xl=selx2;
xr=selx1;
yl=sely2;
yr=sely1;
//top right
if ((selx1 < selx2) & (sely1 > sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
g.setColor(Color.white);
g.fillRect(selx1+1, sely2+1, selx2-selx1-1, sely1-sely2-1);
xl=selx1;
xr=selx2;
yl=sely2;
yr=sely1;
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
g.setColor(Color.blue);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
sxl=xl;
sxr=xr;
syl=yl;
syr=yr;
if (window==0){
for (int o=1;o<nolin+1;o++){
if (red==0){
if (zdata[o][1][zomlev]==1){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
//if (red==0){
// if (data[o][1]==1){
// if (((540-test1[o][1])<selx2) && ((540-test1[o][1])>selx1) && ((380-test1[o][2])>sely1) && ((380-test1[o][2])<sely2)){
// g.setColor(new java.awt.Color(200, 200, 200));}
// g.fillOval(540-test1[o][1],380-test1[o][2],2,2);
/*if (window==1){
if ((nbox==1) | (red==0)){
g.setColor(Color.white);
g.fillRect(3,16, 764, 401);
g.setColor(Color.black);
g.drawLine(75,zeroy,725,zeroy); // y zero axis
g.drawLine(zerox,30,zerox,380); // x zero axis
String minxS="0";
g.drawString(minxS,zerox,400);
String minyS="0";
g.drawString(minyS,10,zeroy);
g.drawString("Log 10 R",10,205);
g.drawString("Difference in Time of Flight",400,400);
if (nbox==1){
g.setColor(Color.white); // clear previous box
g.fillRect(xl, yl, xr-xl+1, yr-yl+1);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
nbox=0;
xl=0;
xr=0;
yl=0;
yr=0;
if (red==1){
g.setColor(Color.black);
g.drawLine(75,zeroy,725,zeroy); // y zero axis
g.drawLine(zerox,30,zerox,380); // x zero axis
//bottom right
if ((selx1 < selx2) & (sely1 < sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-3) & (725-test1[o][1]<sxr+3) & (30+test1[o][2]>syl-3) & (30+test1[o][2]<syr+3)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
g.setColor(Color.white);
g.fillRect(selx1+1, sely1+1, selx2-selx1-1, sely2-sely1-1);
xl=selx1;
xr=selx2;
yl=sely1;
yr=sely2;
//bottom left
if ((selx1 > selx2) & (sely1 < sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (725-test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
g.setColor(Color.white);
g.fillRect(selx2+1, sely1+1, selx1-selx2-1, sely2-sely1-1);
xl=selx2;
xr=selx1;
yl=sely1;
yr=sely2;
//top left
if ((selx1 > selx2) & (sely1 > sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
g.setColor(Color.white);
g.fillRect(selx2+1, sely2+1, selx1-selx2-1, sely1-sely2-1);
xl=selx2;
xr=selx1;
yl=sely2;
yr=sely1;
//top right
if ((selx1 < selx2) & (sely1 > sely2)){
if (sxl>0){
g.setColor(Color.white);
g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
g.setColor(Color.lightGray);
g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
g.setColor(Color.black);
g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
g.setColor(Color.white);
g.fillRect(selx1+1, sely2+1, selx2-selx1-1, sely1-sely2-1);
xl=selx1;
xr=selx2;
yl=sely2;
yr=sely1;
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
g.setColor(Color.red);
g.fillOval(725-zerox+test1[o][1],30+zeroy-test1[o][2],2,2);
if ((725-test2[o][1]>xl) & (725-test2[o][1]<xr) & (30+test2[o][2]>yl) & (30+test2[o][2]<yr)){
g.setColor(Color.blue);
g.fillOval(725-zerox+test2[o][1],30+zeroy-test2[o][2],2,2);
if ((725-test3[o][1]>xl) & (725-test3[o][1]<xr) & (30+test3[o][2]>yl) & (30+test3[o][2]<yr)){
g.setColor(Color.green);
g.fillOval(725-zerox+test3[o][1],30+zeroy-test3[o][2],2,2);
sxl=xl;
sxr=xr;
syl=yl;
syr=yr;
if (window==1){
//plot points depending on choosen sets of data
if ((cho==1) | (cho==4) | (cho==5) | (cho==7)){
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
g.setColor(Color.red);
g.fillOval(zerox+test1[o][1],zeroy-test1[o][2],2,2);
if ((cho==2) | (cho==4) | (cho==6) | (cho==7)){
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
g.setColor(Color.blue);
g.fillOval(zerox+test2[o][1],zeroy-test2[o][2],2,2);
if ((cho==3) | (cho==5) | (cho==6) | (cho==7)){
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
g.setColor(Color.green);
g.fillOval(zerox+test3[o][1],zeroy-test3[o][2],2,2);
// ========= START HERE FOR SENSOR PAIRS ===============
if (window==1){
if ((mpress=true)| (bpre==1)){
bpre=0;
h.setColor(Color.white);
h.fillRect(0,0,661,352);
h.setColor(Color.black);
h.setColor(jPanel9.getBackground());
h.fillRect(0,0,661,352);
h.setColor(jPanel10.getBackground());
scale=0;
int factor=0;
if (jRadioButton13.isSelected()==true){
factor=5;
if (jRadioButton14.isSelected()==true){
factor=10;
if (jRadioButton15.isSelected()==true){
factor=30;
if (jRadioButton16.isSelected()==true){
factor=60;
sw=(int)(factor/divfx);
while (1+scale+sw<661){
h.fillRect((1+scale+zerox),0,sw,352);
scale=scale+sw+sw;
if (1+scale<661){
h.fillRect((1+scale+zerox),0,661,352);
scale=zerox;
while (scale-sw-sw>0){
h.fillRect((scale-sw-sw),0,sw,352);
scale=scale-sw-sw;
if (scale-sw>0){
h.fillRect(0,0,scale-sw,352);
//if (1+scale<661){
//h.fillRect(scale,0,660,351);
h.setColor(Color.black);
h.drawLine(0,zeroy,661,zeroy); // y zero axis
h.drawLine(zerox,0,zerox,381); // x zero axis
int psize=jSlider1.getValue();
if ((cho==1) | (cho==4) | (cho==5) | (cho==7)){
GetCols(6);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
zdata[o][1][zomlev+1]=0;
h.fillRect(zerox+test1[o][1],zeroy-test1[o][2],psize,psize);
if ((cho==2) | (cho==4) | (cho==6) | (cho==7)){
GetCols(7);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
zdata[o][1][zomlev+1]=0;
h.fillRect(zerox+test2[o][1],zeroy-test2[o][2],psize,psize);
if ((cho==3) | (cho==5) | (cho==6) | (cho==7)){
GetCols(8);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
zdata[o][1][zomlev+1]=0;
h.fillRect(zerox+test3[o][1],zeroy-test3[o][2],psize,psize);
xl=0;
xr=0;
yl=0;
yr=0;
g.drawImage(Buffer,75,30,this);
if (mdrag==true){
g.drawImage(Buffer,75,30,this);
g.setColor(Color.black);
l.setColor (Color.black);
l.setStroke(dashed);
//bottom right
if ((selx1 < selx2) & (sely1 < sely2)){
//g.setColor(Color.black);
//g.drawRect(selx1, sely1, selx2-selx1, sely2-sely1);
g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
//l.draw(rectangle);
xl=selx1;
xr=selx2;
yl=sely1;
yr=sely2;
//bottom left
if ((selx1 > selx2) & (sely1 < sely2)){
g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
xl=selx2;
xr=selx1;
yl=sely1;
yr=sely2;
//top left
if ((selx1 > selx2) & (sely1 > sely2)){
g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
xl=selx2;
xr=selx1;
yl=sely2;
yr=sely1;
//top right
if ((selx1 < selx2) & (sely1 > sely2)){
g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
xl=selx1;
xr=selx2;
yl=sely2;
yr=sely1;
int psize=jSlider1.getValue();
if ((cho==1) | (cho==4) | (cho==5) | (cho==7)){
GetCols(9);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((75+zerox+test1[o][1]>xl) & (75+zerox+test1[o][1]<xr) & (30+zeroy-test1[o][2]>yl) & (30+zeroy-test1[o][2]<yr)){
g.fillRect(75+zerox+test1[o][1],30+zeroy-test1[o][2],psize,psize);
zdata[o][1][zomlev+1]=1;
if ((cho==2) | (cho==4) | (cho==6) | (cho==7)){
GetCols(12);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((75+zerox+test2[o][1]>xl) & (75+zerox+test2[o][1]<xr) & (30+zeroy-test2[o][2]>yl) & (30+zeroy-test2[o][2]<yr)){
g.fillRect(75+zerox+test2[o][1],30+zeroy-test2[o][2],psize,psize);
zdata[o][1][zomlev+1]=1;
if ((cho==3) | (cho==5) | (cho==6) | (cho==7)){
GetCols(13);
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((75+zerox+test3[o][1]>xl) & (75+zerox+test3[o][1]<xr) & (30+zeroy-test3[o][2]>yl) & (30+zeroy-test3[o][2]<yr)){
g.fillRect(75+zerox+test3[o][1],30+zeroy-test3[o][2],psize,psize);
zdata[o][1][zomlev+1]=1;
sxl=xl;
sxr=xr;
syl=yl;
syr=yr;
l.setStroke(stroke);
// ========= START HERE FOR PHASE ===============
if (window==2){
if ((mpress=true)| (bpre==1)){
bpre=0;
h.setColor(Color.white);
h.fillRect(0,0,661,352);
h.setColor(jPanel9.getBackground());
h.fillRect(1,0,165,351);
h.fillRect(331,0,165,351);
h.setColor(jPanel10.getBackground());
h.fillRect(166,0,165,351);
h.fillRect(496,0,165,351);
h.setColor(Color.black);
h.drawLine(0,0,0,351); // draw graph axis
h.drawLine(0,351,661,351);
GetCols(11);
int psize=jSlider9.getValue();
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
zdata[o][1][zomlev+1]=0;
h.fillRect(660-test1[o][1],0+test1[o][2],psize,psize);
xl=0;
xr=0;
yl=0;
yr=0;
g.drawImage(Buffer,75,30,this);
if (mdrag==true){
g.drawImage(Buffer,75,30,this);
g.setColor(Color.black);
l.setColor (Color.black);
l.setStroke(dashed);
//bottom right
if ((selx1 < selx2) & (sely1 < sely2)){
//g.setColor(Color.black);
//g.drawRect(selx1, sely1, selx2-selx1, sely2-sely1);
g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
//l.draw(rectangle);
xl=selx1;
xr=selx2;
yl=sely1;
yr=sely2;
//bottom left
if ((selx1 > selx2) & (sely1 < sely2)){
g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
xl=selx2;
xr=selx1;
yl=sely1;
yr=sely2;
//top left
if ((selx1 > selx2) & (sely1 > sely2)){
g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
xl=selx2;
xr=selx1;
yl=sely2;
yr=sely1;
//top right
if ((selx1 < selx2) & (sely1 > sely2)){
g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
xl=selx1;
xr=selx2;
yl=sely2;
yr=sely1;
GetCols(10);
int psize=jSlider9.getValue();
for (int o=1;o<nolin+1;o++){
if (zdata[o][1][zomlev]==1){
if ((735-test1[o][1]>xl) & (735-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
g.fillRect(735-test1[o][1],30+test1[o][2],psize,psize);
zdata[o][1][zomlev+1]=1;
sxl=xl;
sxr=xr;
syl=yl;
syr=yr;
l.setStroke(stroke);
public void drawscales(){
Font font1 = new Font("TW Cen MT", Font.BOLD,12);
Font font2 = new Font("TW Cen MT",Font.PLAIN,10);
Font font3 = new Font("TW Cen MT",Font.BOLD,10);
g.setColor(Color.white);
g.fillRect(2,2, 764, 409);
g.setColor(Color.black);
if (window==0){
g.setFont(font2);
g.drawString(twofours,52,400);
String minyS=String.valueOf(miny);
g.drawString(minyS,50,383);
g.drawString(twofoure,712,400);
String maxyS=String.valueOf(may);
g.drawString(maxyS,50,33);
g.setFont(font1);
g.drawString("Energy againt Time Graph",330,20);
g.setFont(font3);
g.drawString("Peak Energy",10,205);
g.drawString("/ pJ",30,217);
g.drawString("Time of Signal",370,400);
/*h.setColor(Color.black);
h.drawLine(0,0,0,351); // draw graph axis
h.drawLine(0,351,661,351);
h.setColor(jPanel9.getBackground());
h.fillRect(1,0,660,351);
h.setColor(jPanel10.getBackground());
while (1+scale+sw<661){
h.fillRect((1+scale),0,sw,351);
scale=scale+sw+sw;
if (1+scale<661){
h.fillRect(scale,0,660,351);
for (int o=1;o<nolin+1;o++){
GetCols(5);
if (zdata[o][1][zomlev]==1){
int psize=jSlider8.getValue();
h.fillRect(660-test1[o][1],0+test1[o][2],psize,psize);
//g.drawImage(Buffer,75,30,this);
sma.drawImage(smallpow,1,1,jPanel2);
double ndf =((zmpmr-zmpml)/219);
double ndyf=((zmpmt-zmpmb)/116);
int wdp=(int)((dmax-dmix)/ndf);
int htp=(int)((may-miy)/ndyf);
int sx=(int)((dmix-zmpml)/ndf);
int sy=(int)((zmpmt-may)/ndyf);
sma.drawRect(1+sx,1+sy,wdp,htp);
if (window==1){
g.setColor(Color.black);
g.setFont(font2);
String minxS="0";
g.drawString(minxS,zerox+72,395);
String minyS="0";
g.drawString(minyS,65,zeroy+34);
g.setFont(font3);
g.drawString("Log 10 R /",9,200);
g.drawString("Ratio of",13,212);
g.drawString("Energy",13,224);
g.drawString("Difference in Time of Flight / Seconds",315,408);
g.setFont(font1);
g.drawString("Sensor Pairs Graph",350,20);
/* h.setColor(Color.white);
h.fillRect(0,0,661,352);
h.setColor(Color.black);
h.setColor(new java.awt.Color(240, 240, 255));
h.fillRect(0,0,661,352);
h.setColor(new java.awt.Color(220, 220, 255));
scale=0;
sw=(int)(10/divfx);
while (1+scale+sw<661){
h.fillRect((1+scale+zerox),0,sw,352);
Thanks,
I have tried it using
public void paintComponent(Graphics g){
drawStuff();
}in the main body of code and then call upon PaintComponent when I close the settings frame but it makes no difference, I still get the big white box as shown in Q3 - I've tried reading the problem solving section for swing graphics from sun but to no avail.
Any advice on where paintcomponent should be placed / called?
Any ideas would be great.
Thanks,
John
Similar Messages
-
Problem with Graphics and JPanel...
I would like to draw a rectangle on a JPanel. Here is my code:
JPanel panel = new JPanel();
Graphics g = panel.getGraphics();
g.drawRect(20,20,20,20);
When I run my program, I have a NullPointerException...
Do you any suggestions to fix the problem??
thanks
Peteimport java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class pete extends JFrame {
public pete() {
JPanel panel = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int midx = getSize().width / 2;
int midy = getSize().height / 2;
g2.draw(new Rectangle2D.Double(midx/2, midy/2, midx, midy));
getContentPane().add(panel, "Center");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,300);
setLocation(300,100);
setVisible(true);
public static void main(String[] args) {
new pete();
} -
CS5 Interactive PDF - disappearing graphics and buttons
I have been struggling with CS5 - just about every interactive aspect of it anyway. I have an ebook that I just brought into CS5 from CS4. Each chapter in the book has interactive features such as buttons, anchored graphics, embedded video, html links, etc. I had been struggling with creating the interactive PDF (the whole spread thing) but fixed that with a script found in this forum (Thank You). Even still, I am struggling with random graphics and buttons that disappear off the page during pdf creation. One graphic was moved (not by design) into the bleed space of the document. All of these weird interactive bugs are just about more than enough. It is not an option to create the buttons in Acrobat... there are just too many. Anyone else have similar problems or have a solution I could try. I am close to the point of having to return to CS4 (which would suck to have to redo the edits made again).
I am sure that is true and makes very good sense for many projects.
This project is an ever evolving project... a price list that has evolved even from CS. I am in the process of creating it all new again, fresh in CS5 as a side project. Unfortunately, deadlines always push us to make do with what we can and with what we have. I was hopeful that CS5 would take away some of the pains I had been dealing with in CS4, but truly I was just uncovering more crud than I was able to work around. There will be a time when CS5 is good enough... just not today. -
hi all,
below is my code,
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.Graphics.*;
public class Testing extends JFrame implements ActionListener
String x[] = { " ", "Material A", "Material B", "Material C"};
String y[] = { " ", "+5", "+4", "+3", "+2", "+1", " 0",
"-1", "-2", "-3", "-2", "-5" };
private JButton Plot, End;
private Container c;
private JPanel centerPanel, northPanel, southPanel;
private JComboBox designMaterialx, materialRatingy;
String desMaterial = "";
public Testing()
super( "Welcome" );
Container c = getContentPane();
centerPanel = new JPanel()
protected void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g.setColor(Color.blue);
g.drawRect(120, 120, 20, 200);
g.drawString ("Material", 30, 220);
g.drawString ("Ratings", 30, 240);
g.drawString ("+5", 102, 130);
g.drawString ("0", 107, 220);
g.drawString ("-5", 102, 315);
g.setColor(Color.red);
g.drawRect(120, 321, 20, 200);
g.drawString ("Design", 30, 410);
g.drawString ("Materials", 30, 430);
g2d.rotate(-Math.PI/2.0,250.0,250.0);
g.setColor(Color.black);
g.drawString(desMaterial, -15, 135);
centerPanel.setBackground(Color.white);
c.add( centerPanel, BorderLayout.CENTER);
setVisible(true);
northPanel = new JPanel();
northPanel.add(new Label( "Please choose accordingly:" ));
northPanel.setLayout (new FlowLayout(FlowLayout.CENTER, 20, 0));
designMaterialx = new JComboBox( x );
designMaterialx.setMaximumRowCount( 2 );
designMaterialx.setBorder(BorderFactory.createTitledBorder("Design Materials"));
northPanel.add( designMaterialx );
designMaterialx.setEditable(true);
materialRatingy = new JComboBox( y );
materialRatingy.setMaximumRowCount( 2 );
materialRatingy.setBorder(BorderFactory.createTitledBorder("Material Ratings"));
northPanel.add( materialRatingy );
c.add( northPanel, BorderLayout.NORTH );
setVisible( true );
southPanel = new JPanel();
Plot = new JButton( "Plot" );
End = new JButton( "End" );
southPanel.add( Plot );
southPanel.add( End );
c.add( southPanel, BorderLayout.SOUTH );
setVisible( true );
Plot.addActionListener(this);
End.addActionListener(this);
Plot.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
desMaterial = designMaterialx.getSelectedItem().toString();
centerPanel.repaint();
System.out.println(desMaterial);
pack();
public static void main( String args[] )
Testing app = new Testing();
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
public void actionPerformed(ActionEvent e)
if(e.getSource()==Plot)
System.out.println("Plot");
else if(e.getSource()==End)
System.exit(0);
at the moment when the plot jButton is pressed, the selected values of the design materials jComboBox will be painted on the centerPanel inside the red rectangle. upon subsequent selection of the design materials & pressing of the plot jbutton, i wish to add them next to the existing ones but i'm not sure how to do this. could anyone out there help me on this? any kind of help would be appreciated.
thanks in advance.
rolfHere's a bunch of ideasimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
public class Test3 extends JFrame {
MyGraph mg = new MyGraph();
JTextField nameField = new JTextField("Sample2");
JTextField valueField = new JTextField("100");
public Test3() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
mg.addData(new MyData("Sample",50));
content.add(mg, BorderLayout.CENTER);
JPanel dataPanel = new JPanel();
dataPanel.add(new JLabel("Name:"));
dataPanel.add(nameField);
dataPanel.add(new JLabel("Value:"));
dataPanel.add(valueField);
JButton jb = new JButton("Add");
dataPanel.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
mg.addData(new MyData(nameField.getText(),Integer.parseInt(valueField.getText())));
mg.repaint();
content.add(dataPanel, BorderLayout.NORTH);
setSize(300,300);
public static void main(String[] args) { new Test3().setVisible(true); }
class MyGraph extends JPanel {
ArrayList al = new ArrayList();
public void addData(MyData data) { al.add(data); }
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
super.paintComponent(g2d);
g2d.setColor(Color.red);
int height = getHeight(), width=getWidth();
for (int i=0; i<al.size(); i++) {
MyData md = (MyData)al.get(i);
g2d.drawRect(i*20,height-md.getNum(),17,md.getNum());
g2d.rotate(-Math.PI/2.0,width/2,height/2);
g2d.setColor(Color.blue);
for (int i=0; i<al.size(); i++) {
MyData md = (MyData)al.get(i);
g2d.drawString(md.getName(),30,i*20-15);
class MyData {
String name;
int num;
public MyData(String name, int num) {
this.name=name;
this.num=num;
public String getName() { return name; }
public int getNum() { return num; }
} -
Disappearing graphics in CMYK PDF output from Frame 12.0.3
(I thought we already had a thread about this, but I can't find it!) - but I've just run into the same problem with Frame 12 that I've read about other people having.
I have Frame 12, fully patched. With a book file selected (and all my chapter files open), I do File > Save as PDF,
choose the settings I want on "PDF Setup for Selected Files" dialog, and off I go.....
Those settings include the CMYK radio button.
I don't get any error messages, but loads of items are missing (blank) in the resulting PDF - mostly graphics, but also some coloured table border, text, all sorts of stuff really.
If I select the RGB radio button instead, everything is present (although I want a CMYK PDF!!)
What is going on? Is CMYK PDF generation just broken in Frame 12?
I seem to recall someone saying an imported .AI graphic was the culprit in their case, but my graphics are mostly all just PNG or PDF.> ... corporate branding asks for some text and table borders to be in a Pantone colour, and whilst Frame can pass Pantone colours unchanged into a PDF if you hide them inside an EPS graphic, it can't do it for text or coloured lines.
It's close to a lost cause no matter how you do it, due to FM having deminimus color management.
Pantone colors from Frame end up downstream as just uncalibrated CMYK values, unless the object's color definition is tagged with and accompanied by the "PANTONE 123x" whatever string into the .ps of .pdf workflow (and the target app or system officially supports Pantone, and many RIPs do).
Even so, for end user convenience printing on Windows, the PDF content is still going to pass through the Windows GDI, which, despite furious CMYK handwaving by Mr.Bill's Minions, is still an RGB engine. You say, but the color printers are using CMYK inks! Yep, you get yet another color space conversion if the print path isn't Ps or native PDF.
What we've done is to figure out what the our entity colors are in sRGB space, and do all colors in RGB. BabelColor is a useful app for this task, as are one or more freebie web pages that provide sRGB equivalents for Pantone colors (but usually omit the word "pantone" entirely on their site, lest a rainbow of lawyers descend).
We then tell the distill process to tag images for color management, using IEC 61966-2-1:1999. This actually results in RGB values in EPS files with embedded profiles matching RGB colors generated by Frame (for graphics objects).
Getting Frame TEXT color to match as well aggravates the problem. You can get Distiller (and perhaps PDF rendering settings generally) to "tag everything for color management", but this turns black text into composite black, exploding the file size and slowing printing (and in the specific case of sRGB, is black still really black?). If print is your only target, and you can manage the black issue, this might be a solution (or just use some other color space, like Adobe RGB). Another possibility, where color text is limited, is to import it as EPS text from Illustrator.
There might be aftermarket tools for what's really needed, which is "tag all color objects for color management".
This is an area where some tool other than FM is usually indicated. InDesign has color management. I've never been able to figure out if Frame's ostensible DTP competitor has CM. Frame will never get CM, we are told consistently. -
Blurry then disappearing graphics
Help. I'm trying to add logos to a web page.
Q1: Some of the jpegs look awful but the resolution in PSD
looks good. Any thoughts for improving? The optimized gifs looked
even worse.
Q2: So I gave up but now, the images don't show up on a test
page. I get the red 'x'. The logos are named correctly and in a
relative link "../xxx/xxx.jpg" so I'm not sure what's going on?On 13 Apr 2007 in macromedia.dreamweaver, rjez wrote:
> Help. I'm trying to add logos to a web page.
>
> Q1: Some of the jpegs look awful but the resolution in
PSD looks
> good. Any
> thoughts for improving? The optimized gifs looked even
worse.
>
> Q2: So I gave up but now, the images don't show up on a
test page.
> I get the
> red 'x'. The logos are named correctly and in a relative
link
> "../xxx/xxx.jpg" so I'm not sure what's going on?
Could you post a link to the page? Also, a look at the
original images
would help.
Joe Makowiec
http://makowiec.net/
Email:
http://makowiec.net/contact.php -
Use the JPanel's graphics to draw something
I get a Jpanel's Graphcis g and use g to paint something,
g.drawRect(......),
the rectangle show on the JPanel , but it was clear when I resize the JPanel
or switch between applications. I think I can override the paintComponent()
method to let the image keep on it. I want to know: Is there some component
I can get its' graphics like JPanel and whatever I painted on use it can not
be clear?
BTW, I want to try some small game programming, anyone know some BEAutiful
component package?the rectangle show on the JPanel , but it was clear when I resize the JPanelThe reason your painting clears when you resize your window (or min/maximize) is because you will need to
tell your program to repaint the scene after anything happens to the window. The best thing to do is create
a thread to constantly call your paint routines so that even when the painting clears, it is repainted
immediately.
Is there some component I can get its' graphics like JPanel and whatever I painted on use it can not
be clear?I'm afraid not, all components behave this way. You don't have to worry if you use a thread for painting
(a thread for painting is infact one of several standards for rendering). Here is some code:
public void startPainting(){
Thread paintTimer = new Thread(
new Runnable(){
public void run(){
try{
Thread.sleep(delay);
}catch(InterruptedException e) {break;}
repaint();
paintTimer.start();
}[\code] -
AS3, PrintJob, graphics/logo disappearing on multipage printout
I'm printing a multipage report from a single Movieclip (MC). The parent MC has a minimum of 6 dyanmically created pages.
What I do is loop thru a data array and create multiple pages from a template MC that I have in my library and that I access thru it's AS linkage. As I loop thru the data each page is added to the parent MC. They are stacked vertically. Each page is 720px high so page 1 starts at 0, page 2 starts at 720, etc.
Once the report is created I used Printjob to print the MC.
Here's the loop to print the report. I use a defined rectangle area to create each page from the report MC. As I loop thru the pages the Rectangle location is move accordingly.
function doPrintJob(tmpMC:MovieClip):void {
var yStart:Number = new Number(0);
var printerror:Boolean = false;
var my_pj:PrintJob = new PrintJob();
if ( my_pj.start() ) {
for ( var k:int = 0; k < pageCnt; k++ ) {
yStart = (k * 720);
try { my_pj.addPage(tmpMC, new Rectangle (0, yStart, 540, 720) ); } catch(e:Error) {
printerror = true;
trace("############### ERROR SPOOLING DOCUMENT...");
if (!printerror) { my_pj.send(); }
The print loop works ok but what is happening is that a logo graphic that is on the top right of the template MC gets dropped after the 1st page. I have a logo on page 1 but no logos on the rest of pages.
I've been tweaking the .y positioning of every page in the report and it seems to me that if a page is created but the .y location is off by a pixel or 2 that the graphic will not be cropped by a pixel or 2 but instead is dropped outright from the page.
This is really frustrating me because I've tweaked my code repeatedly to make sure every page is located correctly and that the printjob rectangle is located correctly but I still end up losing the logo.
Has anyone had a similar experience of graphics disappearing from a PrintJob movieclip?
Thanks in advance for your replies.
ZakI eventually found the solution. Making sure the movieclip with the print data was added to the stage fixed the disappearing graphics from the print Movieclip. Because I didn't use the movieclip for anything other than printing I didn't add it to the stage, it just resided in memory.
Before I called the print function that is in my 1st post I did this and moved the clip offstage:
this.addChild(pdf_mc);
pdf_mc.x = 2000;
pdf_mc.y = 0 -
Help with 2D Graphics - How do I send Variable data to paint method?
I am working on a program that figures mortgage payments and an amortization schedule when a user inputs the principle, APR, and term length in years. After it figures all of those, I want to be able to display a chart that shows the principle and interest amounts for each year. My problem is, how do I get my loan information into my paint method so that I can draw a chart using that data? Any help would be greatly appreciated. The graph class in the code below is called after pressing a "Display Graph" button from my GUI.
I'm pasting my code below. This does not include my main method or my GUI method. I can post those if necessary. Here is my code so far:
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.io.*;
import java.lang.Math;
public class Graph extends JFrame
public Graph(double dCurrentBalance, double dMonthlyPmt, double dRate, int iTime)
final double balance = dCurrentBalance;
JFrame graphFrame;
int iCounter = 0;
int iPmtNumber = 0;
double dCurrentInt = 0.0;
double dCurrentPrinciple = 0.0;
double dMPR = 0.0;
int yCoordInt = 0; //integer for Y coordinate for Interest
int yCoordPrinciple = 0; //integer for Y coordinate for Principle
iTime *= 12; //determine number of months for this loan
iCounter = iTime; //set loop counter to number of months for this loan
dMPR = dRate/12; //determine monthly periodic rate
graphFrame = new JFrame ("mCalc Graph");
graphFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
graphFrame.setSize(800,600);
graphFrame.setResizable(false);
// center graphFrame on the screen
Dimension ScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension FrameSize = graphFrame.getSize();
if (FrameSize.height > ScreenSize.height)
FrameSize.height = ScreenSize.height;
if (FrameSize.width > ScreenSize.width)
FrameSize.width = ScreenSize.width;
graphFrame.setLocation((ScreenSize.width - FrameSize.width) / 2,
(ScreenSize.height - FrameSize.height) / 2);
//Displays graphFrame
Graphic graphicPane = new Graphic();
graphFrame.add(graphicPane);
graphFrame.setVisible(true);
//This loops until all payments have been figured
for (; iCounter > 0; )
iPmtNumber++;
dCurrentInt = dCurrentBalance * dMPR;
dCurrentPrinciple = dMonthlyPmt - dCurrentInt;
dCurrentBalance = dCurrentBalance - dCurrentPrinciple;
if (iPmtNumber%12 == 0)
// System.out.println("dCurrentBalance = " + dCurrentBalance);
// System.out.println("Payment # = " + iPmtNumber);
// System.out.println("dCurrentInt = " + dCurrentInt);
// System.out.println("dCurrentPrinciple = " + dCurrentPrinciple);
iCounter = iCounter-1;
} //end for loop
} //end Graph constructor
/* This class needs to be personalized to include my own variable names,
* etc. I also need to find a way to bring in data from the Graph class.
class Graphic extends JPanel
public void paintComponent(Graphics comp)
int i; // Declare the variables used to generate the chart
float xLoc = 50; // Location of the X Axis along Y
float yLoc = 50; // Location of the Y Axis along X
Line2D.Float LnA; //
super.paintComponent(comp);
// Establish a tie between this subroutine and the Graphic
Graphics2D comp2D = (Graphics2D) comp;
// Cast the Graphics named comp to a Graphics2D as comp2D
comp2D.setColor(Color.white);
// Set the background color
comp2D.fillRect(0,0,800,600);
// Draw the X and Y axis
comp2D.setColor(Color.black); // Set the pen color to black
Line2D.Float YAxis = new Line2D.Float(50,50,50,getSize().height - 50); // Define the Y-Axis
Line2D.Float XAxis = new Line2D.Float(50F,getSize().height - 50F, getSize().width -50F, getSize().height -50F); //Define the X-Axis
comp2D.draw(YAxis); // Draw the Y-Axis
comp2D.draw(XAxis); // Draw the X-Axis
Font font = new Font("Dialog", Font.BOLD, 12); // Set the font for the Axis labels
comp2D.setFont(font);
float increment = 15;
// Draw the line
xLoc += increment;
comp2D.setColor(Color.red);
/* Need to find a way to bring in my own data to use for the
* yLoc variables.
for (i=1; i<=45; i++)
{ // Begin making the graph
if (i < 30)
yLoc += increment;
} else {
yLoc -= increment;
// Scale the location to the graph height
LnA = new Line2D.Float( xLoc, getSize().height - 50F , xLoc, yLoc); // Create the line
comp2D.draw(LnA); // Draw the line
xLoc += increment;
}//end for
}//end paintComponent
} //end class Graphic
} //end class Graph
Any help would be GREATLY appreciated! Thanks.
Message was edited by:
russedl
My email address iss [email protected] if you wish to reply privately. I can send my entire program code if that will help. Thanks!Hi Deca,
You can use the CmdExecuteSync method of the DIAdem.TOCommand interface to set the value of a text channel. For example passing the string "CHT(1,1) := 'test'" as a parameter to the CmdExecuteSync method will set the 1st row of the 1st channel to "test". Please refer to the DIAdem help for more documentation on the CHT function.
I hope this helps! Please post back if I wasn't clear enough in explaining how to do this or if you have any problems getting it to work.
Regards,
Sarah Miracle
National Instruments -
Audio and other Bugs in 2.0 - are they fixed in 3.0?
I just completed creating an e-learning course using
Captivate 2.0 that used quite a lot of graphics and video. The
numbers of bugs I experienced when publishing to Flash in 2.0 were
so substantial that the delivery date had to be delayed almost two
months, much to the unhappiness of the client. I'll list the most
frustrating problems and hopefully someone can tell me if these
issues were fixed in 3.0. It's difficult for me to justify an
upgrade if I'm going to run into the same horrible problems.
I will start out by stating that I keep my project files
under 20 slides and all the slides have audio. The slides are 800 x
500 and none of the animations/video I'm using are more than 20
secs long. I'm running Captivate 2.0 on a Dell laptop with an Intel
Core 2 Duo, running Windows XP (with all the updates) and with 1 GB
of RAM. I've upped my Virtual Memory to 5 GB. My machine meets all
the specifications listed for Captivate 2.0, but I suspect that one
really needs a much faster machine with a lot more memory to work
at anything other than a snail's pace. I also make sure that no
unused graphics or animations are left in a project's library and I
defrag my hard drive at least once a day (if I don't Captivate
crashes everytime I try and open or save a file).
Problems:
- It takes up to 15 minutes to open or close a file. It
doesn't matter how big the file is. And the more files I open and
close in Captivate in any session, the slower my machine gets and I
evenutally have to restart it. It also takes 10-15 minutes to save
some of my project files, whose sizes have ballooned for no reason
(see below). If Captivate crashes during the save or even right
after a file is saved, the file is corrupted and cannot be opened.
I've had to redo work two or three times because of this problem.
- A project file with 10 multiple choice quiz questions and
two other simple slides (and only one brief audio file) is over 1
GB in size. I can't have more than 10 quiz questions because the
file sizes get so large that the program crashes before I can save
the file. I also have a number of 3-slide projects with graphics,
no animations, and some audio that are over 1 GB in size. But then
I have 20-slide project files with a lot of video and graphics and
audio that never go above 200 MB. In fact, all my project file file
sizes seem enormous for no good reason. And it's not from orphan
files in the Library. It's going to take like 10 DVDs to turn over
all my project files (about 40 project files - all under 20 slides
each) to the client. It's ridiculous!
- If I import audio as a WAV file and then publish the
project to Flash, the audio either moves to different slides or one
audio file gets repeated in all the slides. The only way to fix
this is to convert all the .WAV files to .MP3 files (but at a very
low bit rate), delete all the old WAV files from the project, and
replace them with the MP3 files. Using a WAV file always leads to
major audio scrambling when I publish to Flash.
- If I use a .MP3 audio file with a higher bit rate, when I
publish to Flash, the audio is slowed down by about 50%.
- Graphics fail to show up in the .SWF file after a publish
to Flash. This is entirely random and different graphics are
affected each publish, so I never know what the published file will
look like.The only way to fix this is to go back to the Project
file, double click on the graphic and make a change to one of the
options, save the change, reopen the graphic and change the option
back to the one you started with. Then cross your fingers that
another graphic won't vanish during the Publish process.
- Objects that I have fading in and out on the timeline work
perfectly in the project file, but when they are published as Flash
output, the timings are all off by up to 15 seconds. This happens
on a couple of slides and I can find no explanation or way to fix
this. And it's completely random. One publish may have the timings
out of whack and the next one has the timings correct.
- Adding any animation to a project file causes all drop-down
menus to stop functioning. I see from other posts that I just need
to click on an object in the Library. Wish I had known about that
sooner. I ended up restarting Captivate a lot.
- After closing Captivate, it takes 15 minutes or more before
my machine works at anything like it's normal speed. If I try to
shut down my machine right after closing Captivate, I get an error
message telling me Captivate is still running. It appears that
Captivate does not release memory after it is closed. I have to
restart my machine everytime I close Captivate just so I can
continue working in other applications normally.
These are just the major problems which caused the most
headaches and delays. Most of it seems to be the VERY buggy publish
to Flash option and some problems with releasing memory.
I know a lot of other people have experienced these problems,
as I've read about them in other posts. Has Capitvate 3 fixed any
of these issues? There is no way I'd ever attempt another
e-learining project with Captivate 2. This one about killed me.
Thanks,
JimThanks to everyone who has responded and tried to help.
Unfortunately, none of suggestions have worked.
Here's the update:
- All my files are local, so the business about working on
network drives is not applicable.
- I tried the Save As option to try and decrease my huge file
sizes as suggested by a couple of people. I did a Save As to
another file name, then deleted the original file and did another
Save As from the renamed file back to the original file name. My
file sizes INCREASED each time I saved. I now have a 12 slide
projects file with multiple choice quiz questions, no video,
minimal graphics and audio that tops out over 1.1 GB.
- I can't copy slides from one file to a new file because the
file I want to copy slides from is so large that Captivate crashes
everytime I try to Import slides from another project.
- No one has mentioned anything about all the bizarre, random
things that happen to graphics and audio when you publish to Flash.
This is by far the most frustrating aspects of working with
Captivate 2.0 - there is no telling what will turn up in your .SWF
file and whether the audio will be on the correct slide. I've seen
several posts about the problems using WAV files for audio or about
MP3 files being slowed down in the SWF files but no one can say if
these problems have been fixed in 3.0. Likewise the disappearing
graphics and the inexplicable timeline delays when publishing from
my Project file to an SWF file. And now a new one has popped up: in
the SWF file, the screen size suddenly gets smaller on several
slides, then goes back to normal!
- It sounds like I need a lot more memory and faster machine
(despite Adobe stating that my machine should be adequate to use
Captivate) to deal with the slow performance, constant crashing,
and frequent corrupted files. But this can't possibly explain the
extreme file bloat and all the Publish errors when creating SWF
files.
At this point there's no way I can upgrade to 3.0 because of
all the problems with 2.0. I can't make a justification to my boss
to spend more money on a software program that (from his
perspective and mine) does not work as advertised and has impacted
this project so dramatically.
It sounds like I'm the only Captivate user who is
experiencing these difficulties, which is really perplexing and
bizarre. Perhaps Captivate and Dell laptops are not compatible? I
sure do wish that Captivate had a Mac version. At least there
wouldn't be the usual Windows software excuse of "it must be your
machine."
Sigh... I sure did want to like Captivate, but everytime I
open the program I get the hebbie jebbies, expecting some new
disaster to befall me.
Jim -
Adding a JButton when there's a paint method
I'm creating a game application, sort of like a maze, and I want to add buttons to the levelOne panel to be able to move around the maze. When I add the buttons to the panel they don't appear, I assume the paint method is the reason for this. here's my code, I have 3 files, ill post the user_interface, and the levels class, where the level is created and where i tried to add the button. I tried putting the buttons in a JOptionPane, but then my JMenu wouldn't work at the same time the OptionPane was opened. If anyone knows a way around this instead, please let me know. I also tried using a separate class with a paintComponent method in it, and then adding the button (saw on a forum, not sure if it was this one), but that didn't work either. Also, if there is a way just to simply have the user press the directional keys on the keyboard and have the program perform a certain function when certain keys are pressed, I'd like to know, as that would solve my whole problem. Thanks.
//Libraries
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.text.*;
public class User_Interface extends JFrame
static Levels l = new Levels ();
static Delay d = new Delay ();
private Container contentPane = getContentPane ();
private JPanel main, levelOne;
private String level;
private CardLayout cc = new CardLayout ();
private GridBagConstraints gbc = new GridBagConstraints ();
private JPanel c = new JPanel ();
private String label = "MainMenu";
public User_Interface ()
//Generates the User-Interface
super ("Trapped");
main = new JPanel ();
GridBagLayout gbl = new GridBagLayout ();
main.setLayout (gbl);
c.setLayout (cc);
// set_gbc (gbc, 2, 2, 5, 5, GridBagConstraints.NONE);
c.add (main, "Main Page");
contentPane.add (c, BorderLayout.CENTER);
cc.show (c, "Main Page");
levelOne = new JPanel ();
levelOne.setLayout (new GridBagLayout ());
levelOne.setBackground (Color.black);
c.add (levelOne, "LevelOne");
JMenuBar menu = new JMenuBar ();
JMenu file = new JMenu ("File");
JMenu help = new JMenu ("Help");
JMenuItem about = new JMenuItem ("About");
JMenuItem mainmenu = new JMenuItem ("Main Menu");
mainmenu.addActionListener (
new ActionListener ()
public void actionPerformed (ActionEvent event)
cc.show (c, "Main Page");
label = "MainMenu";
JMenuItem newGame = new JMenuItem ("New Game");
newGame.addActionListener (
new ActionListener ()
public void actionPerformed (ActionEvent event)
l.xCord = 2;
l.yCord = 2;
l.xLoc = 140;
l.yLoc = 140;
JPanel entrance = new JPanel ();
entrance.setLayout (new FlowLayout ());
c.add (entrance, "Entrance");
label = "Entrance";
level = "ONE";
cc.show (c, "Entrance");
JMenuItem loadgame = new JMenuItem ("Load Game");
JMenuItem savegame = new JMenuItem ("Save Game");
JMenuItem exit = new JMenuItem ("Exit");
exit.addActionListener (
new ActionListener ()
public void actionPerformed (ActionEvent event)
JFrame frame = new JFrame ();
frame.setLocation (10, 10);
JOptionPane.showMessageDialog (frame, "Come Back Soon!", "TRAPPED", JOptionPane.INFORMATION_MESSAGE);
System.exit (0);
file.add (about);
file.add (mainmenu);
file.add (newGame);
file.add (loadgame);
file.add (savegame);
file.add (exit);
menu.add (file);
menu.add (help);
setJMenuBar (menu);
//Sets the size of the container (columns by rows)
setSize (750, 550);
//Sets the location of the container
setLocation (10, 10);
//Sets the background colour to a dark blue colour
main.setBackground (Color.black);
//Makes the container visible
setVisible (true);
public void paint (Graphics g)
super.paint (g);
g.setColor (Color.white);
if (label == "MainMenu")
for (int x = 0 ; x <= 50 ; ++x)
g.setColor (Color.white);
g.setFont (new Font ("Arial", Font.BOLD, x));
g.drawString ("T R A P P E D", 100, 125);
d.delay (10);
if (x != 50)
g.setColor (Color.black);
g.drawString ("T R A P P E D", 100, 125);
if (label == "Entrance")
l.Entrance ("ONE", g);
label = "LevelOne";
if (label == "LevelOne")
l.LevelOne (g, levelOne, gbc);
label = "";
public static void main (String[] args)
// calls the program
User_Interface application = new User_Interface ();
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
} //End of Main Method
//Libraries
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
public class Levels extends Objects
private JFrame frame = new JFrame ();
//Sets location, size, and visiblity to the frame where the JOptionPane
//will be placed
frame.setLocation (600, 600);
frame.setSize (1, 1);
frame.setVisible (false);
public int xCord = 2;
public int yCord = 2;
public void LevelOne (Graphics g, JPanel one, GridBagConstraints gbc)
***Trying to add the button, doesn't appear. Tried adding to the container, and any JPanel i had created***
JButton button1 = new JButton ("TEST");
one.add (button1);
g.setColor (Color.white);
g.fillRect (500, 100, 200, 300);
g.setColor (Color.black);
g.drawRect (500, 100, 200, 300);
g.setFont (new Font ("Verdana", Font.BOLD, 25));
g.setColor (Color.black);
g.drawString ("LEVEL ONE", 525, 80);
//ROW ONE
counter = -80;
counter2 = 200;
for (int a = 1 ; a <= 7 ; ++a)
if (xCord < a && yCord == 0)
g.setColor (darkGray);
g.fillRect (xLoc + counter, yLoc - 80, 40, 40);
g.setColor (Color.black);
g.drawRect (xLoc + counter, yLoc - 80, 40, 40);
if (xCord > a - 1 && yCord == 0)
g.setColor (darkGray);
g.fillRect (xLoc + counter2, yLoc - 80, 40, 40);
g.setColor (Color.black);
g.drawRect (xLoc + counter2, yLoc - 80, 40, 40);
counter += 40;
counter2 += 40;
*****Theres 9 more rows, just edited out to save space****
int y = 100;
int x = 100;
for (int a = 0 ; a < 20 ; ++a)
g.setColor (Color.white);
g.fillRoundRect (x, y, 40, 40, 5, 5);
g.setColor (Color.black);
g.drawRoundRect (x, y, 40, 40, 5, 5);
y += 40;
if (a == 9)
x += 320;
y = 100;
x = 140;
y = 100;
for (int a = 0 ; a < 14 ; ++a)
g.setColor (Color.white);
g.fillRoundRect (x, y, 40, 40, 5, 5);
g.setColor (Color.black);
g.drawRoundRect (x, y, 40, 40, 5, 5);
x += 40;
if (a == 6)
x = 140;
y += 360;
g.setColor (Color.black);
g.drawRect (100, 100, 360, 400);
ImageIcon[] images = new ImageIcon [4];
images [0] = new ImageIcon ("arrow_left.gif");
images [1] = new ImageIcon ("arrow_up.gif");
images [2] = new ImageIcon ("arrow_down.gif");
images [3] = new ImageIcon ("arrow_right.gif");
int direction = -1;
*****This is where I tried to have the OptionPane show the directional buttons******
//frame.setVisible (true);
// direction = JOptionPane.showOptionDialog (frame, "Choose Your Path:", "Trapped", JOptionPane.YES_NO_CANCEL_OPTION,
// JOptionPane.QUESTION_MESSAGE,
// null,
// images,
// images [3]);
// if (direction == 0)
// if (xCord - 1 > 0)
// xCord -= 1;
// xLoc += 40;
// if (direction == 1)
// if (yCord - 1 > 0)
// yCord -= 1;
// yLoc += 40;
// if (direction == 2)
// if (yCord + 1 < 9)
// yCord += 1;
// yLoc -= 40;
// if (direction == 3)
// if (xCord + 1 < 13)
// xCord += 1;
// xLoc -= 40;
//LevelOne (g, one, gbc);
}i tried adding a keylistener, that didn't work too well, i had tried to add it to a button and a textarea which i added to the 'one' frame, it didn't show up, and it didn't work. How would i go about changing the paint method so that it doesn't contain any logic? That's the only way I could think of getting the program to move forward in the game. Thanks.
//Libraries
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.text.*;
public class User_Interface extends JFrame
static Levels l = new Levels ();
static Delay d = new Delay ();
private Container contentPane = getContentPane ();
private JPanel main, levelOne;
private String level;
private CardLayout cc = new CardLayout ();
private GridBagConstraints gbc = new GridBagConstraints ();
private JPanel c = new JPanel ();
private String label = "MainMenu";
public User_Interface ()
//Generates the User-Interface
super ("Trapped");
main = new JPanel ();
GridBagLayout gbl = new GridBagLayout ();
main.setLayout (gbl);
c.setLayout (cc);
// set_gbc (gbc, 2, 2, 5, 5, GridBagConstraints.NONE);
c.add (main, "Main Page");
contentPane.add (c, BorderLayout.CENTER);
cc.show (c, "Main Page");
levelOne = new JPanel ();
levelOne.setLayout (new GridBagLayout ());
levelOne.setBackground (Color.black);
c.add (levelOne, "LevelOne");
JMenuBar menu = new JMenuBar ();
JMenu file = new JMenu ("File");
JMenu help = new JMenu ("Help");
JMenuItem about = new JMenuItem ("About");
JMenuItem mainmenu = new JMenuItem ("Main Menu");
mainmenu.addActionListener (
new ActionListener ()
public void actionPerformed (ActionEvent event)
cc.show (c, "Main Page");
label = "MainMenu";
JMenuItem newGame = new JMenuItem ("New Game");
newGame.addActionListener (
new ActionListener ()
public void actionPerformed (ActionEvent event)
l.xCord = 2;
l.yCord = 2;
l.xLoc = 140;
l.yLoc = 140;
JPanel entrance = new JPanel ();
entrance.setLayout (new FlowLayout ());
c.add (entrance, "Entrance");
label = "Entrance";
level = "ONE";
cc.show (c, "Entrance");
JMenuItem loadgame = new JMenuItem ("Load Game");
JMenuItem savegame = new JMenuItem ("Save Game");
JMenuItem exit = new JMenuItem ("Exit");
exit.addActionListener (
new ActionListener ()
public void actionPerformed (ActionEvent event)
JFrame frame = new JFrame ();
frame.setLocation (10, 10);
JOptionPane.showMessageDialog (frame, "Come Back Soon!", "TRAPPED", JOptionPane.INFORMATION_MESSAGE);
System.exit (0);
file.add (about);
file.add (mainmenu);
file.add (newGame);
file.add (loadgame);
file.add (savegame);
file.add (exit);
menu.add (file);
menu.add (help);
setJMenuBar (menu);
//Sets the size of the container (columns by rows)
setSize (750, 550);
//Sets the location of the container
setLocation (10, 10);
//Sets the background colour to a dark blue colour
main.setBackground (Color.black);
//Makes the container visible
setVisible (true);
public void paint (Graphics g)
super.paint (g);
g.setColor (Color.white);
if (label == "MainMenu")
for (int x = 0 ; x <= 50 ; ++x)
g.setColor (Color.white);
g.setFont (new Font ("Arial", Font.BOLD, x));
g.drawString ("T R A P P E D", 100, 125);
d.delay (10);
if (x != 50)
g.setColor (Color.black);
g.drawString ("T R A P P E D", 100, 125);
if (label == "Entrance")
l.Entrance ("ONE", g);
label = "LevelOne";
if (label == "LevelOne")
l.LevelOne (g, levelOne, gbc);
label = "";
//g.setColor (new Color
public static void main (String[] args)
// calls the program
User_Interface application = new User_Interface ();
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
} //End of Main Method
//Libraries
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.ActionMap;
import javax.swing.plaf.*;
public class Levels extends Objects
implements KeyListener
//static final String newline = System.getProperty ("line.separator");
JButton button;
private JFrame frame = new JFrame ();
//Sets location, size, and visiblity to the frame where the JOptionPane
//will be placed
frame.setLocation (600, 600);
frame.setSize (1, 1);
frame.setVisible (false);
JButton button1;
public int xCord = 2;
public int yCord = 2;
public void LevelOne (Graphics g, JPanel one, GridBagConstraints gbc)
// button = new JButton ("TEST");
// ButtonHandler handler = new ButtonHandler ();
// button.addActionListener (handler);
// one.add (button);
g.setColor (Color.white);
g.fillRect (500, 100, 200, 300);
g.setColor (Color.black);
g.drawRect (500, 100, 200, 300);
g.setFont (new Font ("Verdana", Font.BOLD, 25));
g.setColor (Color.black);
g.drawString ("LEVEL ONE", 525, 80);
//ROW ONE
counter = -80;
counter2 = 200;
for (int a = 1 ; a <= 7 ; ++a)
if (xCord < a && yCord == 0)
g.setColor (darkGray);
g.fillRect (xLoc + counter, yLoc - 80, 40, 40);
g.setColor (Color.black);
g.drawRect (xLoc + counter, yLoc - 80, 40, 40);
if (xCord > a - 1 && yCord == 0)
g.setColor (darkGray);
g.fillRect (xLoc + counter2, yLoc - 80, 40, 40);
g.setColor (Color.black);
g.drawRect (xLoc + counter2, yLoc - 80, 40, 40);
counter += 40;
counter2 += 40;
int y = 100;
int x = 100;
for (int a = 0 ; a < 20 ; ++a)
g.setColor (Color.white);
g.fillRoundRect (x, y, 40, 40, 5, 5);
g.setColor (Color.black);
g.drawRoundRect (x, y, 40, 40, 5, 5);
y += 40;
if (a == 9)
x += 320;
y = 100;
x = 140;
y = 100;
for (int a = 0 ; a < 14 ; ++a)
g.setColor (Color.white);
g.fillRoundRect (x, y, 40, 40, 5, 5);
g.setColor (Color.black);
g.drawRoundRect (x, y, 40, 40, 5, 5);
x += 40;
if (a == 6)
x = 140;
y += 360;
g.setColor (Color.black);
g.drawRect (100, 100, 360, 400);
ImageIcon[] images = new ImageIcon [4];
images [0] = new ImageIcon ("arrow_left.gif");
images [1] = new ImageIcon ("arrow_up.gif");
images [2] = new ImageIcon ("arrow_down.gif");
images [3] = new ImageIcon ("arrow_right.gif");
int direction = -1;
//frame.setVisible (true);
// direction = JOptionPane.showOptionDialog (frame, "Choose Your //\Path:", "Trapped", JOptionPane.YES_NO_CANCEL_OPTION,
// JOptionPane.QUESTION_MESSAGE,
// null,
// images,
// images [3]);
// if (direction == 0)
// if (xCord - 1 > 0)
// xCord -= 1;
// xLoc += 40;
// if (direction == 1)
// if (yCord - 1 > 0)
// yCord -= 1;
// yLoc += 40;
// if (direction == 2)
// if (yCord + 1 < 9)
// yCord += 1;
// yLoc -= 40;
// if (direction == 3)
// if (xCord + 1 < 13)
// xCord += 1;
// xLoc -= 40;
one.addKeyListener (this);
// one.add (button1);
if (xCord == 1)
LevelOne (g, one, gbc);
/** Handle the key typed event from the text field. */
public void keyTyped (KeyEvent e)
/** Handle the key pressed event from the text field. */
public void keyPressed (KeyEvent e)
if (e.getSource () == "Up")
JOptionPane.showMessageDialog (null, "Hi", "Hi", 0, null);
/** Handle the key released event from the text field. */
public void keyReleased (KeyEvent e)
// displayInfo (e, "KEY RELEASED: ");
} -
Advanced Button with Movie Clip and Fading
Problem: I'm trying to create a bottun that when you roll
over it it plays a movie clip and also fades in and out on roll
out. It is similiar to the three main navigating buttons on the
following site.
http://www.fjcruiser.ca/
the buttons with the compasses that appear are the ones I am
talking about.
I already know how to make buttons, I just can't figure out
the actionscripting to load the movie and also fade in and fade out
according to roll over and roll out.
Please help. Thank everyone.Amazingly, I actually know exactly how to do this. And it
only requires about 4 lines of code in the _root layer and on the
button.
Instead of having the rollover load an external movie, you
want the have the rollover execute an on(enterFrame) function that
tells each newly entered frame of your movie to check to make sure
the mouse is still on the button, and if not, send the movie
playhead backwards.
So, put that sampleMovie right on the stage with the button.
Then write the code in the _root so that says: as long as the mouse
is over the button, the movie will advance to nextFrame(). When it
gets to the next frame, again the code checks to see if the mouse
is on the button, if so, the movie is instruct to go one more next
frame (which is tweening the fade, right?) again, over and over
until the stop() at the last frame. But, if while while entering a
frame, the code finds that the mouse is no longer over the button,
it does the same thing but this time instructs prevFrame(), and so
on, going prevFrame (backwards, in other words) as long as the
mouse is not on the button.
The result of the above is a gradual fade in and out,
depending on whether the mouse is hovering. This, as opposed to an
abrupt disappearing graphic on(rollOut).
Click the below link for the .fla that demonstrates this
technique (which, by the way, I learned from Joshua Davis'
excellent book, "flash to the core". Check it out at Amazon, or
wherever. Lots of cool tricks).
click here for
fade_Movie example -
Ok I am having major problems running this program.
I need the user to enter in the command line argument;
java ImageDiplay dog jpg 3meaning that the program will select dog1.jpg, dog2.jpg
and dog3.jpg put them in the images array and loop these pictures by showing each one at a time.
My problem is how do I assign each argument to the constructor to build the images name put them in the array. and then use the array to show the pics in an applet.
import java.awt.Toolkit;
import java.awt.Image;
import javax.swing.JFrame;
import java.awt.Graphics;
* This class loads a set of images and flips through them
public class ImageDisplay extends JFrame implements Runnable
protected Image[] images;
protected int current_image = 0;
* Read the basename and num_images parameters.
* Then read in the images, using the specified base name.
* For example, if basename is images/anim, read images/anim0,
* images/anim1, images/anim2, etc.
public ImageDisplay(String baseName, String fileType, int numPics)
super("ImageDisplay");
//add code here to load the pictures
//create a JFrame
//get basename
//get numPics
//add number to each imagename
Toolkit tKit = super.getToolkit();
= tKit.createImage(baseName);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300,300);
this.setVisible(true);
* This is the body of the thread, the method that does the animation.
public void run()
Thread workThread = null;
for (int i=0;i<images.length;++i)
// tracker.waitForID(i);
lastLoaded = i;
repaint();
while (workThread != null)
repaint();
try
Thread.sleep(100);
catch (InterruptedException e)
}//end of method
* This method paints the current image to the screen.
* This method is complete.
* @param g the graphics object that actually does the drawing
public void paint(Graphics g)
System.out.println("Painting");
g.clearRect(0, 0, 300, 300);
g.drawImage(images[current_image], 30, 30, this);
* The main method parses the command line arguments. Then
* it creates a new ImageDisplay object and passes it,
* as a target, to a thread.
public static void main (String[] args)
if (args.length == 3)
ImageDisplay myDisplay = new ImageDisplay(args[0],args[1], Integer.parseInt(args[2]) );
Runnable runner = new ImageDisplay(args[0],args[1],Integer.parseInt(args[2]) );
Thread t1 = new Thread(runner);
t1.start();
}here you go again
all questions answered together
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.image.*;
public class ShowPic extends JFrame implements Runnable{
Image[] images;
int current_image=0;
int maxNumber;
Toolkit tKit = Toolkit.getDefaultToolkit();
Thread th;
Graphics g;
JPanel panel;
public ShowPic(String image, String type, int num) {
panel=new JPanel();
panel.setSize(getWidth(),getHeight());
maxNumber=num;
images = new Image[maxNumber];
for (int i=0;i<maxNumber;i++) {
images=tKit.getImage(image+String.valueOf(i)+"."+type);
System.out.println(image+String.valueOf(i)+"."+type+" added");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setContentPane(panel);
this.setVisible(true);
th = new Thread (this);
th.start ();
public static void main(String[] args) {
try {
System.out.println(args[0]+" "+args[1]+" "+(Integer.parseInt(args[2])));
ShowPic showPic = new ShowPic(args[0],args[1], Integer.parseInt(args[2]));
} catch (NullPointerException e) {
System.out.println("Something is wrong!");
public void run() {
while (true) {
System.out.println("Thread is true - animate");
animate(g);
try {
Thread.sleep(100);
}catch (InterruptedException e) {
System.out.println(e);
}//end of method
public void animate(Graphics g){
if ( current_image == maxNumber-1){
current_image=0;
}else{
current_image++;
paint(g);
public void paint(Graphics g) {
if(g == null){
g=panel.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
g.drawString(""+current_image,10,10);
g.drawImage(images[current_image],10,10, this); -
Hello,
I wrote my own TableUI to draw a JPanel instead of some rows.
This works fine:
public void paintPanel(Graphics g, JPanel infoPanel, int rowIndex)
int yPos = 0;
for(int i = 0; i < rowIndex; i++) {
yPos += at.myTable.getJTable().getRowHeight(i);
// Fast paint: use the table's renderer pane...
rendererPane.paintComponent(g, infoPanel, null, 0, yPos, at.myTable.getJTable().getWidth(), at.infoHeight + 2);
g.translate(0, at.infoHeight);
The problem is that I have a JTextField inside my JPanel and it is not editable when I click on it. I'm not surprised as I only draw the JPanel.
Could someone tell me what I have to add to have the JPanel and its JTextField working properly.
Thanks in advance.
JoeOuch..... a panel as a cell in a table?
Anyway, you'll have to implement a cell editor for the panel because JTable has no idea what editor to use with it. If there are more than one data entry areas in your panel, I suggest you implment an editor that will trigger a JDialog with the entire panel added to its content pane.
;o)
V.V. -
hello guys
i have a main GUI frame and one button on that fires another frame with few graphs. i have an exit button the child one that needs to close that window and return to main one but that button is not working.
i have tried almost everything so far viz. dispose(), DISPOSE_ON_CLOSE, ChildFrame.this.dispose(), setVisible(false),,,,,, but nothing is working.
please please help .....
thanks a lotok.. its a bit longer to read but i m doin it
################ child class ###################
/* Split pane to view simulation results*/
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
public class GraphPane extends JFrame implements ActionListener {
private JPanel base,graphic;
private JButton first,second,third,fourth,fifth,viewer,quit;
private JTextField firstT,secondT,thirdT,fourthT,fifthT;
private JSplitPane hPane;
private TitledBorder title;
private JFileChooser fc;
//mode constants
private final String FIMB="fimB graphs";
private final String FIME="fimE graphs";
private final String FIMBOTH="Co-ordinated graphs";
//mode flag
private String modus=FIMBOTH;
// arrays to hold data of the simulation(s)
private int[] reader1=new int[75];
private int[] reader2=new int[75];
private int[] reader3=new int[75];
private int[] reader4=new int[75];
private int[] reader5=new int[75];
// arrays to supply data
private int[] supply1=new int[25];
private int[] supply2=new int[25];
private int[] supply3=new int[25];
private int[] supply4=new int[25];
private int[] supply5=new int[25];
// comboBox to choose viewing option
private JComboBox selector;
//change determiner
private boolean isChange;
//setting up gridbag layout
GridBagLayout gridbag;
GridBagConstraints c;
public Component createViewcom() {
//put a relevant image on buttons
ImageIcon opnerIcon = createImageIcon("images/opener.gif");
//create a file chooser
fc=new JFileChooser() ;
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setFileFilter(new NewFileFilter());
// create the mode chooser
selector=new JComboBox();
selector.addItem(FIMBOTH);
selector.addItem(FIMB);
selector.addItem(FIME);
selector.setFocusable(false);
//adding item listener
ModeListener modeListener=new ModeListener();
selector.addItemListener(modeListener);
selector.revalidate();
//selection buttons
first=new JButton("Simulation_1",opnerIcon);
first.setHorizontalTextPosition(AbstractButton.LEFT);
first.setForeground(Color.red);
first.setFocusable(false);
first.addActionListener(new ButtonAction1());
second=new JButton("Simulation_2",opnerIcon);
second.setHorizontalTextPosition(AbstractButton.LEFT);
second.setForeground(Color.blue);
second.setFocusable(false);
second.addActionListener(new ButtonAction2());
third=new JButton("Simulation_3",opnerIcon);
third.setHorizontalTextPosition(AbstractButton.LEFT);
third.setForeground(Color.green);
third.setFocusable(false);
third.addActionListener(new ButtonAction3());
fourth=new JButton("Simulation_4",opnerIcon);
fourth.setHorizontalTextPosition(AbstractButton.LEFT);
fourth.setForeground(Color.orange);
fourth.setFocusable(false);
fourth.addActionListener(new ButtonAction4());
fifth=new JButton("Simulation_5",opnerIcon);
fifth.setHorizontalTextPosition(AbstractButton.LEFT);
fifth.setForeground(Color.cyan);
fifth.setFocusable(false);
fifth.addActionListener(new ButtonAction5());
// textfields
firstT=new JTextField(14);
firstT.setEditable(false);
secondT=new JTextField(14);
secondT.setEditable(false);
thirdT=new JTextField(14);
thirdT.setEditable(false);
fourthT=new JTextField(14);
fourthT.setEditable(false);
fifthT=new JTextField(14);
fifthT.setEditable(false);
// viewer button
viewer=new JButton("View Result");
viewer.setFocusable(false);
viewer.addActionListener(this);
//quit button
quit=new JButton(" Exit ");
quit.setFocusable(false);
quit.addActionListener(new QuitButtonListener(this));
//add them to panel
base=new JPanel();
// layout manager
gridbag = new GridBagLayout();
c = new GridBagConstraints();
base.setLayout(gridbag);
base.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
// set constarins for the panel
//add combo box
c.gridx = 0;
c.gridy = 0;
c.gridheight = 1;
c.gridwidth = 2;
c.insets = new Insets(10,0,50,45);
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(selector, c);
base.add(selector);
// first set
c.gridx = 0;
c.gridy = 1;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(first, c);
base.add(first);
c.gridx = 1;
c.gridy = 1;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(firstT, c);
base.add(firstT);
//second set
c.gridx = 0;
c.gridy = 2;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(second, c);
base.add(second);
c.gridx = 1;
c.gridy = 2;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(secondT, c);
base.add(secondT);
// third set
c.gridx = 0;
c.gridy = 3;
c.gridheight = 1;
c.gridwidth = 1;
gridbag.setConstraints(third, c);
c.insets = new Insets(10,0,10,10);
base.add(third);
c.gridx = 1;
c.gridy = 3;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(thirdT, c);
base.add(thirdT);
//fourth set
c.gridx = 0;
c.gridy = 4;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fourth, c);
base.add(fourth);
c.gridx = 1;
c.gridy = 4;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fourthT, c);
base.add(fourthT);
//fifth set
c.gridx = 0;
c.gridy = 5;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fifth, c);
base.add(fifth);
c.gridx = 1;
c.gridy = 5;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(10,0,10,10);
gridbag.setConstraints(fifthT, c);
base.add(fifthT);
//the viewer button
c.gridx = 0;
c.gridy = 6;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(15,0,0,0);
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(viewer, c);
base.add(viewer);
//the quit button
c.gridx = 1;
c.gridy = 6;
c.gridheight = 1;
c.gridwidth = 1;
c.insets = new Insets(15,0,0,0);
c.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(quit, c);
base.add(quit);
base.setPreferredSize(new Dimension(320,440));
title=BorderFactory.createTitledBorder("Simulation Comparison");
base.setBorder(title);
base.setVisible(true);
base.setOpaque(true);
base.updateUI();
//split pane creation
hPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
boolean b = hPane.isContinuousLayout(); // false by default
hPane.setContinuousLayout(true);
b = hPane.isOneTouchExpandable(); // false by default
hPane.setOneTouchExpandable(true);
//hPane.resetToPreferredSizes();
hPane.setDividerLocation(365);
//allocate left component
hPane.setLeftComponent(base);
//allocate right component with a default graph panel
DefaultGraph prelude=new DefaultGraph();
graphic=new JPanel();
graphic.add(prelude);
graphic.setPreferredSize(new Dimension(590,440));
graphic.setVisible(true);
graphic.validate();
hPane.setRightComponent(graphic);
hPane.setPreferredSize(new Dimension(945,440));
hPane.setVisible(true);
return hPane;
// action performed for view Result button
public void actionPerformed (ActionEvent e) {
if(modus.equals(FIMBOTH))
System.out.println("3");
for(int i=50,j=0;i<75;i++,j++)
supply1[j]=reader1;
supply2[j]=reader2[i];
supply3[j]=reader3[i];
supply4[j]=reader4[i];
supply5[j]=reader5[i];
else if(modus.equals(FIME))
System.out.println("2");
for(int i=25,j=0;i<50;i++,j++)
supply1[j]=reader1[i];
supply2[j]=reader2[i];
supply3[j]=reader3[i];
supply4[j]=reader4[i];
supply5[j]=reader5[i];
else if (modus.equals(FIMB))
System.out.println("1");
for(int i=0;i<25;i++)
supply1[i]=reader1[i];
supply2[i]=reader2[i];
supply3[i]=reader3[i];
supply4[i]=reader4[i];
supply5[i]=reader5[i];
System.out.println("works fine!");
if(isChange)
viewer.setEnabled(false);
else
System.out.println("button enabled");
// add GraphReceptorData panel to the splitPane
GraphReceptorData graph = new GraphReceptorData(this);
graphic.removeAll();
graphic.add(graph);
//reset the divider location
hPane.setDividerLocation(365);
//repaint the pane after change
graphic.validate();
graphic.paintImmediately(graph.getX(),graph.getY(),570,400);
//add graph to the the split pane finally
hPane.setRightComponent(graphic);
// isChange boolean method
public boolean isChanged() {
if ((first.isSelected())||(second.isSelected())
||(third.isSelected())||(fourth.isSelected())||
(fifth.isSelected()))
isChange=true;
return isChange;
//Action listeners for buttons
class ButtonAction1 implements ActionListener {
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == first) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
firstT.setText(fc.getName(file));
RandomAccessFile simulation1=new RandomAccessFile(firstT.getText(),"r");
if ((firstT.getText().equals(fourthT.getText()))||(firstT.getText().equals(thirdT.getText()))||(firstT.getText().equals(secondT.getText()))||(firstT.getText().equals(fifthT.getText())))
firstT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation1.seek(i);
reader1[i/4]=simulation1.readInt();
} // end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction2 implements ActionListener {
// action performed for button2
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == second) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
secondT.setText(fc.getName(file));
RandomAccessFile simulation2=new RandomAccessFile(secondT.getText(),"r");
if ((secondT.getText().equals(firstT.getText()))||(secondT.getText().equals(thirdT.getText()))||(secondT.getText().equals(fourthT.getText()))||(secondT.getText().equals(fifthT.getText())))
secondT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation2.seek(i);
reader2[i/4]=simulation2.readInt();
} // end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction3 implements ActionListener {
//action performed for button3
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == third) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
thirdT.setText(fc.getName(file));
RandomAccessFile simulation3=new RandomAccessFile(thirdT.getText(),"r");
if ((thirdT.getText().equals(firstT.getText()))||(thirdT.getText().equals(secondT.getText()))||(thirdT.getText().equals(fourthT.getText()))||(thirdT.getText().equals(fifthT.getText())))
thirdT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation3.seek(i);
reader3[i/4]=simulation3.readInt();
} // end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction4 implements ActionListener {
//action performed for button4
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == fourth) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
fourthT.setText(fc.getName(file));
RandomAccessFile simulation4=new RandomAccessFile(fourthT.getText(),"r");
if ((fourthT.getText().equals(thirdT.getText()))||(fourthT.getText().equals(secondT.getText()))||(fourthT.getText().equals(firstT.getText()))||(fourthT.getText().equals(fifthT.getText())))
fourthT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation4.seek(i);
reader4[i/4]=simulation4.readInt();
} //end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
class ButtonAction5 implements ActionListener {
//action performed for button5
public void actionPerformed (ActionEvent e) {
//Handle open button action.
if (e.getSource() == fifth) {
int returnVal = fc.showDialog(GraphPane.this,"Attach");
if (returnVal == JFileChooser.APPROVE_OPTION) {
try
File file = fc.getSelectedFile();
//loading the file onto the application interface
fifthT.setText(fc.getName(file));
RandomAccessFile simulation5=new RandomAccessFile(fifthT.getText(),"r");
if ((fifthT.getText().equals(fourthT.getText()))||(fifthT.getText().equals(thirdT.getText()))||(fifthT.getText().equals(secondT.getText()))||(fifthT.getText().equals(firstT.getText())))
fifthT.setText("");
JOptionPane.showMessageDialog(null,"File selected has been already choosen","Selection Error",JOptionPane.ERROR_MESSAGE);
else {
for(int i=0;i<300;i+=4)
simulation5.seek(i);
reader5[i/4]=simulation5.readInt();
} //end try
catch (Exception locationError)
System.out.println("Not executed");
} else {
System.out.println("Invalid selection");
//selector listener
class ModeListener implements ItemListener {
// This method is called only if a new item has been selected.
public void itemStateChanged(ItemEvent evt) {
selector = (JComboBox)evt.getSource();
// Get the affected item
String s=(String)selector.getSelectedItem();
if (evt.getStateChange() == ItemEvent.SELECTED) {
// Item selected
modus=s;
System.out.println("cell selected is " + modus);
} else if (evt.getStateChange() == ItemEvent.DESELECTED) {
// Item is no longer selected
} // end of mode listener
// Returns an ImageIcon, or null if the path was invalid
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = GraphPane.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
//get methods to retrieve the values of supply arrays to feed into GraphReceptorData class
public int[] getSupplyOne() {
return supply1;
public int[] getSupplyTwo() {
return supply2;
public int[] getSupplyThree() {
return supply3;
public int[] getSupplyFour() {
return supply4;
public int[] getSupplyFive() {
return supply5;
// listener for the exit button
class QuitButtonListener implements ActionListener {
private Window myWindow;
public QuitButtonListener(Window w) {
myWindow = w; }
public void actionPerformed(ActionEvent evt) {
myWindow.setVisible(false);
myWindow.dispose();
######################## parent class#################
the button there is just calling this class.
// ActionListener for viewGraph button
class ButtonGraph implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFrame frame=new JFrame("Graph view screen");
frame.getContentPane().add(new GraphPane().createViewcom(), BorderLayout.CENTER);
frame.setSize(945, 440);
frame.setResizable(false);
frame.setVisible(true);
}hope this will explain more...
thanks a lot for help guys
Maybe you are looking for
-
I'm trying to understand these different workflows, how they work, plusses and minues of each, with a focus on how it relates to file size. Please help me fill in the gaps Here's what I think I know now. Optmize meda to ProRes 422 Better for perform
-
I cannot close down my primary email account as it's attached to my current modem. So it will have to remain open BUT I don't any emails going to this address. I have created a gmail account and want any emails redirected to this account but wanted t
-
Using Oracle Wallet for Java connection
Hi, Can anyone tell me how to acces the Oracle wallet from my Java application without using the thin or oci drivers?
-
Ssh login works but main login on remote machine does not
I have a PPC Mac mini with Tiger installed at a co-locate with a static ip. I also have remote desktop and I recently discovered that although I can successfully log into my remote machine on a terminal using ssh I can't log into the machine using RD
-
Running an executable file through servlet
Hello People, I tried searching about this on the Forums, but could not find the right solution. Please donot get annoyed if you find this to be a repeted topic, which I am sure is not. I want to run a .sh file in Unix environment through servlet. Ac