Anyone knows whether this method will work?

Hi,
I am trying out this method to construct an applet but I couldn't get it to work.Does anyone here know whether this method will work and how to debug it.Thanks.
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class Project extends Applet implements ActionListener {
private Button circle, square;
private Model aModelInstance;
public void init() {
circle = new Button("Circle");
add(circle);
     circle.addActionListener(this);
     square = new Button("Square");
     add(square);
     square.addActionListener(this);
aModelInstance = new Model();
public void paint(Graphics g) {
     aModelInstance.display(g);
     public void actionPerformed(ActionEvent event) {
if (event.getSource() == circle)
aModelInstance.getCircle();
if (event.getSource() == square)
aModelInstance.getSquare();
repaint();
class Model {
     private aModelInstance.display(g)
     public void getCircle() {
     g.setColor(Color.red);
g.fillOval(145,89,122,122);
private aModelInstance.display(g)
     public void getSquare() {
g.setColor(Color.green);
g.fillRect(145,89,122,122);
public void display(Graphics g) {
}

It will work for the most part put there is a few problems that you would have to work out. Most of the problems are in the inner class Model. I commented out a couple of lines in there that did not make sense. In the getSquare() & getCircle() methods you are referring to the variable 'g' where there was no declaration for that variable, in Model. So I modifed the method to have an input parameter of Graphics, that will need to be passed to the method. Then I modified the code in Project so that it passes Graphics when it calls those methods.
The code now compiles cleanly but there is still some work for you to do. You should modify the getSquare() and getCircle() methods to return the Graphics. Then in the actionPerformed() method, call the paint method with the returned Graphics. Good luck.
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class Project extends Applet implements ActionListener {
private Button circle, square;
private Model aModelInstance;
public void init() {
circle = new Button("Circle");
add(circle);
circle.addActionListener(this);
square = new Button("Square");
add(square);
square.addActionListener(this);
aModelInstance = new Model();
public void paint(Graphics g) {
aModelInstance.display(g);
public void actionPerformed(ActionEvent event) {
if (event.getSource() == circle)
aModelInstance.getCircle(this.getGraphics());
if (event.getSource() == square)
aModelInstance.getSquare(this.getGraphics());
repaint();
class Model {
//private aModelInstance.display(g)
public void getCircle(Graphics g) {
g.setColor(Color.red);
g.fillOval(145,89,122,122);
//private aModelInstance.display(g)
public void getSquare(Graphics g) {
g.setColor(Color.green);
g.fillRect(145,89,122,122);
public void display(Graphics g) {
}

Similar Messages

  • I have a Linksys 10/100 5 port workgroup switch attached to an Airport Extreme. Does anyone know if this setup will work properly?

    I have a Linksys 10/100 5 port workgroup switch attached to an Airport Extreme to expand the number of ports. Does anyone know if this setup will work properly?

    Sure - just be aware that it will limit you to 100Mb/s internal network speed. If you want to be able to transfer files internally on your network faster, look into a gigabit switch.
    Matt

  • Can any body tell whether this logic will work or not

    To calculate quantity for the  material  for  particular month
    This report is used to calculate demand plan(zzdpfc) for market 001 and 002
    eg: the opt shld be
      material number           month              quantity
    1.  1000                           02/2007              40 (market 001+002 for the same      materila and same month)
    2. 1000                          03/2007               20 (same as above)
    3. 1001                           02/2007               30 (same as above)
    i want to know whether  this pgm will work according to this requirement or not .if not please change the code accordingly .please let me know it urgent.
    REPORT  ZPRODUCT_ROLL                           .
    TableS: S507.
    DATA: BEGIN OF T_DATA OCCURS 0,
           matnr LIKE S507-matnr,
           SPMON LIKE S507-SPMON,
           ZZDPFC LIKE S507-ZZDPFC,
           ZZMARKET LIKE S507-ZZMARKET,
           END OF T_DATA.
    DATA:WA_DEMPLAN(10) TYPE C.
    data:material(18) type c.
    data : period like sy-datum..
    period =  sy-datum+0(6).
    Select    mATNR SPMON ZZDPFC ZZMARKET
    From S507
      into corresponding fields of  table  t_DATA WHERE
      VRSIO = '000' AND BEDAE = 'KSV' AND ZZDMTYP = '001'
      AND  ZZDPFC GT '0' AND ZZMARKET IN ('001','002').
    AND SPMON >= PERIOD.
       SORT T_DATA BY MATNR SPMON.
    write:/04 'Material',25 'Demand Plant', 50 'Period'.
    LOOP AT T_DATA.
    move t_data to material.
    modify t_data.
    *WRITE:/02 t_data-MATNR ,25 t_data-ZZDPFC,45 t_data-ZZMARKET,
    *70 t_data-SPMON.
    at new spmon.
    sum.
    write : /02 material color 5,25 t_data-zzdpfc COLOR 5 ,50 t_data-spmon color 5..
    endat.
    endloop.

    hi arun,
    use collect keyword in the loop, it add the quantity fields for the particular material
    or
    use control brake statement in the loop and endloop.
    regards,
    seshu.

  • Anyone know why this doesn't work?

    Hi,
    I am trying to work with layeredPane's, and I am having a bit trouble, Here is my modified code of a java tutorial:
    package org;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    * LayeredPaneDemo.java is a 1.4 application that requires
    * images/dukeWaveRed.gif.
    public class LayeredPaneDemo extends JPanel {
        private String[] layerStrings = { "Yellow (0)", "Magenta (1)",
                                          "Cyan (2)",   "Red (3)",
                                          "Green (4)" };
        private Color[] layerColors = { Color.yellow, Color.magenta,
                                        Color.cyan,   Color.red,
                                        Color.green };
         private Label[] layeredLabels = new Label[5];
        private JLayeredPane layeredPane;
        public LayeredPaneDemo()    {
            setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
            //Create and set up the layered pane.
            layeredPane = new JLayeredPane();
            layeredPane.setPreferredSize(new Dimension(300, 310));
              for (int i = 0; i < layerStrings.length; i++) {
                layeredLabels[i] = createColoredLabel(layerStrings, layerColors[i] );
         layeredLabels[i].addMouseListener(mouseListener);
         setupLayers();
    add(layeredPane);
         private MouseListener mouseListener = new MouseAdapter() {
              public void MouseClicked(MouseEvent e) {     System.err.println("clicked");
                   Label label = (Label) e.getSource();
                   label.setUp();
                   setupLayers();
                   layeredPane.validate();
                   layeredPane.repaint();
         private void setupLayers() {
    //This is the origin of the first label added.
    Point origin = new Point(10, 20);
    //This is the offset for computing the origin for the next label.
    int offset = 35;
              //Add several overlapping, colored labels to the layered pane
    //using absolute positioning/sizing.
              for(int x=0; x< layeredLabels.length; x++) {
                   Label label = layeredLabels[x];
         if(label.up) {
    origin.y += offset;
    label.setBounds(origin.x, origin.y, 100, 100);
    layeredPane.add(label, new Integer(x));
    origin.x += offset;
                   if(label.up) {
    origin.y -= offset;
    //Create and set up a colored label.
    private Label createColoredLabel(String text, Color color) {
    Label label = new Label(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);
    label.setBackground(color);
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    return label;
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("LayeredPaneDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    JComponent newContentPane = new LayeredPaneDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
         class Label extends JLabel {
              public boolean up = false;
              public Label(String text) {
                   super(text);
              public void setUp() { up = !up; }
    for some reason the mouse listener isn't responding, and i don't know why..
    Thats only part of my problem. When the mouse listener does respond, I want to only move one of the labels in the Y direction, and then re-paint everything...
    any ideas?

    public void MouseClicked(MouseEvent e) {     System.err.println("clicked");should be small m
    public void mouseClicked(MouseEvent e) {     System.err.println("clicked");                                                                                                                                                                                                                                                                                                                                                       

  • Anyone know why this program aint working

    i pretty much copied most of the code from an example program but this one doesnt seem to be working
    the error says i need another } but keeps saying the same thing when i add one
    import java.io.*;
    //this is a cprogram i have created so the users data entered into my main program can be read in a text file
    class cdetailreader
         public static void main (String args[])
              int input;
              try
                   // I have created a filereader to read the contents of the text file i created to hold customer data
                   // In my main program i named the text file to store customer details cdetails.txt
                   FileReader readcdetails = new fileReader("cdetails.txt");
                   input = reader.read();
                   While (input >=0)
                        System.out.print ((char) input);
                        input = reader.read();
              catch(Exception e){
              System.out.println("File does not exist"+e);
    }

    nice one mate it is actually a error in the program
    example but should have guessed. thanks for helpI suggest you ditch that source and find another one that doesn't suck.

  • I just purchased the Apple MB974ZM/B World Travel Adapter Kit for my iphone 5. It says it works for the 4.  Does anyone know if this will work for my iphone 5?

    I just purchased the Apple MB974ZM/B World Travel Adapter Kit for my iphone 5. It says it works for the 4.  Does anyone know if this will work for my iphone 5?

    here is the link to Apples compatibility guide for it.
    http://store.apple.com/us/product/MB974ZM/B/apple-world-travel-adapter-kit

  • I'm trying to connect my iPad to my Samsung galaxy s by bluetooth but the ipad will pair with it but not connect and says "its not supported" does anyone know what this means and how I get it to work?

    I'm trying to connect my iPad to my Samsung galaxy s by bluetooth but the ipad will pair with it but not connect and says "its not supported" does anyone know what this means and how I get it to work?

    iOS devices do not have the BT profiles that support file sharing and othr general functions. See:
    iOS: Supported Bluetooth profiles
    Basically it support headphones, keyboards, speakers, peer-to-peer gaming

  • My iPod's headphone jack isn't working anymore, when i put my headphones in , the left l, My iPod's headphone jack isn't working anymore, when i put my headphones in , the left earphone doesn't work. Does anyone know if this can be fixed ?

    My iPod nano 3rd generation headphone jack isn't working anymore, when i put my headphones in , the left earphone doesn't work. Does anyone know if this can be fixed ?

    Hi Mr.Acevedo329!
    I have an article here for you that can help you troubleshoot the issues you are experiencing. That article can be found right here:
    iPod troubleshooting basics and service FAQ
    http://support.apple.com/kb/ts1382
    Specifically, you will want to take note of this section:
    The headphones don't work
    If your iPod's headphones don't work or have static or garbled audio, try connecting them to any other 3.5 mm stereo headphone jack, like the one on your computer. If the issue with the headphones persists, replace them. For an iPod under warranty, you can order a replacement online. Otherwise, check out the cool headphones at the Apple Online Store. If the issue appears to be with the iPod, try resetting it. If that doesn't work, then restore iPod with the latest iPod software using iTunes 7 or later.
    Thanks for using the Apple Support Communities. Have a good one!
    -Braden

  • TS2776 I used my Ipod while at the gym one day and now it's acting wacky.  I have tunes that will not download due to an "unexpected error (-50).  Anyone know what this is and how to fix it?

    I used my Ipod while at the gym one day and now it's acting wacky.  I have tunes that will not download due to an "unexpected error (-50).  Anyone know what this is and how to fix it?

    looks like the gtk theme is not the problem. didnt really think it was, but the documentation was worth posting. the guys over at ubuntu look as though they have dealt with this in great detail, and have produced a few solutions, which may or may not work. i have decided to post these for anyone else who may have these problems.
    Solution 1 - new user creation:
    https://bugs.launchpad.net/ubuntu/+bug/104521
    Solution 2 - config file delete:
    http://ge.ubuntuforums.com/showthread.php?t=724439
    post number 6 here features the config file delete solution, as well as a link to another post which may be useful.
    judging by a google search on this problem and the number of responses that came up, the bonobo/daemon error is quite a common curse for the users of gnome, although much more common in distros such as ubuntu or fedora.
    i hope that this proves useful and if anyone has anything to add, please feel free. the more documentation the better.
    EDIT:
    another solution would be to remove gnome and reinstall it from scratch. (some please tell me if i am doing this correctly. thanks )
    1. clean your catch:
    pacman -Scc
    2. remove gnome, gnome extras, and whatever other gnome files you might have installed
    pacman -Rscn gnome gnome-extra etc...
    3. reinstall gnome and gnome extras
    pacman -Sy gnome gnome-extra
    4. reconfigure your desktop the way you want.
    Last edited by czechman86 (2008-05-28 23:42:43)

  • I would like to install snow leopard instead of lion on latest macbook pro MD318 (oct.2011) Does anyone know if this is possible? If so, will I have to use install-disks of previous model (eg. MC721) or will retail-disks serve?

    Experiencing serious problems with lion, I would like to install snow leopard instead of lion on latest macbook pro MD318 (oct.2011) Does anyone know if this is possible? If so, please tell me how. Will I have to use install-disks of previous model (eg. MC721) ? Or will retail-disks serve?
    Thanks steph

    Snow Leopard is currently running on this MBP 15", late 2011 model, due to my need to run an old version of FileMaker.
    A retail disk with 10.6.3 did not work, I restored my previous Snow Leopard install with Disk Utility.
    However, it is not the shipped software and is not officially supported on this Mac. Therefore, your advice to troubleshoot Lion is the best option.

  • In app purchase is not working in testing environment in sandbox for the past 5 days. Please anyone know about this issue.

    in app purchase is not working in testing environment in sandbox for the past 5 days. Please anyone know about this issue.
    What i did
      1 . Added three products more to the existing in-app
      2 . Tested with sanbox
    i am getting the error "cannot connect to itunes store" with error code "0" when trying to purchase product in sandbox.
    Is sandbox is down?Please help guys..

    Apple's sandbox has been down practically all month. You can check the status here:
    http://sandbox.itunes.apple.com

  • I need to change my apple ID because I'm changing my email address. I'm worried that when I do, I'll no longer be able to use my first generation apple tv unless I change the apple ID there as well.  Does anyone know how this works??

    I have to change my apple ID because I'm changing my email address. (I have a Comcast address and am switching to U-verse) I'm worried that when I do, I'll no longer be able to use my first generation apple tv unless I change the apple ID there as well. I'm also trying to find out if changing my apple ID is going to interfere with getting my itunes content on my computer and my iphone.  Does anyone know how this works??

    My iTunes appleID is an old defunct e-mail address - it does not have to be functional.
    Do what Winston says to ensure you keep getting correspondence related to that ID.
    AC

  • Does anyone know what this error code means?My itunes will not open, no matter how many times i downlaod and restore it??? "The procedure entry point xmlITexTextReaderName could not be located in the dynamic link library libxml2.dlll."

    Does anyone know what this error code means?My itunes will not even open, no matter how many times i downlaod and restore it??? "The procedure entry point xmlITexTextReaderName could not be located in the dynamic link library libxml2.dlll." Please let me know if your know anything! It is greatly apprecitated!

    Taken at face value, you're having trouble with an Apple Application Support program file there. (Apple Application Support is where single copies of program files used by multiple different Apple programs are kept.)
    Let's try something relatively simple first. Restart the PC. Head into your Add or Remove Programs control panel, select "Apple Application Support", click "Change" and then click "Repair".
    If no joy after that, try the more rigorous uninstall/reinstall procedure from the following post. (Although the procedure is for Vista and 7 and you've got XP, just read "Computer" as "My Computer", read "Uninstall a program control panel" as "Add or Remove programs control panel" and assume the system is 32-bit, and you'll be doing the right things.)
    Re: I recently updated to vista service pack 2 and I updated to itunes 10.2.1 and ever since I did that my itunes won't open any more.  Itunes starts but before anything loads a

  • My ipod nano this morning has started to tell me the accessory (lightening to 30-pin adaptor) I use for playing it through my docking station is not supported. It worked fine up until last night. Does anyone know why this might be?

    My ipod nano this morning has started to tell me the accessory (lightening to 30-pin adaptor) I use for playing it through my docking station is not supported. It worked fine up until last night. Does anyone know why this might be?

    Clean any debris from the adapter, docking station connector and the connector on the Nano.

  • HT1848 My iPod will not transfer songs because of an unknown error (-50). Does anyone know what this means?

    My iPod will not transfer songs because of an unknown error (-50). Does anyone know what this means?

    Use search to find out what the error is.

Maybe you are looking for

  • Synchronisation dosen´t work

    Hello... I´ve installed the new PC-Suite 6.82.22.0 for the Nokia 6230. Everything works fine (sendig file etc.) but the synchronisation of the calender and contacts doesn´t work. The PC-Suite knows the phone via Bluetooth or USB but after two seconds

  • Extrnal drive in after a shutdown and it came up a different letter. Now Lightroom does not recognize any of my photos..

    I plugged  my external drive in after removing it to clean the computer. HP PC. When I plugged the external drive in again the drive letter changed and Lightroom could not find any of my photos 11,000 or so of them. I have tried the usual recommendat

  • Document Distribution Log Status

    HI All, In CVI9 I can set a document distribution status to Ignore but I cannot find anywhere in the log that it records who set that status and when.  Does anyone know if there is a background table where this information is stored so I can write a

  • Flex Chart Problems, can anyone help?

    I get the following run time error when my mouse rolls over one of my charts: ReferenceError: Error #1069: Property hitData not found on mx.charts.HitData and there is no default value. at Chart1/::formatDataTip() at mx.charts.chartClasses::ChartBase

  • Security parameters in the kernel do not meet the minimum requirements

    Hello, I am installing Oracle AS Infrastructure. My overall system checkup was fine but of kernel has following message. checking for hardnofiles = 65536 found hardnofiles = 1024 Failed checking for softnofiles = 4096; softnofiles = 1024 Problem: The