Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2005

Tip: Looking for answers? Try searching our database.

class included in JApplet ?

Thread view: 
mgdz - 19 Jul 2005 16:38 GMT
Hi
Have a general question about  classes contained by JApplet.

There is a class which arranges its components lay out and their behaviour
(in answer for the exteranl, user's actions-> it sets the values of this
components and paint something).

Can I just add this class as a contentPane of a JApplet and still be shure
that the behaviour will work. If not , why? (could it be the repaint()
thing?)

Maybe setting the values is possible only from the JApplet level?
becouse now I want to do it lets say , 'internally' by this contained
class, hmm it doesn't work as well as I suppoused it would be :/.
Andrew Thompson - 19 Jul 2005 17:47 GMT
> Hi
> Have a general question about  classes contained by JApplet.
[quoted text clipped - 10 lines]
> becouse now I want to do it lets say , 'internally' by this contained
> class, hmm it doesn't work as well as I suppoused it would be :/.

Is that any earth language?

If you are asking about resizeable applets, then yes,
it is certainly achievable.

You make a resizeable applet much the same way you make
a resizeable application.  Then you simply call it from
some appropriate HTML.  

E.G. <http://www.physci.org/codes/resize/fullwnd5.html>

For the tricks in the HTML, see the source of that page,
for further discussion and Java code, see here..
<http://www.physci.org/codes/resize>

HTH

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Or Is It?

