Internal Frames look?

A

Alan

Hi everybody

when i compile and run code below, I get my internal frames to
display the screen portion, but the internal frames DON'T show the
title, closable, minimize, itd..it doesnt look like an internal
frames...

i tried calling super("title", true, true, true, true);
in the sourceWarp constructor but it doesnt change anything...does
anyone have indea what can i do...extremelly thankful

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

public class Warp extends JFrame
{
private JDesktopPane desktop;
private JPanel options;
private JButton animate, curveButton;
private JLabel label,nfps, curve, space;
private JSlider slider;
sourceWarp src;
//targetWarp trg;
Graphics g;



public Warp()
{
super("Warp");
initGUI();


}//end constructor

public static void main(String args[])
{
Warp pgm = new Warp();
pgm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end main

private void initGUI()
{
desktop = new JDesktopPane();
getContentPane().add(desktop);

src = new sourceWarp();
src.setClosable(true);
src.setTitle("there");

//trg = new targetWarp();



JInternalFrame option = new JInternalFrame
("Options", false, false, false, false);
Container container = src.getContentPane();
container = trg.getContentPane();
container = option.getContentPane();



option.setSize(800,50);

// trg.setBounds(395,0,400,400);
option.setBounds(0,400,800, 100);

desktop.add(src);
src.setVisible(true);

//desktop.add(trg);
//trg.setVisible(true);
//trg.setClosable(true);

desktop.add(option);

// source.setVisible(true);
option.setVisible(true);

options = new JPanel();
animate = new JButton("Animate");
label = new JLabel("Use slider to change the duration of
animation");
slider = new JSlider(SwingConstants.HORIZONTAL, 10, 99, 30);
curve = new JLabel("Use parametric curve to control the speed of
animation ");
curveButton = new JButton("Parametric curve");
space = new JLabel("
");
animate.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event)
{
JInternalFrame animation = new JInternalFrame
("Animation", true, true, true, true);
animation.setSize(400,400);
animation.setBounds(200,0,400,400);
desktop.add(animation);
animation.setVisible(true);
}
});

curveButton.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event)
{
JInternalFrame par_curve = new JInternalFrame
("Parametric Curve", true, true, true, true);
par_curve.setSize(400,400);
par_curve.setBounds(200,0,400,400);
desktop.add(par_curve);
par_curve.setVisible(true);
}
});

slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);
nfps = new JLabel(" 30 frames per second.");

slider.addChangeListener(
new ChangeListener(){
public void stateChanged(ChangeEvent e)
{
nfps.setText(slider.getValue()+" frames per second.");
}
});

options.add(label);
options.add(slider);
options.add(nfps);
options.add(animate);
options.add(curve);
options.add(curveButton);
options.add(space);

container.add(options, BorderLayout.CENTER);
setSize(800,530);
setVisible(true);

}

public void Paint(Graphics g)
{
g.setColor(Color.blue);
g.fillRect(10,10,5,5);
}
} // end Warp class


source Warp code

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;



class sourceWarp extends JInternalFrame {

final int HW = 300;
final int sx=50, sy=50;
final int NUM_PTS = 5;
private int dist = (HW-2*sy)/(NUM_PTS+1);
int ptsOnFrameX[][] = new int [NUM_PTS+2][NUM_PTS+2];
int ptsOnFrameY[][] = new int [NUM_PTS+2][NUM_PTS+2];
private int distX=dist, distY=dist, dx=0, dy=0; // dist btwn points
int xVal, yVal;
boolean zone=false, makeRect=false;
int selPtArrXPos = 0, selPtArrYPos = 0;
int rectBoundX=0, rectBoundY=0;

sourceWarp()
{

setVisible(true);
setSize(HW, HW);

setStartPoints();

addMouseMotionListener(
new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent event)
{
xVal = event.getX();
yVal = event.getY();


if(zone==true) // ensures that control pt is selected
{
if( !(selPtArrXPos == 0) && !(selPtArrYPos ==0))
if( !( selPtArrXPos == (NUM_PTS+1)) && !(selPtArrYPos
==(NUM_PTS+1)))


System.out.println(selPtArrXPos+" "+selPtArrYPos);

if(isInsideBounds(selPtArrYPos, selPtArrXPos, xVal,
yVal))
{

setNewControl(xVal, yVal); // passes new coord. to
selected control pt

}
}
repaint();
}
} );

addMouseListener(
new MouseAdapter()
{
public void mousePressed(MouseEvent event)
{
xVal=event.getX();
yVal=event.getY();

if(isControlPoint(xVal, yVal)) // have to select a control pt
{
zone=true;

if( !(selPtArrXPos == 0) && !(selPtArrYPos ==0)&& !(
selPtArrXPos == (NUM_PTS+1)) && !(selPtArrYPos ==(NUM_PTS+1)))
makeRect=true;
repaint();
/*System.out.println("zone = "+zone+"\n array X value at pos
"+selPtArrXPos
+" = "+ptsOnFrameX[selPtArrYPos][selPtArrXPos]+"\n array Y value at
pos "+selPtArrYPos
+" = "+ptsOnFrameY[selPtArrYPos][selPtArrXPos]);*/
}
}
public void mouseReleased(MouseEvent event)
{
zone=false;
makeRect=false;
}
} );

