Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By JosAH

Thread: Help please!!!!!

  1. #1
    ccrone99 is offline Member
    Join Date
    May 2014
    Posts
    3
    Rep Power
    0

    Default Help please!!!!!

    Im having trouble. Whenever I try to run this code, it closes right away and I can't figure out why and i want to figure this out.
    Heres the code:

    import java.util.Random;

    import java.util.Scanner;
    import java.awt.*;

    import javax.swing.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    class magic8ball extends JPanel {

    public static void main(String[] args)
    {

    int number;
    Random myRandom = new Random();
    Scanner myScanner = new Scanner(System.in);
    number = myRandom.nextInt(1) + 1;}
    public void paintComponent1(Graphics g) {

    Random myRandom = new Random();
    int number = myRandom.nextInt(1) + 1;;
    switch (number)
    {

    case 1:
    g.setColor(Color. MAGENTA);
    g.fillRect(0,0,3000,3000);
    g.setColor(Color. black);
    g.fillOval(300,300,100,100);

    break;
    }
    }

    public magic8ball () {


    }
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    {


    }
    }



    {
    magic8ball t = new magic8ball();
    JFrame jf = new JFrame();
    jf.setTitle("box");
    jf.setSize(600,400);
    jf.setVisible(true);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.add(t);

    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Help please!!!!!

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    If there are any error messages, copy the full text and paste it here.

    The formatting of the code needs fixing. I see some hidden }s.
    Hiding }s make the code hard to read and understand. }s should be on a line by themself.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    7

    Default Re: Help please!!!!!

    when you start your application, then main method is called.

    And your main method is only doing:
    - creates a new instance of Random
    - creates a new instance of Scanner
    - gets a random number
    (If I saw it correct. At the end your code does not make sense ...)

    Konrad

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    29

    Default Re: Help please!!!!!

    Nice topic title b.t.w. I thought someone was drowning ... please change the topic title to something sensible.

    Jos
    gimbal2 likes this.
    Build a wall around Donald Trump; I'll pay for it.

Posting Permissions

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