mgdz - 22 Jul 2005 13:28 GMT
Concerning my alienlike language, well, if my name was John Simpson I
believe I'd speak and write Englisch perfectly, but as long as I am
someone like Jan Kowalski I let myself make some mistakes (well, as long
as you can understand me).
Still thank you for not bothering to much about my English and for advice
regarding java language (what's more important).

I was asking whether the JApplet class (or class which extends JApplet)
would be 'transparent'(not disturbing) for the methods <changing values,
painting something,events handling> which belongs to class included into
this JApplet.
And the answer is yes it is transparent, and every method (even event
handling) implemented in this included class should be realized (and
seenable) in JApplet.
Andrew Thompson - 22 Jul 2005 13:55 GMT
> I was asking whether the JApplet class (or class which extends JApplet)
> would be 'transparent'(not disturbing) for the methods <changing values,
> painting something,events handling> which belongs to class included into
> this JApplet.

'inheritance' is, I believe, the word that describes
how /method/s & /attribute/s of a class are inherited
by any class that /extend/s it.

Only by /overiding/ the inherited method do you change it.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
A By-Product Of The TV Industry

Monique Y. Mudama - 22 Jul 2005 15:26 GMT
>> I was asking whether the JApplet class (or class which extends
>> JApplet) would be 'transparent'(not disturbing) for the methods
[quoted text clipped - 6 lines]
>
> Only by /overiding/ the inherited method do you change it.

I swear I'm not a spelling nazi, but since the context seems to be
teaching a person who's not a native English speaker appropriate
terms, I feel like I should clarify that the term is "overriding,"
with two Rs.

And a question: in Java, we have interfaces that are implemented.
This is also called inheritance, right?

Signature

monique

Thomas Weidenfeller - 22 Jul 2005 15:45 GMT
> And a question: in Java, we have interfaces that are implemented.
> This is also called inheritance, right?

It is a so-called /realization/.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Andrew Thompson - 22 Jul 2005 16:41 GMT
> I feel like I should clarify that the term is "overriding,"
> with two Rs.

Thanks - I appreciate corrections to 'core terms',
it is important to get those right.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Controlling You Through A Chip In Your Butt Since 1999

mgdz - 25 Jul 2005 12:11 GMT
For clearing up - I am not using inheritance, I'm rather using composition.

I'll give an example...Classes(Parameter, Generator) are used as a
components of an Applet (those classes are aggregated in the applet
class). This classes depends somehow from each other, this dependance is
implemented in the methods of this classes.

So, the Generator component is repainted when its method change1 or
change2  is called, and this method is called by, other method (handleLR
or handleUD respectively)which are called when an event of scrollBar
status chenge happens.

[code]
//Parameter class prepares the panel for managing of some parameters by
changing the scrollBar's values
public class Parameter extends JPanel implements AdjustmentListener{

public JScrollBar scrbF;
public JScrollBar scrbA ;
public JTextField wartF ;
public JTextField wartA ;
Appl board1; //Appl is the class in which the object of Parameter class
would be aggregated

public Parameter(int a,int b,int c,int d,int e,int f,int g,int h,Appl
mainBoard) {
     scrbF = new JScrollBar(JScrollBar.HORIZONTAL, a, b, c, d);
     scrbA = new JScrollBar(JScrollBar.HORIZONTAL, e, f, g, h);

     wartF = new JTextField ();
     wartA = new JTextField ();

   board1=mainBoard;  //refference to the class in which the object of
Parameter class is aggregated

   Dimension size=new Dimension(400,80);
   setPreferredSize(size);

   GridLayout gridbg = new GridLayout(2,3);

   setLayout(gridbg);

   JLabel label1 = new JLabel("left-right:", JLabel.LEFT);
   add(label1);
   
   wartF.setEditable(false);
   wartF.setText(""+scrbF.getValue());
   add(wartF);
   
  scrbF.addAdjustmentListener(this);
  add(scrbF);

   JLabel label2 = new JLabel("up-down:", JLabel.LEFT);
   add(label2);
 
    wartA.setEditable(false);
    wartA.setText(""+scrbA.getValue());
    add(wartA);
   
    scrbA.addAdjustmentListener(this);
    add(scrbA);

    setBorder(BorderFactory.createTitledBorder("GO"));            
   }
   
   public void adjustmentValueChanged(AdjustmentEvent e) {
           Object source = e.getSource();
           if (source == scrbF) {
               int value;

               value=scrbF.getValue();
               wartF.setText(""+value);
               board1.handleLR(this); //usage of the method of Appl
class,   'this' reffers to Parameter object which would produce an event
           }
           if (source == scrbA){
               int value;

               value=scrbA.getValue();
               wartA.setText(""+value);
               board1.handleUD(this); ////usage of the method of Appl
class
           }
       }
}

///////////////////////////////////////////////

//class draws something
public class Generator extends JPanel{

   int fnx, fny, fnx1, fny1;

   public Generator() {

       fnx=10;
       fny=10;
       fnx1=30;
       fny1=30;

       Dimension size=new Dimension(400,300);
       setPreferredSize(size);

       repaint();
   }

   public void paintComponent(Graphics g) {

           super.paintComponent(g);
           Graphics2D g2D = (Graphics2D) g;
           g2D.setColor(Color.black);
           g2D.setBackground(Color.lightGray);
           g2D.drawLine((fnx1) , (fny1) , (fnx) , (fny) );
           fnx1=fnx;
           fny1=fny;
           }
    //following methods changes the parameters of drawLine()method
          public void change1(int a) {
             fnx=a*10;
             repaint();
            }
         public void change2(int a) {
             fny=a*10;
             repaint();
         }
}
///////////////////////////////////////////

//this class is an applet and agregates Parameter and Generator classes
and invoke some of their methods to make some changes.

public class Appl extends JApplet {

   JPanel contentPane;
   JPanel chartField;
   Parameter manager;
   Generator chartGenerator;

   public void init() {
       contentPane=new JPanel();
       contentPane.setLayout(new BoxLayout(contentPane,
BoxLayout.Y_AXIS));
     
//contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

       manager= new Parameter(2,0,0,6,6,0,6,10,this);

       chartField=new JPanel();
       chartGenerator=new Generator();
       chartField.setLayout(new BorderLayout());
       chartField.setBorder(BorderFactory.createTitledBorder("Chart"));
       chartField.add(chartGenerator, BorderLayout.CENTER);
       
       contentPane.add(manager);
       contentPane.add(chartField);
       
       setContentPane(contentPane);
   }
   public void handleLR(Parameter x){
          int value;

          value=manager.scrbF.getValue();
          chartGenerator.change1(value);
   }
      public void handleUD (Parameter x){
          int value;

          value=manager.scrbA.getValue();
          chartGenerator.change2(value);
      }
}

[/code]

My program consist on this general design I've shown above.
Why it doesn't work as an applet? The following message is displayed by
the browser:Applet notinited,  but in JBuilder applet viewer it works very
well. And what you'll say? Any ideas?
Andrew Thompson - 25 Jul 2005 12:36 GMT
> Why it doesn't work as an applet?

Maybe it is just sleepy.  Try shaking it.   [ ;-) ]

