JMenu and Paint Problem

Hello,
I have been teaching my self Java and I have become quite proficient with it, however, I have a problem that I can not fix, or get around.
I have a JMenuBar in a JFrame with some JMenu�s containing JMenuItems. I also have a JPanel that I draw inside (I Know that is probably not the wisest way to draw things, but it was the way I first learned to draw and now my program is too big and it is not worth while to change). Any ways, I draw some graphics inside of this JPanel.
The menu items change the drawings; this is done by repainting the JPanel Graphic. However, when I click one of the menu items, the JPanel paints but there is a residual of the JMenu in the background that will not disappear.
The menu is closed and if I open and then close the menu the residual goes away.
=> I would like to know how to prevent the residual from appearing?
The problem also occurs when I use the popup menus outside of the JmenuBar.
What I think is wrong.
I think my problem is with the repaint. I don�t think the JFrame is repainting. I think I am simply repainting all the components in the JFrame but not the JFrame itself and thus the residual is not cleared from the JFrame. I don�t know how to fix this but I believe that is the problem because when I minimize the JFrame then Maximize it the JFrame will not paint, and I can see right through the JFrame, but the components paint fine.
Sorry for the long question, but I don�t know what would be helpful.
Any advice would be appreciated,
Thank you
Seraj

// This is the code that listens for the menu item
private void RBmmActionPerformed(java.awt.event.ActionEvent evt) {                                    
        calc.setIN(false);
        updateData();                    // updates some data
        paint2();                           // my special draw fuction shown below
    public void paint2()                          // this the special paint that draws on the JPanel
        Graphics page = jPanel1.getGraphics();
        if(start_end)
            myPic.draw(page);
        else
            page.setColor(Color.WHITE);
            page.fillRect((int)(OFFSET.getX()), (int)(OFFSET.getY()), (int)(R_BOUND-OFFSET.getX()), (int)(L_BOUND-OFFSET.getY()));
        repaint();             
public void paint(Graphics g)               // this is the regular paint methode
        MessageHandler();
        ATD_age.repaint();
        StanderdCal.repaint();
        ChildSRF.repaint();
        MessageArea.repaint();
    }I hope that is helpful

