applet code multiple classes help :(

Ok, i made an applet which have 2 .class files one is AppTs.class and other is MyPot.class, what I need to write to lets say index.html
to make that applet viewable in browser. Thx.
I try this but it say Applet failed to load...
<HTML>
<BODY>
<APPLET CODE=AppTs.class WIDTH=200 HEIGHT=100>
<APPLET CODE=MyPot.class WIDTH=200 HEIGHT=100>
</APPLET>
</BODY>
</HTML>

Are you sure, could be because, I am using Pirc bot Framework, which isn't in standard Java libraries, is maybe that causing problem, because, applet works perfectly when i run it from Eclipse IDE.
And that your HTML code that you write, it makes 2 applets, but i need only one because GUI is only in AppTs, why is that happening neither?
Edited by: systat on Mar 28, 2008 11:35 AM

Similar Messages

  • Java Applets and multiple classes not working.

    I have tested my JApplet class alone to view its layout and to make sure it actually works. But once I add in my other classes, compile, jar, and test I get the error:
    java.lang.NoClassDefFoundError: AlakApp (wrong name: alak/codeFiles/AlakApp)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    4)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:155)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:127)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:618)
            at sun.applet.AppletPanel.createApplet(AppletPanel.java:779)
            at sun.applet.AppletPanel.runLoader(AppletPanel.java:708)
            at sun.applet.AppletPanel.run(AppletPanel.java:362)
            at java.lang.Thread.run(Thread.java:619)My Directory contains these and only these:
    F:\alak\codeFiles:
      AlakApp.java
      Game.java
      Board.java
      Space.java
      index.html
      AlakGame.jarAll my classes are in the package alak.codeFiles.
    My .html file contains this:
    <HTML>
    <HEAD>
      <TITLE>ALAK</TITLE>
    </HEAD>
    <BODY>
      <applet code="AlakApp.class" archive="AlakGame.jar" width=400 height=200>
      Please use a Java compatible browser to see this.
      </applet>
      <br>
    </BODY>
    </HTML>These are they commands I am issuing:
    F:\alak\codeFiles>javac *.java
    F:\alak\codeFiles>jar -cvf AlakGame.jar *.class
    F:\alak\codeFiles>appletviewer index.htmlI've been trying many different things to narrow down what is going on. If you need to see my code let me know, but I've tested everything with a text-based user interface and they work.
    So does anyone know the cause of this error?

    Ok i rared the test and uploaded to rapidshare.. here is the link:
    http://rapidshare.com/files/76860865/test.rar.html
    But here is the code. They are in the directory /test/files/
    ADigit.java
    package test.files;
    public class ADigit
      private int value;
      public ADigit( int val )
       this.value = val;
      public String toString()
       return "" + this.value;
    }ADigitApp.java
    package test.files;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ADigitApp extends JApplet implements ActionListener
      private ADigit numeroUno;
      private int currentNum;
      private Container container;
      private javax.swing.JLabel jLabel;
      private javax.swing.JTextArea jTextArea;
      private javax.swing.JButton jButton;
      public void init()
        currentNum = 1;
        numeroUno = new ADigit( currentNum );
         container = getContentPane();
        container.setLayout( new BorderLayout() );
         jLabel = new javax.swing.JLabel();
         jTextArea = new javax.swing.JTextArea();
         jLabel.setText( "The Number is: " );
         jTextArea.setText( numeroUno.toString() );
         jButton = new javax.swing.JButton();
         jButton.setText( "New Number" );
        jButton.addActionListener( this );
         container.add( jLabel, BorderLayout.WEST );
         container.add( jTextArea, BorderLayout.CENTER );
         container.add( jButton, BorderLayout.EAST );
        setSize( 200, 200 );
      public void actionPerformed( ActionEvent e )
        this.currentNum++;
         numeroUno = new ADigit( this.currentNum );
         jTextArea.setText( numeroUno.toString() );
    }index.html
    <HTML>
    <HEAD>
      <TITLE>NUMBERSSSS</TITLE>
    </HEAD>
    <BODY>
      <applet code="ADigitApp.class" archive="NumberFun.jar" width=200 height=200>
      Please use a Java compatible browser to see this.
      </applet>
      <br>
    </BODY>
    </HTML>Commands:
    /test/files>javac *.java
    /test/files>jar -cvf NumberFun.jar *.class
    /test/files>appletviewer index.htmlThis example produces the same style of error.

  • Why won't this Applet work? Any help?

    I followed a tutorial, though the tutorial left me to do a lot of the work. Which is good.
    Anyway, I finished the Applet, but I get a message in the bottom corner of the window saying "Applet not initialized."
    I can't figure out what's wrong.
    I downloaded the tutorial's source code and checked it, and I think I have everything they do... I tried running the downloaded source code and it worked fine.
    Here's the main class file of my Applet:
    import java.applet.*;
    import java.awt.*;
    import java.net.*;
    public class Main2 extends Applet implements Runnable
              AudioClip ballLost = getAudioClip(getCodeBase(), "beep_1.au");
              AudioClip bounce = getAudioClip(getCodeBase(), "beep_2.au");
              Player player = new Player();
              Ball ball1 = new Ball(20, this.getSize().width+40, this.getSize().height-30,1,3,8,ballLost,bounce,player,Color.red);
              Ball ball2 = new Ball(20, this.getSize().width+40, 30,1,5,10,ballLost,bounce,player,Color.blue);
              Thread th;
              Cursor c;
              Image dbImage;
              Graphics dbg;
         boolean isStopped = true;
         public void init()
              c = new Cursor(Cursor.CROSSHAIR_CURSOR);
              this.setCursor(c);
              ballLost = getAudioClip(getCodeBase(), "beep_1.au");
              bounce = getAudioClip(getCodeBase(), "beep_2.au");
              player = new Player();
              ball1 = new Ball(20, this.getSize().width+40, this.getSize().height-30,1,3,8,ballLost,bounce,player,Color.red);
              ball2 = new Ball(20, this.getSize().width+40, 30,1,5,10,ballLost,bounce,player,Color.blue);
         public void start()
              th = new Thread(this);
              th.start();
         public void stop()
              th.stop();
         public void run()
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              while (true)
                   if (player.getLives()>0 && !isStopped)
                        ball1.move();
                        ball2.move();
                   repaint();
                   try
                        Thread.sleep (30);
                   catch (InterruptedException ex)
                        // do nothing
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public void paint(Graphics g)
              if (player.getLives()>0)
                   ball1.drawBall(g);
                   ball2.drawBall(g);
                   if (isStopped)
                        g.setColor(Color.green);
                        g.drawString("Double click to start.", 40, 200);
              else if (player.getLives() <= 0)
                   g.setColor(Color.green);
                   g.drawString("Game Over!", 40, 200);
                   g.drawString("Double click to player again", 40, 300);
                   isStopped = true;
         public boolean mouseDown(Event e, int x, int y)
              if (!isStopped)
                   if (ball1.userHit(x,y))
                        //Need audio
                        ball1.ballWasHit();
                   else if (ball2.userHit(x,y))
                        //Need audio
                        ball2.ballWasHit();
                   else
                        //Play normal shot audio
              else if (isStopped && e.clickCount == 2)
                   isStopped = false;
                   init();
              return true;
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
    }My HTML code uses <APPLET CODE="Main2.class" WIDTH=700 HEIGHT=400>.
    And they are both located in the same folder.
    Any idea what's going wrong here?
    Thanks for any help.

    All of the files are in the folder.
    My folder contains:
    Main2.class
    Ball.class
    Player.class
    ShooterGame.html
    beep_1.au
    beep_2.au
    And corresponding source code files.
    Looks correct, right?
    ...

  • Jsp:plugin applet code

    Hi all, I've been wondering if applets can be dynamically called from a jsp or servlet using strings in the applet code section. would this be good if a database was used to store the paths of the applets?
    i've tried this with a small applet in different ways, just to see the effect in Apache Tomcat 4.1.24, but it didn't really work. could anyone help me out here?
    the coding i've been using is below :
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    Here is the applet!
    <br>
    <jsp:plugin type="applet" code="ElecBill_a" codebase="." height="200" width="200" >
         <jsp:fallback>
              <p> Unable to use Java Plugin</p>
         </jsp:fallback>     
         </jsp:plugin>
    <br>
    <applet code = "ElecBill_a.class" height="200" width="200"></applet>
    //up to here it works fine, both applets appear. but below, the string is read directly and causes an error
    <%! String myapplet = new String("ElecBill_a"); %>
    <%! public String getName() {return myapplet; } %>
    <br> The name of the class file is <%= getName() %>
    <br>
    <jsp:plugin type="applet" code="<%= "myapplet" %>" codebase="." height="200" width="200" >
         <jsp:fallback>
              <p> Unable to use Java Plugin</p>
         </jsp:fallback>     
         </jsp:plugin>
    </body>
    </html>

    yes, i suppose it doesn't. i've tried to insert it using the original way with the applet tag like this
    <APPLET code = <%= getName() %> width=300 height=300>
    </APPLET>
    and this works...so i might go with this for a short term solution until i can figure out a better way...thanks!

  • Don't want to re-execute applet code, when refresh browser

    Hi,
    I am developing online exam project, here my issue is in timer, I am creating timer in thread.sleep(1000); (ie) 1000 mili sec = 1 sec. once exam started, i am started reducing timer value. While moving to next question, I want previous Applet timer value in next page. Here i am getting initial value of each time refreshing,
    example:
    suppose timer running in browser like this : 00:00:46 ----> when refresh same page i need value reduce from 00:00:46, But its reload from initial value (ie): 00:00:59 in below example code.
    Here is my Applet code :
    import java.awt.*;
    import java.util.*;
    import java.applet.*;
    import java.net.*;
    public class myclock1 extends Applet implements Runnable
    Thread t,t1;
    int hour=0,minute=0,second=0;
    URL targetURL;
    String URLString = "http://localhost:8080/testing/examresult.jsp";
    AppletContext context;
    public void start()
    minute = Integer.parseInt(getParameter("min"));
    second = Integer.parseInt(getParameter("sec"));
    context = getAppletContext();
    t = new Thread(this);
    t.start();
    public void run()
    t1 = Thread.currentThread();
    repaint();
    public void paint(Graphics g)
    if(hour==0 && minute==0 && second==0)
    try
    targetURL = new URL(URLString);
    catch (MalformedURLException e)
    // Code for recover from the exception
    context.showDocument(targetURL);
    t.destroy();
    t1.destroy();
    this.destroy();
    second--;
    if(second==-1)
    second = 59;
    minute = minute-1;
    if(minute==0)
    if(hour>=1)
    hour = hour - 1;
    minute = 59;
    g.drawString(hour + ":" + minute + ":" + second, 20, 30);
    repaint();
    try{
    t1.sleep(1000); /// 1000 mili sec = 1 sec
    catch(InterruptedException e)
    In JSP Page Code:
    <jsp:plugin type="applet" code="myclock1.class" height="150" width="300">
    <jsp:params>
    <jsp:param name="min" value="0" />
    <jsp:param name="sec" value="60" />
    </jsp:params>
    </jsp:plugin>
    How to do that, Urgent Plz help me.
    Thanks in Advance,
    S.Shyam.

    Is it SAX, Dom, JAXB or something else you are talking about?

  • Need to have an applet in web browser-- HELP

    I have been trying to have the prefuse Graphview applet in a web browser...
    The following is my HTML file
    <html>
    <head>
    <title>Prefuse Demo</title>
    </head>
    <body>
    <applet code="GraphView.class"
    archive="demos.jar,prefuse.jar,prefuse.src.jar"
    width="400" height="400">
    </applet>
    </body>
    </html>
    I am getting the following error when running on the web browser
    java.lang.NoClassDefFoundError: GraphView (wrong name: demos/applets/GraphView)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    I have been on this for 2 days.....really frustrated......
    1)All classfiles (GraphView.class) / jar files (got using the build.bat prefuse and build.bat demos) and
    the htmlfile (GraphView.html) is stored in C:\Documents and Settings\Rudolph\Desktop\prefuse-beta\demos\prefuse\demos\applets
    Can u shed more light on this problem.
    Thanks
    ---! Rudolph

    Try specifying the 'code' attribute for the applet tag in the following manner:
    <applet code="org/apache/maven/plugins/grafo/gui/applets/GraphViewApplet.class"
    archive="maven-grafo-plugin-1.0-SNAPSHOT.jar,prefuse-beta-20060220.jar"
    width="800" height="500">

  • Applet keeps failing, please help!

    Why won't this code run as an applet in a web page?
    my HTML code goes as follows (very simple just want it to show the applet)
    <html>
    <body>
    <applet code="Main.class" width="450" height="450">
    </applet>
    </body>
    </html>
    import javax.swing.*;
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.event.*;
    public class Main extends JPanel
                            implements ActionListener {
        protected JButton b1, b2; //Add 3 JButtons to be used throughout the whole class
        protected JLabel l1, l2, l3; //add 3 labels to be used throughout the class
        public Main() {
            b1 = new JButton("vote Yes"); //Sets b1 (from protected) to Vote No
            b1.setMnemonic(KeyEvent.VK_D);
            b1.setActionCommand("yes");
            b2 = new JButton("Vote No"); //Sets b2 (from protected) to Vote No
            b2.setMnemonic(KeyEvent.VK_E);
            b2.setActionCommand("no");
            l1 = new JLabel("0");
            l2 = new JLabel("0");
            l3 = new JLabel("Votes (yes/no) :");
            //Listen for actions on buttons 1  and  2 (under).
            b1.addActionListener(this);
            b2.addActionListener(this);
            b1.setToolTipText("Click this button to vote yes.");
            b2.setToolTipText("Click this button to vote no.");
            //Adds the buttons and labels to the container (similar to the content in javax.swing that i posted earlier).
            add(b1);
            add(b2);
            add(l3);
            add(l1);
            add(l2);
        public void actionPerformed(ActionEvent e) {
            if ("yes".equals(e.getActionCommand())) {
                 l1.setText("1");
                 b1.setEnabled(false);
                 b2.setEnabled(false);
                 System.out.println("Thankyou for Voting!");
            } else if ("no".equals(e.getActionCommand())) {
                l2.setText("1");
                b2.setEnabled(false);
                b1.setEnabled(false);
         * Creates the GUI that the user will interact with.
         * the first block sets up the window
         * the second block adds a new content pane
         * the third block sets the frame to visible, and packs the frame.
        private static void createAndShowGUI() {
             //block 1
            JFrame frame = new JFrame("ButtonDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //block 2
            Main newContentPane = new Main();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            //block 3
            frame.pack();
            frame.setVisible(true);
        public class main extends Applet {
              * This runs everything, this is the MAIN method
              * here is where you add you're "Create And Show GUI" method to run the GUI.
                public void run() {
                    createAndShowGUI(); //Create And Show GUI Method
        }

    I'd suggest:
    Move createAndShowGUI into the "main" class. Rename the method "main" with the argument list "String[] argv", that is, make it a real main method.
    Rename the "main" class AppWrapper. That's what it is, and having two classes whose names differ only in case is stupid. Get rid of the run() method. It actually does nothing as it is now.
    Rename the Main class to something that expresses what it actually does.
    Move the AppWrapper to a new, top-level class. Correct indentation while you're at it.
    Decide whether you want an Applet or a JApplet. The rest of this assumes you want a JApplet.
    Stop importing Applet. Start importing JApplet.
    Write a new class called AppletWrapper. Make this class extend JApplet.
    Change your HTML to use the class AppletWrapper.
    Make your AppetWrapper instantiate the Main class (or whatever you've renamed it to), and add it to itself. You can do this in the constructor, or preferably in the init() method.
    I think that'll be sufficient.

  • APPLET CODE WITH PACKAGE

    Hello,
    I have o code in a package and I do not know how to write the html file the code parameter is not enough I think. Do I have to add package=myapplication?
    Thanks in advance
    This is my html file
    <applet code="myapplication.class" >
    </applet>

    Let's assume that your Package is named package1 and your applet class file is named applet1.
    Now you must place your applet1 in a folder package1.
    Now, the html file looks like this
    <applet code="package1.applet1" width=300 height=200>
    </applet>
    You don't need to use codebase if you are in the root directory of the package.
    Get Your Java apps rated - http://www.thejavahub.com
    Find Great Java Applets, Applications & Servlets - http://www.thejavahub.com

  • APPLET in jsp (please help)

    hi ,
    can someone tell me please how can i load an applet dynamically in my jsp
    i have some thing like this:
    <APPLET code=" SimpleApplet.class" width=800 height=500>An Applet</APPLET>
    in this case i have allways to copy the "SimpleApplet.class" to the same directory on my jsp and the redeploy.... how can i make it dynamically??
    the "SimpleApplet.class" is in the xxx.jar of my appllication....
    please any idea??
    thanx

    First thing is the applet cannot access the classes in the WEB-INF folder so all the applet classes have to be in the webroot directory.
    Change ur build script so that it will copy it in the web root directory
    Try this
    <applet code="SimpleApplet.class" archive="SimpleApplet.jar" name="SimpleApplet"
              codebase="." width=325 height=325>
    <PARAM NAME="fileName" VALUE="test">
    <PARAM NAME="basePath" VALUE="test">
    </applet>
    Review this tutorial and you should find the problem:
    http://java.sun.com/docs/books/tutorial/deployment/applet/html.html

  • Urgent help needed in two clarifictions of applet code

    Hi,
    I have an applet code where I have two buttons. Now, if button A is clicked it should pass a particular query string while if button B is clicked it should pass another particular query string.
    I would like to confirm
    1) Whether the query string passed is a valid statement(/approach) and
    2) Why there is an error in assigning qryString to qryString1.
    Thanks for any help/advise in advance.
    THE CODE:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    public class ReinApplet1 extends Applet implements ActionListener
    TextField text;
    Button button1;
    Button button2;
    TextArea taResults;
    public void init()
         button1 = new Button("A");
    button1.addActionListener(this);
    add(button1);
    button2 = new Button("B");
    button2.addActionListener(this);
    add(button2);
    taResults = new TextArea(2,30);
    add(taResults);
    // text = new TextField(20);
    // add(text);
    public void actionPerformed(ActionEvent e)
    Object obj = e.getSource();
    if(obj == button1)
    String qryString = "select name from test where letter = A";
    executeQuery();
    if(obj == button2)
    String qryString = "select name from test where letter = B";
    executeQuery();
    public void executeQuery()
    String qryString1 =qryString;
    try
    URL url=new URL("http://localhost:8080/examples/servlet/ReinServlet1");
    String qry=URLEncoder.encode("qry") + "=" +
    URLEncoder.encode(qryString1);
    URLConnection uc=url.openConnection();
    uc.setDoOutput(true);
    uc.setDoInput(true);
    uc.setUseCaches(false);
    uc.setRequestProperty("Content-type",
    "application/x-www-form-urlencoded");
    DataOutputStream dos=new DataOutputStream(uc.getOutputStream());
    dos.writeBytes(qry);
    dos.flush();
    dos.close();
    InputStreamReader in=new InputStreamReader(uc.getInputStream());
    int chr=in.read();
    while(chr != -1)
    taResults.append(String.valueOf((char) chr));
    chr = in.read();
    in.close();
    // br.close();
    catch(MalformedURLException e)
    taResults.setText(e.toString());
    catch(IOException e)
    taResults.setText(e.toString());

    String qryString = "select name from test where letter = A";
    ...this is a local variable ...local to your actionperformed method. The reason the assignment String qryString1 =qryString; doesn't work is because you have no scope to your actionperformed local variables from your executeQuery method. Either make qryString a class variable bty defining it outside any method ...ot, alternatively, pass the string into the executeQuery method.
    if(obj == button1)
      String qryString = "select name from test where letter = A";
      executeQuery(qryString);
    public void executeQuery(String query)
      String qryString1 = query;
    ...As for the sql statement, if you are going to refine the query through the letter column, you will need to pull it into the query when you select...
    ...such as: select name,letter from test where letter = B

  • Help with simple applet code

    i wanted to write a applet that would display a image,(this is my first program) i wrote the code shown below,but image space is emptly when i load it up with any browser.....i ran the code in netbeans,,, i am a novice, any piece of advice also wud be helpful.........
    <applet code="imagereadingapplet" width=500 height=500>
    <param name="img" value="kollam.gif">
    </applet>
    import java.applet.*;
    import java.awt.*;
    * @author raman
    public class imagereadingapplet extends Applet {
    * Initialization method that will be called after the applet is loaded
    * into the browser.
    Image img;
    @Override
    public void init() {
    img = getImage(getDocumentBase(),"kollam.gif");
    @Override
    public void paint(Graphics g){
    g.drawImage(img,0,0,this);
    // TODO overwrite start(), stop() and destroy() methods
    }

    Hi,
    First advice imagereadingapplet -> ImageReadingApplet (Java name convention).
    Second image file name is hard coded so you don't have to set param for the applet (Best would be not to hard code this name).
    Finally maybe the most interesting, It seems that image kollam.gif is not at root folder.
    I don't really know netbeans but your image must be in bin folder, the same as imagereadingapplet.class.

  • Spliting GUI code to multiple classes

    Hi All...
    I am trying to design a large scale GUI, and after reading several MVC articles I still have some question on writing the GUI code.
    for flexability I split the code to classes:
    1) How can I notify on event(exp: actionPerformed), to other widgets located in separated classes which not visible(I attached a code describing this issue, every class would be in separated class)
    Note
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    class BaseComp1 implements ActionListener{
        JButton button1;
        public void actionPerformed(ActionEvent e){
            // notify DrawingArea instance, an action performed
    class BaseComp2 implements ActionListener{
        JButton button2;
        public void actionPerformed(ActionEvent e){
            // notify DrawingArea instance, an action performed
    public class MainComp{ 
        BaseComp1 base1 ;
        BaseComp2 base2;
        public MainComp(){
            base1 = new BaseComp1();
            base2 = new BaseComp2();
    public class drawingArea{
        public void drawStuff(){  // draw stuff when actionPerform in one of BaseComp* instance
    public class GUI{
        drawingArea drawing;
        MainComp mainComp;
        public GUI(){       // need to connect BaseComp* instances in MainComp instance to
                            // notify drawingArea on actionPerform event
            drawing = new drawingArea();
            mainComp = new MainComp();
    }2) If a solution is available but not recommended, is the preferred coding design for large GUI is to write all of it in the same class ?? any suggestion will excepted joyfully..
    I would like to thanks in advance for any help
    Best Regards
    YyYo
    Edited by: YyYo on May 25, 2010 12:35 PM
    Edited by: YyYo on May 25, 2010 12:36 PM

    First of all, I think your code would improve if you don't have GUI classes implement Action or control interfaces. You may wish to have your controls in separate classes.

  • Help With Multiple Class Objects With Methods

    I am dealing with multiple classes. I am wondering why I am getting an error on this line it's by the bottom
              obj1.array() = newArray[i];
    It gives the array out of bounds. On another note I believe I can change obj1 to just like incomingArray if I wanted correct since it's just a reference because I should be able to do this method sort on any array.
    method : selSort
    input - none
    output - void
    This is where we sort the arary
    Pseudocode Code:
    1 Initialize variable oldlocation to hold spot of smallest number in original array
    2 Initialize variable smallnumber to store smallest number in original array
    3 Initialize new integer array
    4 Set new array length to length of original array
    5 Initialize variable length to store lengh of new array
    6 For i = 0 and continue till i < new array length
    6.1 Find smallest number in original array
    6.2 Put the smallest number in new array
    6.3 Remove smallest number from original array
    7 Copy contents of new array that is sorted to original array
    Basic concept is to repetitively find the smallest
    (or largest) item in the original array. Once smallest
    is found, move it to the next spot in a new array and
    remove it from the old array.
    public void selSort ()
         int oldlocation = 0;
         int smallnumber = 0;
         int [] newArray = obj1.array();
         newArray = new int [obj1.length()];
         int length = newArray.length;
         for (int i = 0; i < newArray.length; i++)
    //          System.out.println("Test 1");
              newArray[i] = obj1.sortSmall();
    //          System.out.println("Test 2");
              smallnumber = obj1.sortSmall();
    //          System.out.println("This is the smallest number " + smallnumber);
              oldlocation = obj1.location(smallnumber);
    //          System.out.println("This is the old location " + oldlocation);
    //          System.out.println("Test 3");
              obj1.removeLocation(oldlocation);
    //          System.out.println("Test 4");
         System.out.println();
         System.out.println("The sorted array looks like");
         for (int k = 0; k < newArray.length; k++)
              System.out.print(newArray[k] + " ");
         System.out.println();
         System.out.println();
         obj1.resize(newArray.length);
         for (int i = 0; i < newArray.length; i++)
              obj1.array()[i] = newArray[i];
         return;

    method : selSort
    input - none
    output - void
    This is where we sort the arary
    Pseudocode Code:
    1 Initialize variable oldlocation to hold spot of smallest number in original array
    2 Initialize variable smallnumber to store smallest number in original array
    3 Initialize new integer array
    4 Set new array length to length of original array
    5 Initialize variable length to store lengh of new array
    6 For i = 0 and continue till i < new array length
    6.1 Find smallest number in original array
    6.2 Put the smallest number in new array
    6.3 Remove smallest number from original array
    7 Copy contents of new array that is sorted to original array
    Basic concept is to repetitively find the smallest
    (or largest) item in the original array. Once smallest
    is found, move it to the next spot in a new array and
    remove it from the old array.
    public void selSort ()
         int oldlocation = 0;
         int smallnumber = 0;
         int [] newArray = obj1.array();
         newArray = new int [obj1.length()];
         int length = newArray.length;
         for (int i = 0; i < newArray.length; i++)
    //          System.out.println("Test 1");
              newArray[i] = obj1.sortSmall();
    //          System.out.println("Test 2");
              smallnumber = obj1.sortSmall();
    //          System.out.println("This is the smallest number " + smallnumber);
              oldlocation = obj1.location(smallnumber);
    //          System.out.println("This is the old location " + oldlocation);
    //          System.out.println("Test 3");
              obj1.removeLocation(oldlocation);
    //          System.out.println("Test 4");
         System.out.println();
         System.out.println("The sorted array looks like");
         for (int k = 0; k < newArray.length; k++)
              System.out.print(newArray[k] + " ");
         System.out.println();
         System.out.println();
         obj1.resize(newArray.length);
         for (int i = 0; i < newArray.length; i++)
              obj1.array() = newArray[i];
         return;

  • Help with graph applet code

    I cant figure out how to finsih this... I am creating an applet that draws a quadratic equation according to the parameters in the html file...
    Here is the first class... I think its ok:
    import java.awt.*;
    import java.applet.*;
    public class Graph extends Applet
         public void init()
             int in1 = Integer.parseInt(getParameter("a"));
             int in2 = Integer.parseInt(getParameter("b"));
             int in3 = Integer.parseInt(getParameter("c"));
              int a=1;
              int b=1;
              int c=1;
              if( in1!=0)
                                                 a=in1;
              if( in2!=0)
                 b=in2;
              if( in3!=0)
                 c=in3;
              Dimension size = getSize();
              int width = size.width;
              String msg = "Quadratic Equation: y = ax^2 + bx + c";
              Label bottom = new Label(msg);
              Label header = new Label("Quadratic Equation");
              setLayout(new BorderLayout());
              GraphCanvas canvas = new GraphCanvas(width,a,b,c);
              add(header,BorderLayout.NORTH);
              add(canvas,BorderLayout.CENTER);
              add(bottom,BorderLayout.SOUTH);
    }and here is the GraphCanvas class... which I can't figure out how to finish. hints and help would be appriciated:
    import java.awt.*;
    import java.applet.*;
    public class GraphCanvas extends Canvas
         private double density;
         private final int XMAX = 10;
         private final int XMIN = -10;
        private final int YMAX = 10;
         private final int YMIN = -10;
         private double x;
         private double y;
         public GraphCanvas(int dimension, double a, double b, double c)
             dimension = 20;
              density=dimension/(XMAX-XMIN)
              y=a*x^2+b*x+c;
         public void paint(Graphics g)
              drawGrid(g);
              graphQuadratic(g);
         public void drawGrid(Graphics g)
         public void graphQuadratic(Graphics g)
              for (x=-10;x<=10;x+=0.02)
                   y=x^2+x+1;
                   moveTo(x,y);
                   drawTo(g,x,y);
         public void moveto(double x, double y)
         public void drawto(double x, double y, Graphics g)
    }it;s mainly the drawTo and moveTo methods that i am haveing trouble getting my tired mind wrapped around.

    You may want to test the equation first, then save a "y-offset" value. Otherwise the images you draw may be off the canvas. Do this before drawing the scales (which I presume would appear in your drawGrid method), I'd suggest. Also use the offset when drawing the curve itself.
    it;s mainly the drawTo and moveTo methods that i am haveing trouble getting my tired mind
    wrapped around.Well, you're the one that wants to use them. What do you expect them to do?

  • Need Applet code - pleae help

    Hi all, I'm relatively new to the Java applets technology and i apologise in advance if I am posting this in the wrong forum.
    I am trying to develop a applet base utility to perform database backups etc , to run within our network.
    I am looking for a applet code with following functionalities.
    1 - show unix directory to choose for backup
    2 - create script and run database commands.
    Please send this code to me, or point me to the url from where I can download, I have tried everywhere I could not find.
    Thanks in advance.
    my email [email protected]

    I would recomend that you first look into Servlets, I think this would a better solution.
    Check this link:
    http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets.html

Maybe you are looking for