>..The following message is displayed by the browser

Which browser?

>..:Applet notinited,  

Ahh.. now wait.  Not *IE* by any chance?
You might have it configured to use 1.1
<http://www.physci.org/pc/property.jsp?prop=java.version+java.vendor>

There are mentions of applets (and IE) in the FAQ here is one of them..
<http://www.physci.org/codes/javafaq.jsp#appletie>
..but please read all of it.

>..but in JBuilder applet viewer it works very well.
> And what you'll say? Any ideas?

Drop the IDE[1].  Suspend applet development[2].
Post to a beginners group[3].

[1]
<http://qa.jtiger.org/GetQAndA.action?qids=52&showAnswers=true&showCodeLineNumber
s=true&showCodeBorder=true&codeStyle
=>
[2] <http://www.physci.org/codes/javafaq.jsp#appfirst>
[3] <http://www.physci.org/codes/javafaq.jsp#cljh>

HTH

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
When You See The Robot, Drink!

mgdz - 25 Jul 2005 18:03 GMT
I'm not using builder for its 'builder' features just to have a quick view
of graphical outcome,quick moving between sources,and to avoid spelling
mistaces in easy way, I write everything myself-funny hmm, ...I know it is
created for different things.
I've been testing program with Netscape and IE browsers (where IE is seted
to use Java 2 v1.4.2_08).
Demos delivered with j2sdk1.4.2_08 works well when run by both browsers.
I have compilled the sources on outer server (compillation is ok but...->)
and nothing more achived.
I haven't read all relevant FAQ's so still believe that I'll find the
solution. Thanks for help :),and for showing new sources of info.
When I posted it wasn't 7.00 hour in my time zone :) , I am not 'that'
javafreak.
Andrew Thompson - 25 Jul 2005 19:26 GMT
> I'm not using builder for its 'builder' features just to have a quick view
> of graphical outcome,quick moving between sources,and to avoid spelling
[quoted text clipped - 9 lines]
> When I posted it wasn't 7.00 hour in my time zone :) , I am not 'that'
> javafreak.

This is a bit confusing because you fo not include *any* if the
early text (a little like I did above).  Please try to leave
a little of what you are replying to - so people can understand
better.

Your code works fine for me here, using Java 1.5 to compile
and in the browser (IE and Moz.).

So, to sum up.  

- You are using the code you posted, compiled by JBuilder.
- It works in JBuilder's preview, but not IE or Netscape running Java 1.4
- you are getting 'noinited' messages in *both* browsers.

You need to find the consoles of each browser.  In IE, it is..
Tools | Sun Java Console.

I suspect your JBuilder might be set to compile for 1,5,
but there is not enough information to say for sure..

Can you load your classes up to a web site?  ( With a
web-page, of course! ) It can be a lot quicker if
we can see the page/applet for ourselves.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Soon To Be A Major Religion

mgdz - 25 Jul 2005 18:52 GMT
I'm not using builder for its 'builder' features just to have a quick view
of graphical outcome,quick moving between sources,and to avoid spelling
mistaces in easy way, I write everything myself-funny hmm, ...I know it is
created for different things.
I've been testing program with Netscape and IE browsers (where IE is seted
to use Java 2 v1.4.2_08).
Demos delivered with j2sdk1.4.2_08 works well when run by both browsers.
I have compilled the sources on outer server (compillation is ok but...->)
and nothing more achived.
I haven't read all relevant FAQ's so still believe that I'll find the
solution. Thanks for help :),and for showing new sources of info.
When I posted it wasn't 7.00 hour in my time zone :) , I am not 'that'
javafreak.
mgdz - 26 Jul 2005 07:36 GMT
Unfortunatelly I cannot open my applet when it is setted in outside server
(the same sad message ...notinited appears).