repaint();

}// end constructor

public boolean isInsideBounds(int i, int j, int xVal, int yVal)
{
if(recBound(ptsOnFrameX[j],ptsOnFrameY[j],
ptsOnFrameX[i-1][j-1], ptsOnFrameY[i-1][j-1], ptsOnFrameX[i+1][j+1],
ptsOnFrameY[i+1][j+1]).contains(xVal, yVal))
{ return true; }
return false;
}


public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(sx,sy,HW-2*sx,HW-2*sy);

// draw unmoving points
g.setColor(Color.blue);
for(int i = 0; i<NUM_PTS+2; i++)
{
for(int j=0; j<NUM_PTS+2; j++)
{
g.fillRect(ptsOnFrameX[j]-2, ptsOnFrameY[j]-2, 5, 5);
}//end for
}//end for

g.setColor(Color.red);
if(zone==true && makeRect==true)
{
// connect horizontally
for(int i =selPtArrYPos-1; i<=selPtArrYPos+1; i+=2)
{
for( int j=selPtArrXPos-1; j<selPtArrXPos+1; j++)
g.drawLine(ptsOnFrameX[j], ptsOnFrameY[j],
ptsOnFrameX[j+1], ptsOnFrameY[j+1]);

}//end for

// connect vertically
for(int i = selPtArrYPos-1; i<selPtArrYPos+1; i++)
{
for( int j=selPtArrXPos-1; j<=selPtArrXPos+1; j+=2)
g.drawLine(ptsOnFrameX[j], ptsOnFrameY[j],
ptsOnFrameX[i+1][j], ptsOnFrameY[i+1][j]);
}

}//end if

g.setColor(Color.black);
// connect right diagonals
for(int i=0; i<NUM_PTS+1 ; i++)
{
for(int j=0; j<NUM_PTS+1 ; j++)
g.drawLine(ptsOnFrameX[j], ptsOnFrameY[j],
ptsOnFrameX[i+1][j+1], ptsOnFrameY[i+1][j+1]);

}//end for

// connect left diagonals
for(int i=0; i<NUM_PTS+1 ; i++)
{
for(int j=0; j<NUM_PTS+1 ; j++)
g.drawLine(ptsOnFrameX[i+1][j], ptsOnFrameY[i+1][j],
ptsOnFrameX[j+1], ptsOnFrameY[j+1]);

}//end for

// erease extra diagonals
g.setColor(Color.white);
g.drawLine(ptsOnFrameX[1][0], ptsOnFrameY[1][0],
ptsOnFrameX[0][1], ptsOnFrameY[0][1]);
g.drawLine(ptsOnFrameX[NUM_PTS+1][NUM_PTS],
ptsOnFrameY[NUM_PTS+1][NUM_PTS], ptsOnFrameX[NUM_PTS][NUM_PTS+1],
ptsOnFrameY[NUM_PTS][NUM_PTS+1]);

g.drawLine(ptsOnFrameX[NUM_PTS][0], ptsOnFrameY[NUM_PTS][0],
ptsOnFrameX[NUM_PTS+1][1], ptsOnFrameY[NUM_PTS+1][1]);
g.drawLine(ptsOnFrameX[0][NUM_PTS], ptsOnFrameY[0][NUM_PTS],
ptsOnFrameX[1][NUM_PTS+1], ptsOnFrameY[1][NUM_PTS+1]);


}// end paint

// sets an action zone around control point. 10x10 pxs square
protected Rectangle controlZone (int elX, int elY)
{
return new Rectangle(elX-7, elY-7, 15,15);
} // end controlZone

protected Rectangle recBound(int eX, int eY, int elX1, int elY1, int
elX2, int elY2)
{
System.out.println("start ex="+elX1+" eY="+elY1+" elX2="+elX2+"
elY2="+elY2);

return new Rectangle(elX1, elY1, elX2-elX1, elY2-elY1);
}

public void setStartPoints()
{

for(int i = 0; i<NUM_PTS+2; i++)
{
for(int j = 0; j<NUM_PTS+2; j++)
{
ptsOnFrameX[j] = sx + dx;
ptsOnFrameY[j] = sy + dy;

dx = dx + dist;
}
dx=0;
dy=dy+dist;
}

}// end setStartPoints

public void setNewControl(int xVal, int yVal)
{
ptsOnFrameX[selPtArrYPos][selPtArrXPos]=xVal;
ptsOnFrameY[selPtArrYPos][selPtArrXPos]=yVal;
}

public boolean isControlPoint(int xVal, int yVal)
{
for(int i =0; i<NUM_PTS+2; i++)
{
for(int j=0; j<NUM_PTS+2; j++)
{
if (controlZone(ptsOnFrameX[j],
ptsOnFrameY[j]).contains(xVal, yVal))
{
selPtArrXPos = j;
selPtArrYPos = i;
return true;
}
}
}
return false;
}

} // end class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top