Article View: borland.public.jbuilder.java.api
Article #2593Clone of applet???
From: Ren� Thomsen
Date: Wed, 20 Sep 2000 00:00
Date: Wed, 20 Sep 2000 00:00
170 lines
4763 bytes
4763 bytes
i want to clone an applet
the functionalty is like this: i have an applet which is a
chartpie(homemade) on dubbelclick
i want to create a new frame containing the original applet(this). this is
because the pie is embedded in html of course and resizing the original will
corrupt the html page, so a new frame with a copy of the class/applet would
be nice.
here is a eksample of the function ((copying) referencing) the container of
the applet but my original disappers offcourse since all handling are
reference.
void this_mouseClicked(MouseEvent e) {
if(e.getClickCount() > 1)
{
Container thisFrame = this;
do {
thisFrame = thisFrame.getParent();
}while ((thisFrame != null) && !(thisFrame instanceof Frame));
Frame et = new Frame();
try{
et = (Frame) thisFrame;
}catch (Exception ex) {}
et.setSize(700,700);
et.show();
et.repaint();
}
the function works fine but its really just a very advanced resize
here is the hole applet......
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
package untitled5;
import java.awt.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javachart.chart.*;
public class Applet1 extends Applet implements Cloneable{
PieChart chart;
int NumberOfValues;
//Construct the applet
public Applet1() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Initialize the applet
public void init() {
try {
chart = new PieChart();
NumberOfValues = Integer.parseInt(getParameter("NumberOfValues"));
chart.getPie().setTextLabelsOn(true);
chart.getBackground().setTitleString(getParameter("TitleString"));
chart.getBackground().setSubTitleString(getParameter("SubTitleString"));
chart.setThreeD(true);
chart.getDataRepresentation().setLabelsOn(true);
chart.addDataset("my
data",MakeDoubleArray(getParameter("DataSetValues"))
,MakeStringArray(getParameter("TextLabels")));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void paint(Graphics g) {
chart.resize(this.getSize().width, this.getSize().height);
chart.paint(this,g);
}
////////////////////////////////////////////////////////////////////////////
////
private String[] MakeStringArray(String str)
{
int n = 0;
int pos = 0;
int posComma;
String Array[] = new String[NumberOfValues];
while ( pos < str.length())
{
posComma = str.indexOf(',', pos);
if(posComma < 0)
posComma = str.length();
Array[n++] = str.substring(pos,posComma);
pos = posComma + 1;
}
return Array;
}
////////////////////////////////////////////////////////////////////////////
////
private double[] MakeDoubleArray (String str)
{
int n = 0;
int pos = 0;
int posComma;
double Array[] = new double[NumberOfValues];
while ( pos < str.length())
{
posComma = str.indexOf(',', pos);
if(posComma < 0)
posComma = str.length();
Array[n++] = (double)
Float.valueOf(str.substring(pos,posComma)).floatValue();
pos = posComma + 1;
}
return Array;
}
public String[][] getParameterInfo(){
return null;
}
private void jbInit() throws Exception {
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
this_mouseClicked(e);
}
});
}
void this_mouseClicked(MouseEvent e) {
if(e.getClickCount() > 1)
{
Container thisFrame = this;
do {
thisFrame = thisFrame.getParent();
}while ((thisFrame != null) && !(thisFrame instanceof Frame));
Frame et = new Frame();
try{
et = (Frame) thisFrame;
}catch (Exception ex) {}
et.setSize(700,700);
et.show();
et.repaint();
}
}
have tried the cloneable interface but it only returns a shallow copy? of my
applet
so what do i do?
Technical Details
Message-ID:
<8qafa7$he48@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,ad5b1d0138e30fef,start X-Google-Attributes: gid1089d0,public From: "Ren� Thomsen" <rtNOSPAM@bankinvest.dk> Subject: Clone of applet??? Date: 2000/09/20 Message-ID: <8qafa7$he48@bornews.borland.com> X-Deja-AN: 672042121 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.api