The URL of my page is :
http://fatcat.ftj.agh.edu.pl/~mgdz/lis/L.html

Now I think that the problem may concern the path I give in base tag, and
in applet code property.
The html code:

[cpde]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1250">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<title>Lissajous</title>
<base  href="http://fatcat.ftj.agh.edu.pl/~mgdz/lis/">
</head>
<body>
<applet  code="LissajousApl.class" name="TestApplet" width="400"
height="500" hspace="0" vspace="0" align="middle"></applet>
</body>
</html>

[/code]
Andrew Thompson - 26 Jul 2005 07:52 GMT
> Unfortunatelly I cannot open my applet when it is setted in outside server
> (the same sad message ...notinited appears).
>
> The URL of my page is :
> http://fatcat.ftj.agh.edu.pl/~mgdz/lis/L.html

I can see that applet just fine in IE (and Opera)
using Java 1.5.0.

Can someone else check it with 1.4?  I suspect the class
format is 1.5 only.  But cannot immediately see the class
format version number in the consoles.

What is a programmatic way to tell that?

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Soon To Be A Major Religion

mgdz - 26 Jul 2005 09:23 GMT
>Can someone else check it with 1.4?  I suspect >the class format is 1.5
only.

I could run applet which source file was compiled on mine machine with
java 1.4, using browser with the same java version,but I couldn't run
applet that was 'created' from the same sources compiled on other server
(with java 1.5 'onboard') unless I've upgraded mine java.

And that was the thing, I've upgraded the java version and now everything
is just fine.
So, the java version used by browser must be the same or higher(maybe),
than the jdk's version with which the sources were compilled.

>What is a programmatic way to tell that?
Maybe compilersensitivity ? :)

Thank you very much for help.  
Andrew Thompson - 26 Jul 2005 09:31 GMT
> So, the java version used by browser must be the same or higher(maybe),
> than the jdk's version with which the sources were compilled.

No!  You can compile classes compatible for Java 1.1
(or other early) VM's using the 1.5 compiler.  Trust
me on that, I jave a lot of experience with it.
You just need to know how.

Which brings me to ..JBuilder.

I use JBuilder often, it is funky.  But you should stop
using it for the moment, and instead switch to a much
simpler Java editor like TextPad.

The real problem is that JBuilder is doing things for you
that you do not understand.  Once you understand those things,
you will be able to change JBuilder to do what you need.

But first, you need to understand what you are doing.

Are you willing to give up using JBuilder for a while?

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Transmitido en Martian en SAP

mgdz - 25 Jul 2005 12:22 GMT
For clearing up - I am not using inheritance, I'm rather using composition.

I'll give an example...Classes(Parameter, Generator) are used as a
components of an Applet (those classes are aggregated in the applet
class). This classes depends somehow from each other, this dependance is
implemented in the methods of this classes.

So, the Generator component is repainted when its method change1 or
change2  is called, and this method is called by, other method (handleLR
or handleUD respectively)which are called when an event of scrollBar
status chenge happens.

