problem with multiple internal frames for drawing different graphs



Hello,

I want to use the same code to draw graphs just with different input so
I have the following code:

showgraph sg1 = new showgraph("AAAA",tp,x[n], y[n]);
showgraph sg2 = new showgraph("BBBBB",tp,x[n+1], y[n+1]);


public showgraph(String text, JPanel tp, int x, int y)
{
JPanel pan = new graphpanel(text);

setClosable(true);
setPreferredSize(new
java.awt.Dimension(globals.smallFrameX,globals.smallFrameY));
pan.setBackground(new java.awt.Color(255, 255, 255));
pan.setForeground(new java.awt.Color(51, 51, 51));
getContentPane().add(pan, java.awt.BorderLayout.CENTER);

pack();
this.setVisible(true);
tp.add(this, new org.netbeans.lib.awtextra.AbsoluteConstraints(x,
y, globals.smallFrameX, globals.smallFrameY ) );
this.setTitle(title);
this.setLocation(x,y);
this.toFront();
}

public class graphpanel extends JPanel{
public static String data;

public graphpanel(String str)
{
int xpan = this.getWidth();
int ypan = this.getHeight();
System.out.println(xpan +" - "+ypan);
data=str;
}//graphpanel


public void paintComponent(Graphics g)
{
super.paintComponent(g);

int xpan1 = this.getWidth();
int ypan1 = this.getHeight();
System.out.println(xpan1 +" - "+ypan1);

g.drawString( data, 10, 10 );
}
Now when I run the code it will produce 2 windows (internal frames as
expected) but both will have the same content "AAAA". What did I do
wrong.

Furthermore, Iäd like to have as much time consuming code in the
graphpanel method instead of the paintComponent method, but it seems
that the witdh and height (xpan and ypan) isn't known in the moment
when graphpanel is called. I guess it is due to the fact that the
pack() in showgraph is called afterwords.

How can I resolve this issues?

.



Relevant Pages

  • How Do I Set the Focus to a Object?
    ... I had a program running some time back that brought up a <JPanel> ob- ... int height; ... Color clr; ... public void keyReleased ...
    (comp.lang.java.programmer)
  • JPanel inside a JScrollPane
    ... I have a JPanel ... subclass which I'd like to be able to scroll in my app. ... public int getScrollableBlockIncrement( ... public boolean getScrollableTracksViewportHeight() { ...
    (comp.lang.java.gui)
  • Applet Java Problem help please
    ... public static final int YD=30; ... JPanel jpanel1=new JPanel; ... public void paint{ ... class EnsForme extends JPanel implements MouseListener,MouseMotionListener { ...
    (comp.lang.java.help)
  • Applet Problem help please
    ... public static final int YD=30; ... JPanel jpanel1=new JPanel; ... public void paint{ ... class EnsForme extends JPanel implements MouseListener,MouseMotionListener { ...
    (comp.lang.java.help)
  • Re: Size of JPanel inside contentPane
    ... setBounds(int, int, int, int), where you can write the position and the ... JPanel main=new Panel; ... "Heiko Fleischmann" escribió en el mensaje ... > I have a JPanel as a contentPane of a JFrame, ...
    (comp.lang.java.help)