Similar Messages

  • JMenu and MouseListener problems

    I have a JMenu that is used as a JMenuItem in another JMenu in the menu bar. The same JMenu is added as a popup menu to a button.
    I added a MouseListener to the JMenu because I want to execute some code upon mouseEntered() and mouseExited().
    Problem: the listener is only fired when I enter or exit the menu from the menu bar, never when the popup menu of the button is entered or exited.
    What can I do to trigger the mouse listener?

    I have a JMenu that is used as a JMenuItem in another JMenu in the menu bar.Components can only have a single parent. I don't know how what you are describing is possible.
    If you want to share the ActionEvent then you should be using an Action when creating the menu. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html]How to use Actions.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JMenuItem painting Problem

    Hi,
    I have painting problem with adding the JMenuItems dynamically. In the screen1 figure shown below, Menu 2 has has total 10 items, but initially we will show only three items. When the user clicks on the menu item ">>" all the Ten Items in Menu 2 are shown. But, All the 10 items are inserted in a compressed manner as shown in screen 2. When i click on the Menu 2 again, is shows properly as shown in screen 3.
    screen 1:
    <img src="http://img.photobucket.com/albums/v652/petz/Technical/screen1.jpg" border="0" alt="Screen 1"/>
    screen 2:
    <img src="http://img.photobucket.com/albums/v652/petz/Technical/screen2.jpg" border="0" alt="Screen 2"/>
    screen 3:
    <img src="http://img.photobucket.com/albums/v652/petz/Technical/screen3.jpg" border="0" alt="Screen 3"/>
    Here is the code:
    import java.awt.GridLayout;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class MenuUI implements MouseListener
        JFrame frame;
        JMenuBar menubar;
        JMenu menu1,menu2;
        JMenuItem menuItem;
        JMenuItem lastMenuItem;
        String MENU1_ITEMS[] = {"ONE","TWO","THREE","FOUR","FIVE"};
        String MENU2_ITEMS[] = {"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN"};
        int MIN_MENU = 3;
        public MenuUI()
            menubar = new JMenuBar();
            /*menu1 = new JMenu("Menu 1");
            menu1.setMnemonic(KeyEvent.VK_1);
            menu1.getPopupMenu().setLayout(new GridLayout(5,1));
            menu2 = new JMenu("Menu 2");
            menu2.setMnemonic(KeyEvent.VK_2);
            menu2.getPopupMenu().setLayout(new GridLayout(5,2));*/
            menu1 = new JMenu("Menu 1");
            menu1.setMnemonic(KeyEvent.VK_1);
            menu2 = new JMenu("Menu 2");
            menu2.setMnemonic(KeyEvent.VK_2);
            menubar.add(menu1);
            menubar.add(menu2);
            createMinMenuItems();
            frame = new JFrame("MenuDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setJMenuBar(menubar);
            frame.setSize(500, 300);
            frame.setVisible(true);
        public void createMinMenuItems()
            for (int i = 0; i < MIN_MENU; i++)
                menuItem = new JMenuItem(MENU1_ITEMS);
    menu1.add(menuItem);
    lastMenuItem = new JMenuItem(">>");
    lastMenuItem.addMouseListener(this);
    menu1.add(lastMenuItem);
    for (int i = 0; i < MIN_MENU; i++)
    menuItem = new JMenuItem(MENU2_ITEMS[i]);
    menu2.add(menuItem);
    lastMenuItem = new JMenuItem(">>");
    lastMenuItem.addMouseListener(this);
    menu2.add(lastMenuItem);
    private void showAllMenuItems(int menuNo)
    if(menuNo == 1)
    menu1.remove(MIN_MENU);
    for (int i = MIN_MENU; i < MENU1_ITEMS.length; i++)
    menuItem = new JMenuItem(MENU1_ITEMS[i]);
    menu1.add(menuItem);
    menu1.updateUI();
    else if(menuNo == 2)
    menu2.removeAll();
    menu2.getPopupMenu().setLayout(new GridLayout((MENU2_ITEMS.length),1));
    for (int i = 0; i < MENU2_ITEMS.length; i++)
    menuItem = new JMenuItem(MENU2_ITEMS[i]);
    //menuItem.setMinimumSize(new Dimension(35,20));
    menu2.add(menuItem);
    menu2.updateUI();
    //menu2.getPopupMenu().invalidate();
    //menu2.getPopupMenu().repaint();
    //menubar.repaint();
    //menubar.invalidate();
    //menubar.getParent().repaint();
    /* (non-Javadoc)
    * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
    public void mousePressed(MouseEvent arg0)
    System.out.println("mousePressed: Menu 1 selected: "+menu1.isSelected());
    System.out.println("mousePressed: Menu 2 selected: "+menu2.isSelected());
    if(menu1.isSelected())
    System.out.println("mousePressed: Menu 1: Show All Items");
    showAllMenuItems(1);
    else if(menu2.isSelected())
    System.out.println("mousePressed: Menu 2: Show All Items");
    showAllMenuItems(2);
    /* (non-Javadoc)
    * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
    public void mouseClicked(MouseEvent evt)
    /* (non-Javadoc)
    * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
    public void mouseEntered(MouseEvent arg0)
    /* (non-Javadoc)
    * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
    public void mouseExited(MouseEvent arg0)
    /* (non-Javadoc)
    * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
    public void mouseReleased(MouseEvent arg0)
    public static void main(String[] args)
    MenuUI ui = new MenuUI();

    // menu2.updateUI();
    menu2.getPopupMenu().setVisible(false);
    menu2.getPopupMenu().setVisible(true);

  • Jsp and JPanel problem

    Hello. I've been to this forum many times, but have always been a bit gunshy about posting anything of my own. Now I have a problem I haven't seen before, so here goes. I have a JPanel in a java program that has all sorts of other componants added to it. I am trying to display the whole thing in a jsp page. This is what I am doing in the java file to return the image ("display" is the JPanel):
    public byte[] getImage(){
        int w = display.getWidth();
        int h = display.getHeight();
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        display.paint(img.createGraphics());
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(img, "jpeg", os);
        return os.toByteArray();
    }and then in the jsp page I say:
    <%@ page contentType="image/jpeg" %>
    <%@ page import="myPackage.MyClass" %>
    <%
         MyClass picture = new MyClass();
         byte[] b = picture.getImage();
         OutputStream os;
         os = response.getOutputStream();
         os.write(b);
         os.flush();
    %>And the problem is that the page is displaying a blank JPanel and none of the componants that were added to it. If I save the the JPanel as a jpeg in the java program, though, it does contain all the componants, so I am not sure what I am doing wrong here. If there is some way to get the all the JPanel componants returned, that would be great to know. Thanks for any help.

    nope, that didn't work.
    Maybe I am going about solving the problem all wrong. The JPanel and its componants are kind of like a template. When a user of the system submits their information it automatically puts the data into the template and displays it on screen as a jpg. It works when I save the jpg as a file from the java program but not when i send the byte array to the jsp server. It just shows the blank panel....
    Is there a better way to go about doing this?

  • Coloring issues with magic wand tool and paint bucket tool, leaves uncolored areas near drawn lines

    Photoshop CS6 doesn't color properly.  Whetever I use brush tool or elliptical marquee tool to do the lines (with brush tool I use Hard Round, not soft), it doesn't color the whole area when i fill them with color. This happens with both magic wand tool AND paint bucket tool, there is always a small uncolored area near the lines. I have tolerance on 30,  and anti-alias, contiguous and sample all layers boxes checked. (this setting worked on my old CS3) I have tried tolerance from 0 to 100, no difference. I have also tried unchecking the boxes I just mentioned, still no difference. I hope there is a solution for this, because it is tedious to always go to the Select - Modify - Expand every time I need to color some area. So how do I fix this problem? I use seperate layers for lines and colors, like I have always done with other Photoshop versions. Even in school where they have CS5 those normal settings work.

    Hello Chris,
    I don't think this is a "user error". I think Adobe should be able to program a state of the art paint bucket, which is capable to get this done right.
    Other applications are able to get this done right.
    Please don't fall into a programmer's ignorance ("this is done right by definition") but listen to us artists and improve this unintuitive behavior. Add something like "ignore transparent pixels", because this doesn't even work if you draw on an empty layer.
    Thank you!

  • Paintbrush and paint bucket use wrong color in PE6 for Mac

    Hi.  I am trying to use either the paintbrush or paint bucket tool to add a solid color in a layer.  I choose a foreground color and apply the tool and instead of using the color I've chosen, it uses an old color I used several photos ago.  (I chose the old color with the eyedropper tool in case that matters).  No matter what I do, it seems that this old color is stuck in both the paintbrush and paint bucket.  I've tried choosing a different color with the eyedropper, and although that color appears as the foreground color, the old "bad" color still applies when I use either the paintbrush or bucket tool.  I have reset the tools (no luck), rebooted photoshop (no luck), tried switching back to the default (B&W) colors (still no luck).  Does anyone have any suggestion what I can try?  I'm new to the forum and have tried searching for this issue, but can't find it.  I apologize if this is an old issue.  Thank you for your help.

    Hi, thank you for this suggestion.  I will try it, and it also sounds useful for lots of quirky things.  In the meantime, I tried something else that solved my problem. I reset the eyedropper tool and picked another color with it and it cleared it out.  I had reset all the tools, but somehow it didn't work until I did this.  Thank you for your help.

  • Paint problems in 1.4-RC1

    Is anyone else experiencing repaint problems with RC1? I've seen two intermittent things so far:
    1) When a modal JDialog is shown above its owner window, the contents of the owner window are being painted inside the JDialog
    2) Scroll bars (JScrollPane) are not being repainted properly when window is resized. Phantom scroll buttons remain at the old position.
    Any others out there?

    My JDK 1.4.0 Swing application does not paint very well on 2 out of 4 NT / SP5-6machines tested. Its OK on 2 machines and NOT OK on 2 others... The machines have mixture of different graphics cards.
    The base problem reminds me of 'running out of paint handles' in Win 3.1 days... i.e. the GUI fails to refresh and gets cluttered with 'random' strips, streched painting, general 'junk' that won't clear. Its quite serious because when the application window is moved the edit-box / buttons etc don't necessarily move at same time and get partially 'off the window' and stop working. Minimize/Maximize and drag overs by other apps don't clear it. The problem seems to get worse the longer the application is executed and seems to be even worse when there's more than 1 window up a time... i.e. it almost seems like 'lack of horsepower' in CPU but these machines are PIII 400MHZ with OK RAM so there should be enough CPU.
    Note that JDK 1.3 'corrects' the problem - i.e. running same code on JDK 1.3 (instead of JDK 1.4) works just fine and does NOT have the paint problems.
    ANY HELP APPRECIATED!!

  • Help Please, with Annoying painting problem.

    Hi:
    I keep running in to this annoying problem:
    Swing Components not being re-drawn properly after:
    Windows turns on the screensaver
    or to a lesser degree if the Java program is Iconified / deiconified.
    Components with Images on them get corrupted and the image is not drawn properly, maybe just the top cm or so, but it is annoying..
    And I can't figure out what or if anything I am doing wrong.
    It happens in a few of my applications.........
    mostly those wher I have overidden paintComponent()
    If someone would like to see if they have the same thing happen, below is an example that demonstrates the problem.
    You will probably need to fiddle with you power settings so that you monitor blanks after 1 min. to avoid having to wait too long.
    Run the program, wait for screen to blank out, bring screen back,...
    If the java picture is not corrupt try re-sizing the JFrame and see what happens.
    I am using Win98SE
    I have Java:
    java version "1.4.2-beta"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
    Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
    I would appreciate someone trying this out. Even if it doesn't happen for them.
    Or maybe there is a glaring Error in my code.... And if so I could fix it..
    Here is an exmple program to demonstrate this.
    Two classes, The JPanel was obviously meant to do other things but I cut it down..
    The main:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import java.net.*;
    public class Test extends JFrame
         public Test()
              super("Test");
              Container content = this.getContentPane();
              content.setLayout( new BorderLayout() );
              URL url = null;
              Class ThisClass = this.getClass();
              url=ThisClass.getResource("Background.jpg");
              StarPanel panel = new StarPanel( url );
              content.add( panel , BorderLayout.CENTER );
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible( true );
         public static void main( String[] args )
              Test Example = new Test();
    }The JComponent - with overrriden paintComponent()
    import java.awt.Image;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.MediaTracker;
    import java.awt.Toolkit;
    import java.net.*;
         cut down version
    public class StarPanel extends JPanel
    private Image image = null;
    private boolean imageLoaded = false;
         public StarPanel( URL imageLocation )
              super();
              this.setOpaque( true );
              loadImage( imageLocation );
         public boolean isOpaque()
              return true;
         public Image getImage()
              return this.image;
         public boolean hasImage()
              return imageLoaded;
         public void loadImage( URL imageLocation )
              boolean goodLoad = true;
              boolean Test = false;
              Toolkit T = this.getToolkit();
              image = T.getImage( imageLocation );
              prepareImage(image, this);
              MediaTracker Tracker = new MediaTracker( this );
              Tracker.addImage( image , 0 );
              try
                   Tracker.waitForID( 0 );
              catch( InterruptedException IE )
                   System.out.println( "Interrupted loading Image for StarPanel: " + IE.getMessage() );
                   goodLoad = false;
              Test = Tracker.isErrorID( 0 );
              if( Test )
                   goodLoad = false;
              if( !goodLoad )
                   imageLoaded = false;
              else
                   imageLoaded = true;
              Tracker = null;
         sans any error checking
         protected void paintComponent(Graphics g)
              super.paintComponent( g );
              Graphics2D g2D = (Graphics2D) g;
              boolean T = g2D.drawImage(this.getImage(), 0, 0, this.getWidth(), this.getHeight(), this );
    }I have tried quite a few different approaches to remove or minimize this problem, and have read everything I can here on paintComponent() and etc
    Help would be appreciated.
    No dukes cos I somehow have less than 0.
    Arrg my code was all neat - before I pasted it in to the code tags.

    I tried your code and did not notice any painting problems. I'm using JDK1.4.1 on Windows 98.
    I don't see any problems with your code. Here is the thread I usually recommend when people want to add an image to a component, in case you want to run another test:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=316074

  • Painting problems with cwgraph in multiple document interface (mdi).

    Has anyone else seen weird behavior when using a cwgraph on an MDI child form in .NET. Whenever I open a new child window (containing a cwgraph) it gets painted once in the correct location and again offest about 50 pixels away and the old original location doesn't get invalided properly.
    The only workaround I've found is to contain the cwgraph in a panel or groupbox and the problem seems to go away entirely.

    Do you only see this problem with the graph, or do you see it with other Measurement Studio controls as well? Do you have any other ActiveX control on an MDI child and if so, what is the behavior of those controls? Could you please post a small test project that reproduces the problem? Thanks.
    - Elton

  • Netbeans Paint Problem

    I've got quite a strange problem I can't resolve. Currently, I have a program that can load an image and paint it on a jlabel in a scrollpane. The user can then drag rubberbanding transparent rectangles over areas of the image.
    When I run the application in netbeans, it runs absolutely flawless and is very fast. However, as soon as I compile the application into a jar and run that from a console, the painting is suddenly very slow and laggy. I'm not imagining the change at all.
    I'm currently using ubuntu and I had a few suggestions to make sure I was indeed running the sun java jre and not the gcj java on ubuntu, and I certainly am using the newest one.
    Another note: The jar runs perfectly on windows and is as fast as it is in netbeans.
    Is there some sort of drawing bug in the ubuntu version of java that I ran to, or does anyone have any other avenues to explore? I'm tearing my hair out over this one.

    Have googled it? It seems to be a bug/error inMotif
    (which is what AWT is based on Unix). Does the
    warning have any other negative effect on your
    application?my applet doesnt working i dont expect any more
    negative effectsAre you sure this "doesnt working" is caused by the warning?
    I use JDK 5 release 4 on Redhat 9 (not up to date) and also on Fedora Core 3 (up to date) with Netbeans 4.1 . I don't get a warning and both Netbeans and Applets work OK for me. I can run Applets from within Netbeans and from within Firefox.
    Have you tried writing some simple test programs. Start with HelloWorld not using X and then create and AWT HelloWorld and then create an Applet HelloWorld.

  • I am not able to launch FF everytime i tr to open it, it says FF has to submit a crash report, i even tried doing that and the report was submitted too, but stiil FF did not start, and the problem still persists, please help me solve this issue in English

    Question
    I am not able to launch FF everytime i try to open it, it says FF has to submit a crash report,and restore yr tabs. I even tried doing that and the report was submitted too, but still FF did not start, and the problem still persists, please help me solve this issue
    '''(in English)'''

    Hi Danny,
    Per my understanding that you can't get the expect result by using the expression "=Count(Fields!TICKET_STATUS.Value=4) " to count the the TICKET_STATUS which value is 4, the result will returns the count of all the TICKET_STATUS values(206)
    but not 180, right?
    I have tested on my local environment and can reproduce the issue, the issue caused by you are using the count() function in the incorrect way, please modify the expression as below and have a test:
    =COUNT(IIF(Fields!TICKET_STATUS.Value=4 ,1,Nothing))
    or
    =SUM(IIF(Fields!TICKET_STATUS=4,1,0))
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • BOSD, Battery issues and Heating problem after iOS 8 upgrade

    i have upgraded my iPad mini to iOS 8. Ever since I upgraded to iOS 8 am facing blue screen issues and heating problem as well. This is really frustrating even the patch iOS 8.0.2 dint solve the problem. Are you guys listening our complaints. When will you fixing it.

    The same thing happened to me on my 2012 Subaru Outback.  I'm not sure this will help you since you have a Honda, but I'm posting this just in case.
    I paired the audio on my car with my iPhone 6.  However, when I turned the car off and back on again, the iPhone would not pair automatically.  I had to manually connect the iPhone with the car.  Turns out there are two separate bluetooth pairings on my car: one for phone which allows up to 5 devices and one for audio which allows only one device.  So I did the second bluetooth pairing for the phone (had already done the audio), and that fixed it.  YMMV

  • I am making code to try to make a game and my problem is that my code......

    I am making code to try to make a game and my problem is that my code
    will not let it change the hit everytime so im getting the first guy to hit 1 then next hits 8 and so on and always repeats.
    Another problem is that I would like it to attack with out me telling it how much times to attack. I am using Object oriented programming.
    Here is the code for my objects:
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class rockCrab {
         //Wounding formula
         double sL = 70;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 50;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         rockCrab() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              double done = rint(fH - fA);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("Rockcrab hit" +done);
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class self {
         //Wounding formula
         double sL = 1;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 1;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         self() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("You hit" +done);
    }Here is the main code that writes what the objects do:
    class fight {
         public static void main(String[] args) {
              self instance1 = new self();
              rockCrab instance2 = new rockCrab();
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
    }when the code is run it says something like this:
    you hit 1
    RockCrabs health is 9
    RockCrab hit 7
    your health is 38
    you hit 1
    RockCrabs health is 8
    RockCrab hit 7
    your health is 31
    you hit 1
    RockCrabs health is 7
    RockCrab hit 7
    your health is 24
    you hit 1
    RockCrabs health is 6
    RockCrab hit 7
    your health is 17
    my point is whatever some one hits it always repeats that
    my expected output would have to be something like
    you hit 1
    RockCrabs health is 9
    RockCrab hit 9
    your health is 37
    you hit 3
    RockCrabs health is 6
    RockCrab hit 4
    your health is 33
    you hit 2
    RockCrabs health is 4
    RockCrab hit 7
    your health is 26
    you hit 3
    RockCrabs health is 1
    RockCrab hit 6
    your health is 20
    Edited by: rade134 on Jun 4, 2009 10:58 AM

    [_Crosspost_|http://forums.sun.com/thread.jspa?threadID=5390217] I'm locking.

  • Remote and IR Problem

    A rather odd and annoying problem has recently been occuring on my MBP. A couple days ago my remote (after working without fail for over a year now) suddenly stopped working. Yesterday night and this morning it started working again but after a while it stopped again. I've read dozens of support articles which haven't really helped because there seems to be another problem.
    Most articles have stated that there is an option to disable the IR receiver in the "security" window under system preferences. When the IR and remote are not working this option disappears but when they are working the option is present. I have also tried replacing the battery without any result.
    I am now thinking that it might have something to do with heat buildup because it is mainly occuring after the laptop has been on for about a half hour, so I am going to try to borrow someone's fan.
    If anyone has any suggestions to solve this I would appreciate it if you could help. Thanks!
    MacBook Pro 1.83 GHz   Mac OS X (10.4.9)  

    check out this thread. Seems to be the same problem.
    http://discussions.apple.com/thread.jspa?messageID=4701905&#4701905

  • LG Ally text message and gps problems

    hello. ive been with verizon for about 10 years maybe. ive been overall happy with the service and customer service. but the prices should be alot lower.lol. i started out with the motorolas then switched to the lg phones. only problem with the motorola was the speakers. not loud enough. could never hear the phone ring. the lgs usually suffer from the same problem.
    i had a few phone problems but nothing like this lg ally. im on my second one and about to be my 3rd one in about 3 months. 1st phone i had every problem under the sun. this phone i am suffering from text message problems and gps problems. i suffer from what everyone else has problems with. the messages wont send. they will eventually lock up. it will show the envelope with the red explanation point ( i think thats the graphic). then usually everytime when i sent a text the texts will close. it will send then bounce back and show up as a draft and i have to resend it and wait for it to go thru. finally the last problem with the texts. when i send a text a phone number from my contacts shows up and freezes on the screen. its in white text with a black background. its the same number every time. it stays on the screen until i restart or pull my battery out.
    gps. when i open up google gps that comes with the phone i make sure the gps is on... when the directions are found and the map pops up 9 out of 10 times it just keeps saying searching for gps. the turn by turn never is found. the 1 time it does it takes a good 10 minutes to be found. atleast on my first one ally the gps did work 8 out of 10 times. it just took a good 5-10 minutes for gps to be found and show turn by turn.
    anyone else have these problems? where you able to fix them or did you need to get a new phone? the 2.1 update was supposed to fix problems. i think they just made it worse. the ally is supposed to have 2.2 froyo. where is it. is it ever going to get it. i got this phone because i like the lgs and the keyboard. also the sales representative on the phone was giving the lg ally rave reviews. why couldnt he say dont buy this go with a motorola droid. this phone is the biggest junk ever made

    I do apologize you are having trouble with your device I looked in our information system on the LG Ally in reguards to issues you are having it states if you have the Free Droid Security anti virus protection application down loaded it will cause the phone to lock up or freeze. Check and make sure you do not have the application on your device. Check you GPS settings and make sure correct. Go to Settings; Location & Security; make sure GPS is on wireless network. If this does not fix issue you can try doing a Master Reset on your device. Make sure your contacts are saved in your G-mail account or through Back Up Assistance.
    Master Reset/Soft Reset:
    Factory Reset option 1
    From the main screen, touch menu tab
    Touch Settings
    Touch Privacy
    Touch Factory Data reset
    Touch Reset Phone
    Warning: This will erase all data from your phone, including:
    Your Google account
    System and application data and settings
    Downloaded Applications
    It will not erase: Current System software and bundled applications; SD Card files, such as music or Photos
    Factory Reset option 2  - Warning this will reset device back to original factory settings.
    Turn off the phone
    Press and hold "home" + "end" + "volume up or down" keys together for a few seconds when the device is power off
    Once device displays boot information, release keys.
    Soft Reset
    Press the Power key.
    Touch Power off.
    Touch OK.
    Press the Power key to power on the device.
    or
    Remove battery cover, remove battery and reinstall.Also there is a new update for LG Ally it will be the Froyo 2.2 but there is not release date available at this time it will post on your device when available. Hope this Helps. Leslie

Maybe you are looking for

  • Apple job site problem

    I have been using the Apple job site portal and have applied to a few vacancies since July 2013. When I go under 'my activity' it shows the name of the position, the date in which it was submitted and a " - " under questionnaire. I wwas wondering wha

  • Using iWeb as a noticeboard?

    Can iWeb and .Mac be used to create a noticeboard? I have created a website for a school parents association where the secretary (without a mac) needs to leave notices for others. I don't want others to be able to leave comments, only to read them. I

  • File to Idoc with wait for 30 secs time

    Hi Experts, We  have a requirement like, sending a file using MDM adapter to Idoc. We need to process messgaes coming into ftp one by one to target system ECC with a time interval of 30 seconds. After 1 msg is processed, wait for 30 seconds and next

  • HT203167 how can i download all my audiobook purchases

    how can i download all my audiobook purchases

  • Finder Preview without using PDF Compatability.

    Not every file I build is destined to end up in an ID document. Therefore in the interest of reducing file size I often don't need the PDF Compatibility check on in most AI files. However, not having a preview in Finder can be a bit of a pain. I'd li