[code]
//Parameter class prepares the panel for managing of some parameters by
changing the scrollBar's values
public class Parameter extends JPanel implements AdjustmentListener{

public JScrollBar scrbF;
public JScrollBar scrbA ;
public JTextField wartF ;
public JTextField wartA ;
Appl board1; //Appl is the class in which the object of Parameter class
would be aggregated

public Parameter(int a,int b,int c,int d,int e,int f,int g,int h,Appl
mainBoard) {
     scrbF = new JScrollBar(JScrollBar.HORIZONTAL, a, b, c, d);
     scrbA = new JScrollBar(JScrollBar.HORIZONTAL, e, f, g, h);

     wartF = new JTextField ();
     wartA = new JTextField ();

   board1=mainBoard;  //refference to the class in which the object of
Parameter class is aggregated

   Dimension size=new Dimension(400,80);
   setPreferredSize(size);

   GridLayout gridbg = new GridLayout(2,3);

   setLayout(gridbg);

   JLabel label1 = new JLabel("left-right:", JLabel.LEFT);
   add(label1);
   
   wartF.setEditable(false);
   wartF.setText(""+scrbF.getValue());
   add(wartF);
   
  scrbF.addAdjustmentListener(this);
  add(scrbF);

   JLabel label2 = new JLabel("up-down:", JLabel.LEFT);
   add(label2);
 
    wartA.setEditable(false);
    wartA.setText(""+scrbA.getValue());
    add(wartA);
   
    scrbA.addAdjustmentListener(this);
    add(scrbA);

    setBorder(BorderFactory.createTitledBorder("GO"));            
   }
   
   public void adjustmentValueChanged(AdjustmentEvent e) {
           Object source = e.getSource();
           if (source == scrbF) {
               int value;

               value=scrbF.getValue();
               wartF.setText(""+value);
               board1.handleLR(this); //usage of the method of Appl
class,   'this' reffers to Parameter object which would produce an event
           }
           if (source == scrbA){
               int value;

               value=scrbA.getValue();
               wartA.setText(""+value);
               board1.handleUD(this); ////usage of the method of Appl
class
           }
       }
}

///////////////////////////////////////////////

//class draws something
public class Generator extends JPanel{

   int fnx, fny, fnx1, fny1;

   public Generator() {

       fnx=10;
       fny=10;
       fnx1=30;
       fny1=30;

       Dimension size=new Dimension(400,300);
       setPreferredSize(size);

       repaint();
   }

   public void paintComponent(Graphics g) {

           super.paintComponent(g);
           Graphics2D g2D = (Graphics2D) g;
           g2D.setColor(Color.black);
           g2D.setBackground(Color.lightGray);
           g2D.drawLine((fnx1) , (fny1) , (fnx) , (fny) );
           fnx1=fnx;
           fny1=fny;
           }
    //following methods changes the parameters of drawLine()method
          public void change1(int a) {
             fnx=a*10;
             repaint();
            }
         public void change2(int a) {
             fny=a*10;
             repaint();
         }
}
///////////////////////////////////////////

//this class is an applet and agregates Parameter and Generator classes
and invoke some of their methods to make some changes.

public class Appl extends JApplet {

   JPanel contentPane;
   JPanel chartField;
   Parameter manager;
   Generator chartGenerator;

   public void init() {
       contentPane=new JPanel();
       contentPane.setLayout(new BoxLayout(contentPane,
BoxLayout.Y_AXIS));
     
//contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

       manager= new Parameter(2,0,0,6,6,0,6,10,this);

       chartField=new JPanel();
       chartGenerator=new Generator();
       chartField.setLayout(new BorderLayout());
       chartField.setBorder(BorderFactory.createTitledBorder("Chart"));
       chartField.add(chartGenerator, BorderLayout.CENTER);
       
       contentPane.add(manager);
       contentPane.add(chartField);
       
       setContentPane(contentPane);
   }
   public void handleLR(Parameter x){
          int value;

          value=manager.scrbF.getValue();
          chartGenerator.change1(value);
   }
      public void handleUD (Parameter x){
          int value;

          value=manager.scrbA.getValue();
          chartGenerator.change2(value);
      }
}

[/code]

My program consist on this general design I've shown above.
Why it doesn't work as an applet? The following message is displayed by
the browser:Applet notinited,  but in JBuilder applet viewer it works very
well. And what you'll say? Any ideas?
mgdz - 25 Jul 2005 20:35 GMT
I don't know why but every time I reload the page the message which I've
already sent is being sent again...I'll try not to do it, sorry.

At last I have got some achivements.

I've changed the settings of the Path variable at first (I've added the
path to bin folder of j2sdk packet), and then put in (better) order my
source and classes files (which concerns the 'packet' declarations)what is
very important, and everything works well on my computer now. Either
running by NETSCAPE or IE.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.