Problem doing Applet exercise

In my (swedish) course literature I am currently supposed to write an Applet that follows the actions of the window when it is resized . The point is to learn ComponentListener and making it runnable to avoid flickering.
the applet is supposed to look like a red rectangle with a white cross.
This is the script so far:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends Applet implements ComponentListener{
    int left = 10, top = 10, rutbredd, ruth?jd;
    public void init(){
        Dimension appletsize = getSize();
        rutbredd = appletsize.width-20;
        ruth?jd = appletsize.height-20;
        addComponentListener( this);
    public void paint( Graphics g){
        Color col = new Color (255,0,0);
        g.setColor(col);
        g.fillRect(left,top,rutbredd,ruth?jd);
        g.setColor( Color.white);
        g.drawLine(left, top, left+rutbredd,top+rutbredd);
        g.drawLine(left+rutbredd,top,left, top+ruth?jd);
    public void componentResized( ComponentEvent e){
        Dimension appletsize =  getSize();
        if(rutbredd>appletsize.width-20){
            rutbredd=appletsize.width-20;
        if(rutbredd<appletsize.width-20){
            rutbredd=appletsize.width-20;
}My mission is to make it runnable by adding 'Runnable' after 'implements ComponentListener' on the class-line and add these methods to the code:
    public void start(){
        Thread tr?d = new Thread( this);
        tr?d.start();
    public void run (){
        int fartbredd = -1, farth?jd = -1; // growth speed
        while(true){
            rutbredd += fartbredd;
            ruth?jd += farth?jd;
            Dimension appletSize= getSize();
            if(rutbredd <1){
                fartbredd=1;
            if(rutbredd >appletSize.width){
                fartbredd= -1;
            if(ruth?jd<1){
                farth?jd=1;
            if(ruth?jd>appletSize.height){
                farth?jd= -1;
            repaint();
            try { Thread.sleep(10);
            }catch( InterruptedException ie) {}
        }It does not say where to put these methods so I figured that perhaps I could put them just after the ones in script #1. Netbeans however gives an error message and Applet Viewer does not show any output at all.. (I get the usual 'Start: applet not intialized'). Does this work for anyone else?
By the way, after copy-pasting it to another editor and back netbeans gives an error message on the first (originally working) script. This worked before I copied it to and back from another programming editor (bluefish). perhaps it is just netbeans not woking when moving stuff around too much?
I have been trying to solve this for two hours. please help me put this script together!
Thanks in advance.

uj2n wrote:
gives an error messageI'm sorry but I skipped the mind reading class at school. Perhaps you can share the error message(s) with us.

Similar Messages

  • Problem calling applet method using IE

    I've searched through the forum and can't seem to find anything that can help me fix this. I'm trying to call an applet's method using Javascript. This is working fine under Netscape, but not IE. Everything I've read seems to indicate that I'm doing this right, but I'm getting "Object doesn't support this property or method" when I try to call the applet method from IE.
    In this example method, I'm trying to call the applet's countChars method, which should return the length of the string you pass into it. Works under Netscape 6.2, but not IE 6.0
    Here's my applet code:
    import java.lang.String;
    public class test extends java.applet.Applet {
    public static int countChars(String s) {
    return s.length();
    And my HTML
    <HTML>
    <HEAD>
    <script language="Javascript">
    function refreshApplet()
    /*     i = document.forms.myForm.TestApplet.countChars();
         document.forms.myForm.output.value=i; */
         document.forms.myForm.output.value=document.applets["TestApplet"].countChars(document.forms.myForm.input.value);
    </script>
    </HEAD>
    <BODY>
    <APPLET CODE = "test.class" WIDTH = 400 HEIGHT = 400 ALIGN = middle NAME = "TestApplet" scriptable="true">
    </APPLET>
    <br>
    <form name="myForm">
    <input type="text" name="input">
    <input type="button" value="click me" onClick="refreshApplet();">
    <hr>
    <input type="text" name="output">
    </form>
    </BODY>
    </HTML>
    Thanks in advance!
    Craig Drabik
    Sr. Programmer/Analyst
    University at Buffalo

    I have very similar problem, my applet works OK using Netscape (6.2 and 7.0), but with IE 6.0 It only works with windows XP;
    The reported error is "Object doesn't support this property or method"
    Can someone please help me to solve this problem.
    Cheers
    Horus
    This is my code:
    - I call the applet using javaScript and input the method setData with two strings.
    function graphic()
         var dataZenith;
         var dataManual;
         initVariables();
         dataZenith = graphicZENith(); //Call other Javascript functions
         dataManual = graphicManual(); //Call other Javascript functions
         document.AppletOne.setData(dataZenith,dataManual);
    I run the applet with this HTML code:
    <applet NAME="AppletOne" code="Appl.class" width="450" height="450"
    MAYSCRIPT></applet>
    //Applet code/////////////
    import java.awt.*;
    import java.awt.geom.*;
    import java.applet.*;
    import java.util.*;
    public class Appl extends Applet {
         private int [] myArray1 = new int [156];     
         private int [] myArray2 = new int [156];
         private boolean flag = false;
         // maxDataYAxesNumber es usado para dividir el eje de las Y
    public void init()
              setFont(new Font("SansSerif", Font.BOLD, 12));
              setBackground (Color.white);
              setSize(getSize());     
    // Get data and put in an array
    public void setData(String data1, String data2)
              final String DELIMITER = ",";
              final StringTokenizer theTokens1 =
                   new StringTokenizer(data1, DELIMITER);     
              final StringTokenizer theTokens2 =
                   new StringTokenizer(data2, DELIMITER);
              try
                        String dataX = data1;
                        for (int i = 0; i < 156; i++)
                        myArray1[i] = Integer.parseInt(theTokens1.nextToken().trim());
                        myArray2[i] = Integer.parseInt(theTokens2.nextToken().trim());
              catch (NumberFormatException e) {};
              flag = true; //I get the data OK
              repaint();
    public void paint (Graphics g){
    Graphics2D g2d = (Graphics2D)g;
    setData(data1, data2) ;
    if (flag == true)
                   //Call other functions to process the graphic
    else g2d.drawString(" Sorry I can get Data", 100,80);          

  • Problem downloading applet in W2K with SP4.

    Hi,
    We are using a Security Applet in our web application for validation purposes. We were using W2K Professional / W2K Server with SP3 and Sun JRE 1.3.x. The application was working as expected.
    We are now testing with W2K Server with SP4 (to upgrade to SP4). The current testing environment is W2K Server with SP4 and Sun JRE1.3.x. Now with the setup, we are facing a problem in downloading the applet (Security Applet). The downloading applet fails and the subsequent loading as well.
    Please advice. Does it requires any particular settings to be done at Client?
    The specs are
    Windows 2000 Server, SP4
    IE 6 SP1
    Sun Jre 1.3.x
    Problem:Downloading applet fails.
    PS: When we test with SP3, we can see the applet downloaded (CAB File), with SP4 it was not found.
    Thanks in Advance,
    Prakash

    Does the w2k sp4 server host your pages and applet?
    If yes then why install the SUN JRE 1.3 on the server, doesn't the client need this?
    Is the cab format supported by SUN jre or is it meant for msjvm and if so why is the client trying to open
    the cab with sun jre?
    http://java.sun.com/j2se/1.4.2/docs/guide/deployment/deployment-guide/upgrade-guide/article-02.html
    What's on the server doesn't have anything to do with the applet. The server is
    just serving it. Forcing the client/consumer of the html page with the applet is trying to open an applet
    with sun jre while the applet is ment for msjvm causes the error.
    The client can fix this by opening IE and check under tools -> internet options -> advanced -> UNCHECK
    the use sun jre ... for <applet tag. For the XP machine you might have a problem. Some of the don't have
    the msjvm at all so there is nothing to run the <applet, I tried to download it at microsoft but was unable
    to find it.

  • Problem in Applet while communicating with Javascript

    Hi,
    I’m facing a problem with applet. Applet calls JavaScript methods and vice versa. Applet works fine with JRE 5 to JRE 6 up to build no 1.6.0._7 but it fails with build no 1.6.0_10.
    The problem description is given below:
    After embedding applet in my HTML page using <OBJECT> tag, I’ve to check either any problem during applet’s execution, I want to get the error reason by calling my defined method getErrorReason() in applet that returns the error reason, I call the getErrorReason() against the applet’s object in JavaScript immediately after embed applet code in my HTML page, a JavaScript errors occurs and my applet fails to perform its execution.
    JavaScript error: Object does not support this property.
    The error points to the HTML page area where I’m calling getErrorReason() against applet object.
    The above JavaScript error occurs after the successful completion of Applet’s init(). I’m facing this problem only in JRE 6 build 1.6.0_10-b33.
    Please suggest me any solution.
    Thanks in advance.
    Regards,
    Israr Ahmed

    Hi Bharath,
    Even i got similar error and i tried deleting the below(Attaching the stack trace is always better way.)
    1) delete the folder ‘workspace’ or rename(including all files and subfolders) in the path D:\Documents and Settings\lzcr8r\Documents\SAP\workspace
    2) delete all .dtr/.dtc/.metadata directories in your personal folder (e.g. C:\Documents and Settings\lzcr8r).
    Restart the IDE once you are done with the above steps.
    Second part to increase the virtual mem
    1) RtClick on the Shortcut of NWDS -->Properties and in the Target put the below
    "C:\Program Files\SAP\IDE\IDE70\eclipse\SapIde.exe" -vmargs -Xms512m -Xmx1536m  "C:\j2sdk1.4.2_08\bin\javaw.exe"
    2) You can also try  Creating a bat file with the complete path of your IDE and start your ide from the bat
       content in the bat eg: "C:\Program Files\netbeans-4.1\bin\netbeans.exe" -vmargs -Xms512m -Xmx1536m
    Here -Xms512m is the min JVM size and -Xmx1024m is the max JVM size.
    You can place this batch file anywhere and double click the batch file.
    It will automatically start your IDE
    3) if you are using Tomcat you can try creating an env variable and assign Value
    Variable Name:  CATALINA_OPTS
    Variable Value:  -server -Xmx800m
    please award points if usefull.
    Regards
    Souza
    Edited by: Souza Aluri on Apr 9, 2008 9:46 AM

  • HT5429 How long after you report a problem does it take for the fix to be picked up in maps?

    How long after you report a problem does it take for the fix to be picked up in maps? The street I live on is misspelled. It's shown as one word, but it should be two words. Maps cannot find the address when it is spelled correctly, so I have it purposely misspelled it as one word in my contacts, which helps for the most part, however it still tries to place my home on an entirely different street all together. Fortunately this new random street is at least close to where I live. When I used to spell my street correctly with two words, maps would try to send me to the next town over. So it kind of works, as long as I misspell my street, and ignore the fact that it is showing where I live to be a couple of streets down from where I actually live. I live in Connecticut - not in the most populated of areas, but not in the middle of nowhere either. Amazingly enough Google Maps will correctly find my address whether it's spelled with one words or two words. Google Maps also shows my apartment complex, which Apple Maps does not. I really wish Apple would just do a quick pass of the area to fix these issues. I’ve reported the problem several times, months ago. How long will it take for there to be a fix? I keep trying to use the Apple ecosystem, but Google is clearly the better solution for me.

    Apple does not do the GIS data for maps. That comes from 3rd party vendors like Tom Tom. I have read it takes some time to update map data. The only thing you can do is report it.
    Not to belittle your complaint, but on my end it is Apple that is clearly better. When looking at my house in Google, the satellite photo is more than 4 years old, and the Apple one is much newer. I can tell because of the condition of my home and the neighbor's. They had an above ground pool which was removed 4 years ago and it shows on the Google Map. I had remodeling and roof work done to my home that started 3 years ago and Apple's satellite view showed this work done, which took over a year to complete. I live in the middle of a block in a rural town. Both Apple and Google split the block into 100 parts and put my home close to the beginning of the block instead of where it actually sits. I've reported it to both Google and Apple and no one has changed. Just one of those things. But, keep your chin up, it will get corrected eventually.

  • How does one update Flash? I currently cannot watch videos on You Tube, it says I need to upgrade, I have no problem doing this on a PC.

    How does one update Flash? I currently cannot watch videos on You Tube, it says I need to upgrade, I have no problem doing this on a PC.

    If you're not using chrome you can just go to adobe's website (http://get.adobe.com/flashplayer/) and download the newest flash player.  You run the .dmg and then open the application, which updates flash.  With the latest version of flash there should be a preference pane within system preferences to allow you to change settings and check for updates.

  • When I enable imatch on my iPhone 4s it takes approximately 30 minutes before other data fills 13.2gb of usable data. This problem does not occur when I manually sync music to my phone. Is this a common bug, and if so; is there a fix?

    When I enable imatch on my iPhone 4s it takes approximately 30 minutes before other data fills 13.2gb of usable data on the phone. This problem does not occur when I manually sync music to my phone only when I access imatch. Is this a common bug, and if so; is there a fix?

    yes it is. you can sign out of itunes account then sign back in. use http://support.apple.com/kb/ht1311 to sign out.

  • I have a 17" Macbook pro with flickering red and cyan(blue) lines across the screen. The issue disappears temporarily when I tap on the computer, and the problem does not occur when I use external display or try to screen capture the problem.

    I purchased my Macbook (17") through a certified apple tecnition in August 2012, it was refurbished and the motherboard was completely replaced. I do a lot of photo editing, but I have been unable to do so because of the red vibrating lines that interrupt my screen. The issue disappears temporarily when I tap on the computer, and the problem does not occur when I use external display or try to screen capture the problem. I brought the computer back to the technition I purchased it from and he said that it was a problem with my fan, so I have two new fans but the issue is still occuring. He says he doesnt know whats wrong. Does anyone have any information on this issue?
    Here is an image of the issue
    http://www.flickr.com/photos/67839707@N08/8884847081/

    I recommend having your Mac serviced by someone competent. A force sufficient to "blow apart" the fans was clearly excessive and may have damaged the display cable, as well as any number of other problems.
    Dust is properly cleaned with a vacuum, preferably one designed for computer service, and they are not cheap.
    Compressed air should never be used. It just blows dust everywhere, often into places where it can no longer be removed.

  • Caching problem in Applets - Java Control Panel

    I have a problem of applets being cached in Java Control Panel. Is there a way in Java to stop caching applets programatically in the Java Control Panel.
    There is one way to stop caching files by unchecking "Keep Temporary Files on my Computer" under Java Control Panel --> General --> Settings page.
    But I want to do this programatically using some Java programming/Java Scripting/some parameter in applet tag.
    Some solutions like setting cache_option = No, cache_archive= jar file name in PARAM tag in applet and classloader_cache="false" have been already tried. But noting is seeming to be working out.
    Can somebody please provide a solution.

    Following is the listener status
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ
    ction
    Start Date 11-APR-2007 11:51:12
    Uptime 0 days 0 hr. 1 min. 28 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Listener Parameter File I:\oracle\product\10.2.0\db_1\network\admin\listener.o
    ra
    Listener Log File I:\oracle\product\10.2.0\db_1\network\log\listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jbpsouthcbg)(PORT=1521)))
    Services Summary...
    Service "jbpsouth" has 2 instance(s).
    Instance "jbpsouth", status UNKNOWN, has 2 handler(s) for this service...
    Instance "jbpsouth", status READY, has 2 handler(s) for this service...
    Service "jbpsouth_XPT" has 1 instance(s).
    Instance "jbpsouth", status READY, has 2 handler(s) for this service...
    The command completed successfully

  • On my new iMac, mail has no sound after waking from sleep.  If I select do not wake for network access in general preferences, the problem does not occur.  Anyone have an idea on how to fix this?

    On my new iMac, mail has no sound after waking from sleep.  If I select do not wake for network access in general preferences, the problem does not occur.  Anyone have an idea on how to fix this? Thanks --

    Same here on an older iMac since Lion. Thanks for the uncheck wake for network access tip though, it doesn't do it either in that case, I will leave it that way.

  • Problem doing a chart

    hi!
    I have a problem doing a chart, I have three columns: I have dimension department in X Axis and I have two measure columns.
    I have a view selector with each measure so...I have two charts. My problem is that I have to apply a filter and I need to show only departments that has a value more than 0. How can I apply this filter?
    If I apply a filter in answers two charts has the same departments and isn't true because each measure has different departments...
    Can you help me??
    Thanks!!!

    Hello!
    I know this type of filter.
    In my fx formula I have this code:
    FILTER(IFNULL("- Actual".Value, 0) USING ("Dim Concept".Concept = 'Number of Ships'))
    Then I have another column (Department) and I have to do a chart.
    I want to see only departments that has my first column > 0, but I have to apply this filter inside of my column because I have another columns with another concept...
    I mean, If I choose on my view selector Measure 1 I can see for example: 10 departments on X AXIS of my chart and If I choose Measure 2 in my view selector...I should see for example only 7 because another has 0 value...
    Is possible to get this???
    Thanks!!

  • I just downloaded the new itunes update, now I can't copying TV shows purchased from the library to my backup computer, it says the files are invisible. Never had any problem doing it until the update.

    I just downloaded the new itunes update, now I can't copying TV shows purchased from the library to my backup computer, it says the files are invisible. Never had any problem doing it until the update. I have a Mac Pro G5 OS 10.6.8. The desktop hidden files app doesn't reveal the TV shows.

    found a solution in a different discussion.. thank god.

  • Problem doing SFTP through ISDN

    Hi,
    I have a problem doing SFTP through ISDN, ISDN connection is not staying active throughout the duration of the file transfer, it drops after its timeout value even if data transfer is in progress and file transfer break at that point, this happens with sftp transfer only, other type of connection like telnet, rdp works fine. Intresting traffic list I have define is,
    access-list 112 permit ip host 10.10.10.9 any. All the traffic is orignating from IP address 10.10.10.9
    Any suggestion on that.
    Thank you
    Yamin

    This is a fairly common issue with ISDN dialers. The disconnect may be initiated by either side of the connection.
    If you are certain that all is OK on your end, it may be the remote side that initiates the disconnect.
    regards,
    Leo

  • My mouse is unable to access the top toolbar in websites and email with Firefox - this problem does not present in Windows XP or Internet Explorer

    My mouse is unable to connect with the top toolbar of my hotmail account and any other websites I visit using Mozilla as a browser. This problem does not occur when I use Internet Explorer

    The answer was perfect! I fixed the problem following the link. When I posted the question yesterday, I was not very optomistic that anyone would reply and/or help - but, I was wrong. The solution was quick and simple.
    Thanks very much!!

  • Having problems doing an iCloud backup it keeps showing the estimated time thing but the blue load bar hasn't budged in over a half hour is there a way to correct this

    Having problems doing an iCloud backup it keeps showing the estimated time thing but the blue load bar hasn't budged in over a half hour is there a way to correct this

    You might try a forced shutdown to begin with, hold down the top and home buttons together until the device shuts down, then restart it.
    First check that your device is correctly connected to the wifi/internet (settings > wifi)
    If your back up continually fails, you might try turning off back up on your mobile device (settings > iCloud > storage & backup) and then deleting the backup file from iCloud by swiping the backup file on the mobile device (settings > iCloud > storage & backup > manage…) and then turning back up on again.
    If this doesn't help, try turning off some items for back up in a pattern to try to establish if your problem is being caused by specific data on your device.
    Being able to back up to the cloud can be very useful, especially if you don't have access to a computer or have infrequent access to one, however unless you specifically need to use iCloud for back up, you will find backing up to iTunes significantly more convenient and possibly more reliable.
    More about iCloud v iTunes Back Up

Maybe you are looking for

  • Save and Save As options are greyed out

    I have an install of Adobe X Standard. An external source is sending in PDFs which are marked as Secured. However, according to the creator of these documents, only editing has been locked down, not Save or Save As functionality. When I open the docu

  • How do i redirect wifi sync in iOs 5 to a different computer user

    how do i redcirect wifi sync to a different user on the same computer? how do I redirect wifi sync to a different computer on the same network?

  • Mass Maintenance of EDI Partner Profiles

    Hello SDN folks,   my customer is a large multinational - and they are beginning to run into difficulties in the management of their EDI partner profiles. The problem is that there are thousands of external parties that must be communicated to via ID

  • Podcast not in store

    hi, so apple has sent me a conformation letter that my podcast is indeed in the itunes store, they also gave me a link to go to view it. The link works, and my podcast shows up in the music store. But when I try to search my podcast in the music stor

  • Runtime Errors       " UNCAUGHT_EXCEPTION ...... While loading data

    Hi Gurus:  Need yoyur help to resolve the loading issue (Data Mart) Scenario:     Loading data from BW layer to BI layer - Cube to Cube loading of data.     Data loaded in DW layer cube with no issues.  However, gives the following error when loading