Results 1 to 2 of 2
  1. #1
    bastian is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default how do I handle the exception of my code?

    in my code the paint method does not run and I do not know what is the problem?
    the exception of my code is:

    Exception in thread "AWT-EventQueue-1" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unk nown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.valueOf(Unknown Source)
    at shoot.paint(shoot.java:192)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Un known Source)
    at javax.swing.RepaintManager.access$700(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run( Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


    code:

    import java.awt.Button;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.GridLayout;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.ActionListener;
    import java.util.Scanner;

    import javax.swing.ImageIcon;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.event.ChangeListener;


    public class shoot extends JApplet {
    boolean shoot = false;
    int step = 0;

    JTextField v0 ;
    JTextField a0;
    JTextField x0;
    JTextField y0;

    public void init(){
    JPanel bord = new JPanel();

    JLabel v = new JLabel("initial rate");
    JTextField v0 = new JTextField(2);
    JLabel a=new JLabel("initial angle");
    JTextField a0 = new JTextField(2);
    JLabel x=new JLabel("initial height");
    JTextField x0 = new JTextField(2);
    JLabel y=new JLabel("initial with");
    JTextField y0=new JTextField(2);


    JButton shootIt = new JButton("play");
    JButton exit = new JButton("exit");

    JLabel d = new JLabel();
    JLabel dd = new JLabel();
    JLabel ddd = new JLabel();
    JLabel dddd = new JLabel();
    JLabel ddddd = new JLabel();
    JLabel l = new JLabel();
    JLabel ll = new JLabel();
    JLabel lll = new JLabel();
    JLabel llll = new JLabel();
    JLabel llllll = new JLabel();
    JLabel nn = new JLabel();
    JLabel nnn = new JLabel();
    JLabel nnnn = new JLabel();
    JLabel nnnnn = new JLabel();
    JLabel nnnnnn = new JLabel();
    JLabel nnnnnnn = new JLabel();





    shootIt.addMouseListener(new MouseListener(){

    @Override
    public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub
    System.out.println("you are shooting?!");
    shoot = true;
    repaint();
    JTextField x0 = new JTextField(2);
    String s="";
    s=x0.getText();
    Integer h = Integer.valueOf(s);
    JTextField y0 = new JTextField(2);
    String p="";
    p=y0.getText();
    Integer f = Integer.valueOf(p);


    JTextField v0 = new JTextField(2);
    String w="";
    p=y0.getText();
    Integer q = Integer.valueOf(p);
    JTextField a0 = new JTextField(2);
    String xx="";
    xx=y0.getText();
    Integer k = Integer.valueOf(p);



    }

    @Override
    public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    @Override
    public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    @Override
    public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    @Override
    public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    });

    bord.setBackground(Color.yellow);


    bord.setLayout(new GridLayout(0,2,10,10));


    bord.add(x);
    bord.add(x0);
    bord.add(nnnn);
    bord.add(nnnnn);
    bord.add(nnnnnn);
    bord.add(nnnnnnn);

    bord.add(a);
    bord.add(a0);
    bord.add(d);
    bord.add(dd);
    bord.add(ddd);
    bord.add(dddd);

    bord.add(y);
    bord.add(y0);
    bord.add(ddddd);
    bord.add(l);
    bord.add(ll);
    bord.add(lll);



    bord.add(v);
    bord.add(v0) ;
    bord.add(llll);
    bord.add(llllll);
    bord.add(nn);
    bord.add(nnn);





    bord.add(shootIt);
    bord.add(exit);


    exit.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
    System.exit(0);


    }
    });

    this.setLayout(new GridLayout(1,2));
    add(bord);
    add(new JLabel( ));

    this.setSize(800,800);
    this.setVisible(true);
    }

    public void paint(Graphics g){
    super.paint(g);
    JTextField x0 = new JTextField(2);
    String s="";
    s=x0.getText();
    int h = Integer.valueOf(s);
    JTextField y0 = new JTextField(2);
    String p="";
    p=y0.getText();
    int f = Integer.valueOf(p);
    int[] a=new int [4];
    int []n=new int [4] ;
    for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){

    h=h+50;
    a[i]=h;

    f=f+50;
    n[j]=f;

    g.drawLine(n[j], a[i], n[j+1], a[i+1]);

    }
    }

    if(shoot)
    g.fillArc(f+(step++), h+(step++), 30, 30, 0, 360);
    shoot = false;

    g.setColor(Color.red);
    g.fillRect (400, 500, 100,300);
    g.setColor(Color.red);
    g.fillRect (600, 500, 100,300);

    g.drawString( "welcom!" , 500 , 200);

    g.drawString( "if your bullet hit to barrier you will win!" , 500 , 250);



    }

    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: how do I handle the exception of my code?

    There's nothing advanced about this question. Since it's a duplicate, I'm closing this. Original poster, please only *one* thread per question. Else you needlessly divide the discussion and that is not fair to the volunteers of this forum. It's also against the rules that you agreed to on joining the forum.

Similar Threads

  1. how do I handle the exception of my code?
    By bastian in forum New To Java
    Replies: 2
    Last Post: 07-11-2012, 09:53 PM
  2. How to handle socket Exception
    By mayank0512 in forum Networking
    Replies: 14
    Last Post: 12-22-2010, 12:31 AM
  3. Replies: 8
    Last Post: 04-23-2010, 04:47 PM
  4. Handle exception manually
    By John_28 in forum New To Java
    Replies: 2
    Last Post: 06-05-2008, 12:26 PM
  5. [SOLVED] Handle own exception
    By stevemcc in forum New To Java
    Replies: 3
    Last Post: 04-10-2008, 05:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •