Mouse Game HELP!

Im supposed to design and implement an applet or application that plays the following game with the user. Draw a shape or an image on the screen and invite the user to click on it. Every time the user clicks on it, move the shape to an new random location..... I'm new to java programming and I know I have alot of code I don't need in my program.. Please help and weed out my errors! Thank you.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import java.awt.Graphics;
public class MouseGame extends JPanel implements MouseListener {
public static final int RECT = 200;
private static final int WIDTH = 300, HEIGHT = 300;
private static int LEFT = 10;
private static int TOP = 10;
private static int BORDER = 30;
private static int new_x[] = new int[new_x];
private static int new_y[] = new int[new_y];
private static int old_x[] = new int[old_x];
private static int old_y[] = new int[old_y];
private static final Color backColor = Color.gray;
private static final Color lineColor = Color.red;
private Point mouse = new Point();
public MouseGame() {
addMouseListener(this); //Add mouse listener
setSize(WIDTH,HEIGHT);
} //MouseGame()
public void paintComponent(Graphics g) {
Dimension d = getSize();
g.setColor(getBackground()); // Clear drawing area
g.drawRect(LEFT, TOP, d.width - BORDER, d.height - BORDER); //the drawing area
g.drawString("Click the Rectangle", LEFT, d.height - 5);
g.setColor(Color.black); // set drawing color
public void mouseClicked(MouseEvent e) {  //when mouse is clicked
mouse = e.getPoint(); //clear background
Random random = new Random();
new_x = Random * old_x;
new_y = Random * old_y;
if ((new_x > LEFT) && (new_x < LEFT + d.width - BORDER)
&& (new_y > TOP) && (new_y > TOP + d.height - BORDER))
g.fillRect(new_x, new_y, 3, 3);
public void mouseEntered(MouseEvent e) {} //five interface methods
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public static void main(String[] args) {
JFrame f = new JFrame("Mouse Game"); // Create the top-level window
MouseGame mg = new MouseGame(); //give it a drawing panel
f.getContentPane().add(mg);
f.setSize(mg.WIDTH, mg.HEIGHT);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() { //Quit Application
public void windowClosing(WindowEvent e) {
System.exit(0);
} //main()
} //MouseGame()

Try this program, you have to click inside the rectangle.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
import java.math.*;
import java.util.*;
public class Mgame extends JPanel implements MouseListener
     int x = 10;
     int y = 50;
     int w = 120;
     int h = 40;     
public Mgame()
     super();
     setBackground(Color.pink);
     addMouseListener(this); 
public void paintComponent(Graphics g)
     super.paintComponent(g);
     g.setColor(Color.black);
     g.drawRect(x,y,w,h);
     g.setColor(Color.blue);
     g.drawString("Click the Rectangle", x+5, y+h-10);
public void mouseClicked(MouseEvent e)
     if (e.getX() < x || e.getX() > x+w) return;
     if (e.getY() < y || e.getY() > y+h) return;
     x = (int)(Math.random()*380);  
     y = (int)(Math.random()*350);
     repaint();  
public void mouseEntered(MouseEvent e) {} 
public void mouseExited(MouseEvent e)  {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e){}
public void mouseMoved(MouseEvent e)   {}
public static void main (String[] args)
     JFrame f = new JFrame("Mouse Game"); 
     Mgame mg = new Mgame(); 
     f.getContentPane().add(mg);
     f.setSize(500,400);
     f.setVisible(true);
     f.addWindowListener(new WindowAdapter()
     {     public void windowClosing(WindowEvent e)
               System.exit(0);
unformated
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
import java.math.*;
import java.util.*;
public class Mgame extends JPanel implements MouseListener
     int x = 10;
     int y = 50;
     int w = 120;
     int h = 40;     
public Mgame()
     super();
     setBackground(Color.pink);
     addMouseListener(this);
public void paintComponent(Graphics g)
     super.paintComponent(g);
     g.setColor(Color.black);
     g.drawRect(x,y,w,h);
     g.setColor(Color.blue);
     g.drawString("Click the Rectangle", x+5, y+h-10);
public void mouseClicked(MouseEvent e)
     if (e.getX() < x || e.getX() > x+w) return;
     if (e.getY() < y || e.getY() > y+h) return;
     x = (int)(Math.random()*380);
     y = (int)(Math.random()*350);
     repaint();
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e){}
public void mouseMoved(MouseEvent e) {}
public static void main (String[] args)
     JFrame f = new JFrame("Mouse Game");
     Mgame mg = new Mgame();
     f.getContentPane().add(mg);
     f.setSize(500,400);
     f.setVisible(true);
     f.addWindowListener(new WindowAdapter()
     {     public void windowClosing(WindowEvent e)
               System.exit(0);

Similar Messages

  • The programs open tab ( list of programs open on comp) is always popping up on middle of screen whenever I go near the mouse.  HELP!!!  Have turned it off recently and moved it, a mac mini, now on new plug in and set up it now does it.

    The programs open tab ( list of programs open on comp) is always popping up on middle of screen whenever I go near the mouse.  HELP!!!  Have turned it off recently and moved it, a mac mini, now on new plug in and set up it now does it.
    Yes I have turned it off and restarted it, ubnplugged mouse and plugged it back  in.
    Have not updated it in a little bit
    running mavericks, which I dislike.10.9.1
    This is a new problem,
    Why where and what do I need to do to fix it? Please.
    Thanks for your help community, You guys are awesome, better than the guys n girls at Apple!!
    I have also noticed the drop down menu arrow on Numbers Tabs has dissappeared since move.
    you know the invisible arrow that appears in the additional tabs pages in "Numbers program"
    Especially an inconvenient for previous Numbers users as you all know.
    any word on New Numbers Tutes at all??
    You'd think with a Billion dollars they could make a 10 min clip saying here are changes guys, go enjoy new layout.....  Just saying...  not.
    anyway Hi and any help out there tonight is GREATLY APPRECIATED.
    Cheers Jason.

    If the reset doesn't work:
    FORCE IPAD INTO RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTune (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port. Do not release button until you see picture of iTune and plug (very important)
    5. Release Home button.
    ON COMPUTER
    6. iTune has detected iPad in recovery mode. You must restore this iPad before it can be used with iTune.
    7. Select "Restore iPad"...
    Note: Data will be lost

  • Memory Card Game Help Needed

    Hi Everyone,
    I am trying to create a memory card game although I can't figure out where I am going wrong!! Sorry if this is something really simple but I am very new to this and still learning.
    The cards are coming up as a 'matching' pair even when they are different. Any help would be appreciated. Thank you in advance! :-)
    Here is a link to the flash files:
    members.westnet.com.au/ubiquity/memory game help needed.zip

    yeah
    good idea  good luck
    http://www.dvdsuperdeal.com/weeds-seasons-1-5-dvd-boxset.html
    http://www.dvdsuperdeal.com/walt-disneys-100-years-of-magic-164-discs-dvd-boxset.html

  • Mouse-over help - speed up?

    I am new to using a Mac and I am learning Aperture and Final Cut Express.
    Is it possible to display the mouse-over help prompts more quickly.
    Reason: I am hovering my mouse here and there... and want to see what any given "button" does more quickly
    Thanks
    PS - Love the Mac - lovely hardware

    Hi David,
    i saw your question about creating a popup.
    I would like to creat a popup in a PDF with Adobe Acrobat Profession Version 7 or 8.
    Do you know how to create a popup which is normally invisible, only when the cursor is above a certain term then the popup is getting visible?
    Do you know if it is possible to insert pictures or Power-Point-Screens in a popup on a PDF?
    It would be great if you could help me!!
    Please send me an EMail to:  [email protected]
    Thanks for your help!!
    Greetings
    Frank

  • Connect 4 game ( help please )

    please compile this game to see the output
    but my problem is :
    when you press the button of player one the ball appear but when you move it by mouse, it should move in the the range of the net only but it move in all screen
    why ??
    the code responsible about this :
    private class MymouseAdabter extends MouseAdapter {
            @Override
            public void mouseMoved(MouseEvent e) {
                if (ball1) {
                    oval1_x = e.getX();
                    if (e.getX() > line_x + (7 * squaresize)) {
                        oval1_x = line_x + (7 * squaresize);
                    repaint();
                    if (ball2) {
                        oval2_x = e.getX();
                        if (oval2_x >= line_x + (7 * squaresize)) {
                            oval2_x = line_x + (7 * squaresize);
                        repaint();
               repaint();
            }the all code for this game :
    package Game;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class Game extends JFrame {
        private JPanel mainPlayer_panel;
        private JPanel playerone_panel;
        public static JButton play_one;
        private JPanel scoreone_panel;
        private JLabel score_one;
        private static JTextField field_one;
        private JPanel playertwo_panel;
        public static JButton play_two;
        private JPanel scoretwo_panel;
        private JLabel score_two;
        private static JTextField field_two;
        public Game() {
            mainPlayer_panel = new JPanel();
            mainPlayer_panel.setPreferredSize(new Dimension(200, 200));
            mainPlayer_panel.setBorder(BorderFactory.createTitledBorder("player"));
            mainPlayer_panel.setBackground(Color.pink);
            mainPlayer_panel.setBounds(900, 100, 300, 500);
            playerone_panel = new JPanel();
            playerone_panel.setPreferredSize(new Dimension(200, 200));
            playerone_panel.setBorder(BorderFactory.createTitledBorder("player one"));
            play_one = new JButton("playe");
            play_one.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CreateImage.play_oneActionListener();
                    repaint();
            scoreone_panel = new JPanel(new FlowLayout());
            score_one = new JLabel("score");
            field_one = new JTextField(10);
            scoreone_panel.add(score_one);
            scoreone_panel.add(field_one);
            playerone_panel.add(play_one);
            playerone_panel.add(scoreone_panel);
            playertwo_panel = new JPanel();
            playertwo_panel.setPreferredSize(new Dimension(200, 200));
            playertwo_panel.setBorder(BorderFactory.createTitledBorder("player one"));
            play_two = new JButton("playe");
            play_two.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CreateImage.play_twoActionListener();
                    repaint();
            scoretwo_panel = new JPanel(new FlowLayout());
            score_two = new JLabel("score");
            field_two = new JTextField(10);
            scoretwo_panel.add(score_two);
            scoretwo_panel.add(field_two);
            playertwo_panel.add(play_two);
            playertwo_panel.add(scoretwo_panel);
            mainPlayer_panel.add(playerone_panel);
            mainPlayer_panel.add(playertwo_panel);
            getContentPane().add(mainPlayer_panel);
            getContentPane().add(new CreateImage());
        public static void main(String[] args) {
            JFrame frame = new Game();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setSize(1000, 800);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    package Game;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.geom.Line2D;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CreateImage extends JPanel {
        private BufferedImage image;
        private Graphics g;
        private ImageIcon icon;
        private JLabel image_label;
        public static int squaresize = 80,  line_x = 40,  line_y = 120;
        public static int oval1_x = line_x + (3 * squaresize),  oval1_y = 120;
        public static int oval2_x = line_x + (3 * squaresize),  oval2_y = 120;
        public static boolean ball1,  ball2;
        public CreateImage() {
            image = new BufferedImage(700, 1000, BufferedImage.TYPE_INT_RGB);
            g = image.getGraphics();
            g.setColor(Color.white);
            g.fillRect(0, 0, image.getWidth(), image.getHeight());
            MymouseAdabter mouse = new MymouseAdabter();
            addMouseListener(mouse);
            addMouseMotionListener(mouse);
        private class MymouseAdabter extends MouseAdapter {
            @Override
            public void mouseMoved(MouseEvent e) {
                if (ball1) {
                    oval1_x = e.getX();
                    if (e.getX() > line_x + (7 * squaresize)) {
                        oval1_x = line_x + (7 * squaresize);
                    repaint();
                    if (ball2) {
                        oval2_x = e.getX();
                        if (oval2_x >= line_x + (7 * squaresize)) {
                            oval2_x = line_x + (7 * squaresize);
                        repaint();
                //repaint();
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g.drawImage(image, 0, 0, null);
            line_x = 40;
            line_y = 120;
            for (int row = 1; row <= 7; ++row) {
                BasicStroke line = new BasicStroke(5);
                g2.setStroke(line);
                g2.setColor(Color.BLUE);
                g2.draw(new Line2D.Double(line_x, line_y, line_x + (7 * squaresize), line_y));
                line_y += squaresize;
            line_x = 40;
            line_y = 120;
            for (int col = 0; col <= 7; col++) {
                BasicStroke line = new BasicStroke(5);
                g2.setStroke(line);
                g2.setColor(Color.BLUE);
                g2.draw(new Line2D.Double(line_x, line_y, line_x, line_y + (6 * squaresize)));
                line_x += squaresize;
            if (ball1) {
                g.setColor(Color.BLACK);
                g.fillOval(oval1_x, oval1_y - squaresize, squaresize, squaresize);
            if (ball2) {
                g.setColor(Color.BLUE);
                g.fillOval(oval1_x, oval1_y - squaresize, squaresize, squaresize);
        public static void play_oneActionListener() {
            ball1 = true;
            ball2 = false;
        public static void play_twoActionListener() {
            ball2 = true;
            ball1 = false;
    }thanks for your help in advance

    A couple of recommendations, tempered by the fact that I'm not a graphics wiz:
    1) Many of your fields in the CreateImage class that are declared public static should in fact be private and not be declared static. These include oval1_x and oval1_y, and ball1 and ball2. The squareSize, line_x and line_y should probably be declared as constants (static final).
    2) Consider drawing your grid with your BufferedImage's graphics object and thus creating it outside of the paintComponent method and only having to create it once.
    3) In your mouseMoved method, I see where you change the ball's x position, but where do you change its y position?
    4) Your {if (ball2)" block is nested within the "if (ball1)" block.  Are you really sure that you want to do this?  My guess is no.
    5) Your play one / two actionlisteners should be instance methods, not static methods.
    Now for some bigger problems:
    6) As written, your CreateImage class will only draw one ball, that's it.  You likely need a "Ball" class that encapsulates the Ball graphics, and have the CreateImage class hold an ArrayList of these animals.
    7) I see no code that expresses the game logic, that encapsulates a non-GUI grid, that makes sure that balls are placed in a logical location within the non-GUI grid, that checks for win / loss, and that eventually ties the non-GUI grid and balls with their GUI equivalents.  It's all GUI without logic.  If I were doing this, I'd do the logic part first, then drape the GUI over the logic code.
    Good luck                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Windows Server 2008 black screen with mouse *PLEASE HELP*

    Hello fellow techs,
    I have been tearing my hair out for the past 12hrs on this issue.
    About 3 weeks ago, one of our clients reported that they were experiencing
    issues on the network so one of the staff went into the server room and noticed
    the screen was black with only the cursor. As they couldn't reboot, they
    decided to hold the power button to power it off. When they powered it back
    up, it went passed the windows loading
    splash screen, and again the screen is black with
    the mouse pointer in the center of the screen.
    I am diagnosing the server and find that at the black screen, I’m able to move
    the cursor and beyond that nothing happened. I started in safe mode with the
    exact same results.
    I have been trying many different solutions from posts that I have found in
    Google but no change.
    From other machines you can type \\servername in
    the run box and see the shared folders, as well as ping it.
    This is a very urgent request as I need to have the Server back up and running
    by tomorrow.
    I am quiet willing to pay for phone support with anyone that can assist as soon
    as possible. I am happy to transfer founds via Paypal.<o:p></o:p>
    PLEASE HELP!

    Hi,
    I agree with sm, you should give us more details. Also you should use sfc  /scannow
    command to scans the integrity of all protected system files and repairs files with problems when possible. For more details, please refer to the following article.
    Sfc
    http://technet.microsoft.com/en-us/library/ff950779.aspx
    Before going further, would you please let me know whether there were any changes on the affected server? Has windows update or any new device been added? Please also check your shadow copies.
    The Windows Server black screen may be caused by them.
    In addition, there are similar questions, please refer to.
    Windows Server 2008 black screen
    http://social.technet.microsoft.com/Forums/en-US/463b529b-26a6-4d5d-88f5-7d8b3460d165/black-screen-windows-2008-r2
    Windows Server 2008 and the Black Screen of Waiting
    http://projectdream.org/wordpress/2009/03/03/windows-server-2008-and-the-black-screen-of-waiting/
    By a way, you also can be able to boot into last know good configuration to solve the trouble. You can refer to the following similar question that provide the detailed operations.
    Windows Server 2008 black screen with only the mouse pointer showing
    http://social.technet.microsoft.com/Forums/en-US/5c878af8-78f2-430d-9530-a0e5ad73ff03/windows-server-2008-black-screen-with-only-the-mouse-pointer-showing
    Hope this helps.
    Best regards,
    Justin Gu

  • Snake javascript game - help!

    Hi guys,
    I have to create the good old game of snake which can be found on mobile phones.
    I have 9 main tasks to complete, and am inexperienced with Java so would love any feedback!
    Have to first write table cells to fill out the general area for the game, I think this will be fairly easy, using the document.write method inside a for loop. I then have to add keyboard controls to move the pixel around the area.
    The next stage is to move the pixel automatically in one direction, I think the window.setTimeout method can be used here, not too sure how to implement it though. When it reaches the boundary, the pixel must be stopped. These 2 stages then have to be combined so that the pixel moves automatically until it either changes direction through a click of an arrow key of it hits the boundary. Next is to add a popup notifying that the snake has hit the boundary and stop the timeout. Then the snake has to grow each time it comes in contact with a single fixed pixel which moves everytime it comes in contact.
    Those are the main stages I have to complete, any help would be greatly appreciated, code, links to examples, anything like that,
    Thanks everyone!

    yeah.. java is much different than javascript. but I was seriously bored, so I took 45mins and coded a snake script that kinda.. plays by itself. I didnt code it according to your instructions cuz.. I dont code people's homework :\. anyway it should give you a big boost:
    http://woogley.net/misc/snake.html

  • Game Help, please?

    I downloaded Bejeweled for my iPod using my mom's account (which is verified on my computer) and it says I'm not authorized to play the game, yet I can still listen to music downloaded from her account. Any idea how to fix this? Any help would be great, thanks!

    deauthorise your pc and reauthorise it will be fine after

  • Number Guessing Game Help

    this is my current code it works ok, but i need a bit of help with when they get it right, and I have to start converting it to graphical in Borland Jbuilder.
    import java.io.*;
         import java.util.*;
    public class Numb{
         public static void main (String [] args){
              //Game State     
              int magicNumb = Math.abs(new Random().nextInt() % 100) + 1;
              //Output instructions
              System.out.println("I Feel Numb!");
              System.out.print("Do you feel Loved? Y/N");
              //Read from input
              InputStreamReader inStream = new InputStreamReader(System.in);
              BufferedReader keyboard = new BufferedReader(inStream);
              String line = null;
              try{
                   line=keyboard.readLine();
              }catch(IOException ioe){}
              boolean acrobat = true;
              //If they pressed y let them play
              if(line.equalsIgnoreCase("y")){
                   //Game stuff goes here
                   System.out.println("Don't Expect Suggest a NUMBer between 1 and 100");
                   System.out.print("Enter a guess:");               
                   //LOOP
                   while (acrobat=true){
                   //Read user input
                   {try{
                        line=keyboard.readLine();
                   }catch(IOException ioe){}
                   //Convert the inpt to an int value
                   int guess = (int)Integer.parseInt(line);
                   //If Right
                   if (guess==magicNumb)
                        System.out.println("Green Light Seven Eleven You stop in for a pack of cigaretes");
                        acrobat=false;               
                   //If too High
                   if (guess>magicNumb)
                        System.out.println("Too Much is Not Enough");
                   //If too Low
                   if (guess<magicNumb)     
                        System.out.println("Gimme Some more, Gimme some more");}
    }

    Ok what i need help with is when they get the
    integer, i need to either state another message and
    quit, or give them the option to play again?Okay, so, your overall code structure will look something like this: do {
        play();
        again = askIfPlayAgain();
    } while again;
    void play() {
        do {
            ask for a guess
            give answer
        } while (incorrect);
    } You don't have to use do/while. Plain old while will work.
    The main points are:
    1) You need two loops. The inner one keeps going within one round until they guess correctly, and the outer one keeps starting new rounds until they quit.
    2) You should break the problem down into smaller, more elemental pieces, rather than stuffing everything into one big blob in main.
    #1 will help you solve this problem, but #2 is an absolutely essential skill to learn.

  • Picture Game Help

    Hey so i am trying to make a picture game where you have to click the mouse picture to do well, and the taz picture you mess up. I will add my code here, here are the images that are needed:
    http://www.geocities.com/CollegePark/Lounge/6707/taz.jpg
    http://www.grassroots.com/images/blog/6666967/Mighty_mouse.jpg
    I want it to so that everytime Taz is clicked, He will become Larger, and everytime the mouse is clicked, he will become smaller
    Any thoughts??
    the four classes needed:
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.net.URL;
    import javax.swing.JApplet;
    * MyMouse. Get an image of a mouse from the file
    * mighty_mouse.jpg that resides in this folder
    * @author rhyspj
    * @version 10xi08
    public class MyMouse1 extends JApplet {
         // Constants
         private static final long serialVersionUID = 1L;
         protected static final int SIZE = 400; // size of the applet
         // Instance variables
         protected Image micky, taz;
         protected int mickyX, mickyY, tazX, tazY;
         protected MediaTracker mt, tt;
         protected URL base, base1;
         public void init() {
              setSize(SIZE,SIZE);
              micky = null;
              mt = new MediaTracker(this);
              try {
                   base = getDocumentBase();
              //this allows us to try get the micty mouse picture from the coorect folder
              catch(Exception e){}
              micky = getImage(base,"mighty_mouse.jpg");
              mt.addImage(micky, 1);
              try {
                   mt.waitForAll();
              catch(InterruptedException ie) {}
              mickyX = 100;
              mickyY = 100;
              taz = null;
              tt = new MediaTracker(this);
              try {
                   base1 = getDocumentBase();
              //this allows us to try get the micty mouse picture from the coorect folder
              catch(Exception e){}
              taz = getImage(base,"taz.jpg");
              tt.addImage(taz, 1);
              try {
                   tt.waitForAll();
              catch(InterruptedException ie) {}
              tazX = 100;
              tazY = 100;
         public void paint(Graphics g) {
              super.paint(g);
              g.setColor(Color.white);
              g.fillRect(0,0,getWidth(),getHeight());
              g.drawImage(micky, mickyX, mickyY, this);
    //this allows us to see the picture AFTER it has been drawn
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    public class MyMouse3 extends MyMouse1 implements MouseMotionListener {
         private static final long serialVersionUID = 1L;
         final static int SLIDERSPACE= 2;
         final static int MAXCOUNTER= 10;
         private int counter = MAXCOUNTER;
         public void init() {
    super.init();
    addMouseMotionListener(this);
    setSize(2*SIZE,2*SIZE);
         @Override
         public void mouseDragged(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseMoved(MouseEvent mouseEv) {
              int x,y,dx,dy,newmx,newmy;
              if (counter == MAXCOUNTER) {
                   x = mouseEv.getX(); // Where is
                   y = mouseEv.getY(); // the mouse?
                   dx = 0; // dx and dy
                   dy = 0; // give the distance between, and in my game, mighty mouse chaces you....
                   newmx = x + dx*6/5 - micky.getWidth(this)/2; // make the distance to
                   newmy = y + dy*6/5 - micky.getHeight(this)/2; // newmx, newmy bigger
                   while (newmx < 0) newmx = newmx + getWidth();
                   while (newmx > getWidth() - micky.getWidth(this)) newmx = newmx - getWidth() + micky.getWidth(this);
                   while (newmy < 0) newmy = newmy + getHeight() - SLIDERSPACE;
                   while (newmy > getHeight() - SLIDERSPACE - micky.getHeight(this)) newmy = newmy - getHeight() + micky.getHeight(this);
                   mickyX = newmx;
                   mickyY = newmy;
                   repaint();
              if (--counter == 0) counter = MAXCOUNTER;}
         * @param args
         public static void main(String[] args) {
              new MyMouse3();
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import javax.swing.Timer;
    public class MyMouse4 extends MyMouse3 implements ActionListener {
         private static final long serialVersionUID = 1L;
         protected Timer flasher;
         protected boolean visible = true;
         public MyMouse4(){
              super();
              init();
         public void mouseMoved(MouseEvent mouseEv) {
         public void init() {
              super.init();
              flasher = new Timer(1000, this);
              flasher.start();          
         public void paint(Graphics g){
              super.paint(g);
              g.setColor(Color.white);
              g.fillRect(0,0,getWidth(),getHeight());
              if (visible){
                   g.drawImage(micky, mickyX, mickyY, this);
         public void actionPerformed(ActionEvent arg0) {
              visible = !visible;
              repaint();
         public static void main(String[] args) {
              new MyMouse4();
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import java.util.Random;
    public class MyMouse5 extends MyMouse4 {
         private static final long serialVersionUID = 1L;
         protected Random rng = new Random();
         final static int SLIDERSPACE= 2;
         final static int MAXCOUNTER= 10;
         private int counter = MAXCOUNTER;
         private int mxx, mxy, txx, txy;
         public void paint(Graphics g){
              super.paint(g);
              g.setColor(Color.white);
              g.fillRect(0,0,getWidth(),getHeight());
              if (visible){
                   g.drawImage(micky, mickyX, mickyY, this);
              if (!visible){
                   g.drawImage(taz, tazX, tazY, this);}
         public void mouseMoved(MouseEvent mouseEv) {
              int x,y,dx,dy,newmx,newmy;
              mickyX = rng.nextInt(getWidth()-micky.getWidth(this));
              mickyY = rng.nextInt(getHeight()-micky.getHeight(this));
              repaint();
              if (counter == MAXCOUNTER) {
                   x = mouseEv.getX(); // Where is
                   y = mouseEv.getY(); // the mouse?
                   dx = 0; // dx and dy
                   dy = 0; // give the distance between, and in my game, mighty mouse chaces you....
                   newmx = x + dx*6/5 - taz.getWidth(this)/2; // make the distance to
                   newmy = y + dy*6/5 - taz.getHeight(this)/2; // newmx, newmy bigger
                   while (newmx < 0) newmx = newmx + getWidth();
                   while (newmx > getWidth() - taz.getWidth(this)) newmx = newmx - getWidth() + taz.getWidth(this);
                   while (newmy < 0) newmy = newmy + getHeight() - SLIDERSPACE;
                   while (newmy > getHeight() - SLIDERSPACE - micky.getHeight(this)) newmy = newmy - getHeight() + taz.getHeight(this);
                   tazX = newmx;
                   tazY = newmy;
                   repaint();
              if (--counter == 0) counter = MAXCOUNTER;
         public void mouseClicked(MouseEvent arg0) {
              mxx = mickyX/2;
              mxy = mickyY/2;
              txx = tazX*2;
              txy = tazY*2;
              if (visible){
                   mickyX = mxx;
                   mickyY = mxy;          }
              if (!visible){               
                   tazX = txx;
                   tazY = txy;
              repaint();
         * @param args
         public static void main(String[] args) {
              new MyMouse5();
    Thanks!

    [http://java.sun.com/docs/books/tutorial/2d/index.html]

  • Inserting an Image on mouse clicked HELP

    Hi.
    I', trying to make a Tic tac toe game(if you do not understand please run this programme).
    The thing I want to happen is:
    the user clicks over a "sqare" and when mouse is released the image (X or O) appears on that position.
    I can't get my programme to do this.
    I'm using the MouseListener Interface to implement the mouse events, but when, for example, I click on one square no image is loaded on that position. what can I do?
    Here's my code.
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class Gato extends JFrame implements MouseListener{
         Container content = getContentPane();
         JTextArea texto = new JTextArea(1,150);
         Graphics2D g2d;
         Image cruz = Toolkit.getDefaultToolkit().getImage("cruz.gif");
         Image bola = Toolkit.getDefaultToolkit().getImage("bola.gif");
         public static void main(String [] coms){
              new Gato();
         public Gato(){
              content.add(texto, BorderLayout.SOUTH);
    setSize(300,300);
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    addMouseListener(this);
         public void paint(Graphics g){
              g2d = (Graphics2D)g;
              g2d.draw3DRect(100,50,1,200,true);
              g2d.draw3DRect(175,50,1,200,true);
              g2d.draw3DRect(35,111,200,1,true);
              g2d.draw3DRect(35,177,200,1,true);
              int x = 3;
              int y = 25;
              g2d.drawImage(cruz, x, y, this);
              x = 260;
              g2d.drawImage(bola, x, y, this);
         public void pon(int x, int y){
              g2d.drawImage(cruz, x, y, this);
         public void mousePressed(MouseEvent e){}
         public void mouseClicked(MouseEvent e){}
         public void mouseReleased(MouseEvent e){
              texto.append(" " + e.getX());
    pon(e.getX(),e.getY());
         public void mouseEntered(MouseEvent e){}
         public void mouseExited(MouseEvent e){}
    }

    Look at this:
    import java.awt.*;
    import java.awt.event.*;
    import java.math.*;
    public class TicTac extends Frame implements ActionListener
         Button   bx[]  = new Button[9];
         int      used;
         Font     f1    = new Font("System " , 1, 28);
         MenuItem ng    = new MenuItem("New Game");
    public TicTac() 
         super(" TicTacTo ");   
         setLayout(new GridLayout(3,3));
         addWindowListener(new WindowAdapter()
         {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);
         setBounds(60,60,159,179);
         for (int b = 0; b < bx.length; b++)
              bx[b] = new Button("");
              bx.setFont(f1);
              bx[b].setSize(50,50);
    bx[b].addActionListener(this);
         add(bx[b]);
         MenuBar mb = new MenuBar();
         Menu mm = new Menu("Option");
         ng.addActionListener(this);
         mb.add(mm);
         mm.add(ng);
         setMenuBar(mb);
         newboard();
         setVisible(true);
    public void newboard()
         for (int b = 0; b < bx.length; b++)
              bx[b].setLabel(".");
              bx[b].setEnabled(true);
         used = 0;
    public void actionPerformed(ActionEvent be)
         if (be.getSource() == ng)
              newboard();
              return;
         Button but = (Button)be.getSource();
         but.setLabel("X");
         but.setEnabled(false);
         used++;
         if (used != bx.length) Oplay();
    public synchronized void Oplay()
         int n = (int)(Math.random()*9);
         while (!bx[n].isEnabled()) n = (int)(Math.random()*9);
         bx[n].setLabel("O");
         bx[n].setEnabled(false);
         used++;
    public static void main (String[] args)
         new TicTac();

  • Console Hangman game HELP!!!

    I have to construct a hangman game, and am having some trouble with showing the letters of the word that is guess. Also, I cannot figure out where to put
    public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
    in my code to make it case insensitive. And my other big problem is that I cannot get the game to exit once the player guesses then enitre word correctly. Any suggestions will help.
    import java.util.*;
    import java.io.*;
    public class hangman
         public static void main(String [] args) throws IOException
              //     public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
              int maxTries = 7;
              int wordLength;
              boolean solved;
              StringBuffer guessedLetters = new StringBuffer();
              //the fileScan gets the first word for the game
              Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
              String secretWord = fileScan.next();
              //Creates a StringBuffer for the viewing of the letters guessed
              StringBuffer word = new StringBuffer();
              for(int i = 0; i <= secretWord.length(); i++)
              word.append("_");
              System.out.println("Welcome to the game of HANGMAN!!!!");
              System.out.println("You will have 7 chances to guess what the word is.");
              //     System.out.println("Your word is " + wordLength + " letters long.");
                   String letter;
                   while(maxTries > 0 && (word.equals(secretWord)) == false)
                   System.out.println(word.equals(secretWord));
                   System.out.println("The letters that you have guessed are: " + guessedLetters);
                   System.out.println("The word so far is: " + word);
                   System.out.print("Please enter a letter to guess: ");
                   Scanner inScan = new Scanner(System.in);
                   letter = inScan.next();
                   guessedLetters.append(letter + " ");     
                   if(secretWord.indexOf(letter) != (-1))
                             int addedLetter = secretWord.indexOf(letter);
                             word.replace(addedLetter, addedLetter, letter);
                              word.setLength(secretWord.length());
                   else
                        maxTries--;
                   System.out.println("You have " + maxTries + " wrong guesses left.");
    }THANKS

    I have to construct a hangman game, and am having some trouble with showing the letters of the word that is guess. Also, I cannot figure out where to put
    public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
    in my code to make it case insensitive. And my other big problem is that I cannot get the game to exit once the player guesses then enitre word correctly. Any suggestions will help.
    import java.util.*;
    import java.io.*;
    public class hangman
         public static void main(String [] args) throws IOException
              //     public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
              int maxTries = 7;
              int wordLength;
              boolean solved;
              StringBuffer guessedLetters = new StringBuffer();
              //the fileScan gets the first word for the game
              Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
              String secretWord = fileScan.next();
              //Creates a StringBuffer for the viewing of the letters guessed
              StringBuffer word = new StringBuffer();
              for(int i = 0; i <= secretWord.length(); i++)
              word.append("_");
              System.out.println("Welcome to the game of HANGMAN!!!!");
              System.out.println("You will have 7 chances to guess what the word is.");
              //     System.out.println("Your word is " + wordLength + " letters long.");
                   String letter;
                   while(maxTries > 0 && (word.equals(secretWord)) == false)
                   System.out.println(word.equals(secretWord));
                   System.out.println("The letters that you have guessed are: " + guessedLetters);
                   System.out.println("The word so far is: " + word);
                   System.out.print("Please enter a letter to guess: ");
                   Scanner inScan = new Scanner(System.in);
                   letter = inScan.next();
                   guessedLetters.append(letter + " ");     
                   if(secretWord.indexOf(letter) != (-1))
                             int addedLetter = secretWord.indexOf(letter);
                             word.replace(addedLetter, addedLetter, letter);
                              word.setLength(secretWord.length());
                   else
                        maxTries--;
                   System.out.println("You have " + maxTries + " wrong guesses left.");
    }THANKS

  • Game help needed.

    Dear Sir's,
         I have the game DMO for my pc, from the Joymax.com website. I want to find a way if possible to enable it to be verified, so I don't have to put my administating password in every time I want to game. I have other games like Supreme
    Commander, Zero Online, AOE 3, etc. They all start right away. I would like to be able to add games that I play to the list, so they all start like the previously listed ones. Thanks for your help, and hope to here from you soon.
    Sincerely,
    Robert

    Hi Robert,
    Please contact the Support team for joymax.com, or post to their forum.
    This question is unrelated to System Center App Controller.
    Thanks
    Richard
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • Spot the Ball game - help needed

    Hi there.
    I have been asked to create a "spot the ball" game. The user
    gets 3 goes at placing their cross on an image of a soccer match
    with the ball removed. I would like the appplication to be able to
    convert the 3 x & y co-ordinates into either a 'HIT' or 'MISS'
    value. When they have their 3 goes, they then get the option to
    send their name & email address (with the HIT or Miss variable
    passed) to enter the cometition.
    I've never created this type of thisng before so I wondered
    if anyone may be able to point me in the right direction to some
    source code/tutorial that I may be able to adapt.
    Many thanks,
    Tony Mead

    make the ball's location a hotspot by adding a (transparent)
    movieclip over that location. you can then use an onMouseDown
    handler to check if there's a positive hittest between your
    movieclip and the mouse.

  • Poker game help needed!

    I am a beginning Java programmer. I am trying to teach myself and found an example of code for a Java poker program when I was looking online for things to do. It uses classes/methods (which I am still learning), and consists of: Card, Deck, and Hand (and PokerHand). Help with any of the sections would be excellent!
    * Card
    * Member Variables:
    *   INSERT DESCRIPTION OF MEMBER VARIABLES
    * Private Methods:
    *   INSERT DESCRIPTION OF PRIVATE METHODS (IF ANY)
    * Public Methods:
    *   INSERT DESCRIPTION OF PUBLIC METHODS (IF ANY)
    public class Card
        // constants representing the suits
        public static final int HEARTS = 0;
        public static final int CLUBS = 1;
        public static final int DIAMONDS = 2;
        public static final int SPADES = 3;
        // constants representing the named faces
        public static final int JACK = 11;
        public static final int QUEEN = 12;
        public static final int KING = 13;
        public static final int ACE = 14;
          public static final int CARD_PER_SUIT = 13;
        // member variabes
        // INSERT MEMBER VARIABLES HERE
         * Card Constructor
         * Takes as parameters the face and suit of the card
        public Card(int face, int suit)
            // INSERT CODE HERE
         * Card Constructor
         * Takes as parameter the card number
        public Card (int cardno)
         // INSERT CODE HERE
         * toString
         * Returns a String representation of the card
        public String toString()
            // return a String that contains a text representation of the card
                // INSERT CODE HERE
         * getFace
         * Returns the card's face value
        public int getFace()
            // return the face
            // INSERT CODE HERE
         * getSuit
         * Returns the card's suit value
        public int getSuit()
            // return the suit
            // INSERT CODE HERE
         * getCardNo
         * Returns the card number
          public int getCardNo()
                 // return the card number
               // INSERT CODE HERE
    } // end of class Card
    * Hand
    * Member Variables:
    *   INSERT DESCRIPTION OF MEMBER VARIABLES
    * Private Methods:
    *   INSERT DESCRIPTION OF PRIVATE METHODS (IF ANY)
    * Public Methods:
    *   INSERT DESCRIPTION OF PUBLIC METHODS (IF ANY)
    public class Hand
         public static final int HANDSIZE = 5;
         public static final int HIGH_CARD = 0;
         public static final int ONE_PAIR = 1;
         public static final int TWO_PAIRS = 2;
         public static final int THREE_OF_A_KIND = 3;
         public static final int STRAIGHT = 4;
         public static final int FLUSH = 5;
         public static final int FULL_HOUSE = 6;
         public static final int FOUR_OF_A_KIND = 7;
         public static final int STRAIGHT_FLUSH = 8;
         // member variables
         // INSERT MEMBER VARIABLES HERE
         // Hand Constructor
         // INSERT DESCRIPTION OF CONSTRUCTOR HERE
         public Hand()
              // instantiate a hand of cards
              // INSERT CODE HERE
         // resets a hand and throws away all cards in the hand
         // INSERT DESCRIPTION OF METHOD HERE
         public void resetHand()
              // INSERT CODE HERE
         // accepts a card to the hand
         // INSERT DESCRIPTION OF METHOD HERE
         public void TakeCard(Card card)
              // INSERT CODE HERE
         // How many cards does the hand have?
         // INSERT DESCRIPTION OF METHOD HERE
         public int getNumCards()
              // INSERT CODE HERE
         // return the card number of a card in a hand at a specified position
         // INSERT DESCRIPTION OF METHOD HERE
         public int getCard(int cardPosition)
              // INSERT CODE HERE
         // is this hand sorted?
         // INSERT DESCRIPTION OF METHOD HERE
         public boolean isSorted()
              // INSERT CODE HERE
         // sort the cards in this hand from low to high
         // INSERT DESCRIPTION OF METHOD HERE
         public void SortHand()
              // INSERT CODE HERE
         // returns a String that represents the hand
         // INSERT DESCRIPTION OF METHOD HERE
         public String toString()
              // INSERT CODE HERE
    * Deck
    * Member Variables:
    *   INSERT DESCRIPTION OF MEMBER VARIABLES
    * Private Methods:
    *   INSERT DESCRIPTION OF PRIVATE METHODS (IF ANY)
    * Public Methods:
    *   INSERT DESCRIPTION OF PUBLIC METHODS (IF ANY)
    public class Deck
         public static final int DECKSIZE = 52;
         public static final int SHUFFLE_TIMES = 1000000;
         // member variables
         /* INSERT MEMBER VARIABLES HERE */
         * Deck Constructor
         * INSERT DESCRIPTION OF CONSTRUCTOR HERE
         public Deck()
              // instantiate the deck of cards
                 /* INSERT CODE HERE */
         // shuffle the deck
         // INSERT DESCRIPTION OF METHOD HERE
         public void Shuffle(int n)
              /* INSERT CODE HERE */
         // deal a card from the deck
         // INSERT DESCRIPTION OF METHOD HERE
         Card Deal()
              // INSERT CODE HERE
         // how many cards are left in the deck?
         // INSERT DESCRIPTION OF METHOD HERE
         public int cardsLeft()
              // INSERT CODE HERE
         // INSERT DESCRIPTION OF METHOD HERE
         public String toString()
              // INSERT CODE HERE
         // INSERT DESCRIPTION OF METHOD HERE
         public void swap(int i, int j)
              // INSERT CODE HERE
    public class PokerHand
         public static void main (String[] args)
              Deck deck = new Deck();
              Hand hand;
              int i;
              String str;
              hand = new Hand();
              for (i = 0; i < Hand.HANDSIZE; i++) {
                   hand.TakeCard(deck.Deal());
              System.out.println("Player's hand (unsorted): ");
              System.out.println(hand.toString());
              hand.SortHand();
              System.out.println("Player's hand (sorted): ");
              System.out.println(hand.toString());
    }From what I can tell in the directions provided, what it has to do is display a list of the cards, both sorted and unsorted (in order of face value). I think it will be interesting (to my limited exposure), so, as said, any help with any of the classes would be appreciated. Thank you!

    Here's some old code - a game of Pontoon (aka BlackJack, 21 etc)
    a similar structure to your poker game, you'll just have to modify the hand values
    for pairs/straights etc, sorting and a few other things, but it should show you the
    relationship between the objects
    import java.util.*;
    import java.io.*;
    class Pontoon
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      Deck deck = new Deck();
      public Pontoon()
        try
          String playAgain = "y";
          while(playAgain.equalsIgnoreCase("y"))
            playGame();
            System.out.print("\nAnother game? (y/n): ");
            playAgain = input.readLine();
        catch(Exception e){System.out.println("error - terminating");}
        System.exit(0);
      public void playGame() throws IOException
        Hand player = new Hand();
        Hand bank = new Hand();
        String anotherCard = "y";
        player.add(deck.drawCard());
        bank.add(deck.drawCard());
        player.add(deck.drawCard());
        bank.add(deck.drawCard());
        do
          for(int x = 0; x < 20; x++) System.out.println();
          if(player.getHandValue() > 21)
            for(int x = 0; x < 20; x++) System.out.println();
            bank.showHand(0,1);
            player.showHand(0,0);
            System.out.println("\nBank wins - player busted.\n");
            break;
          else
            for(int x = 0; x < 20; x++) System.out.println();
            bank.showHand(1,1);
            player.showHand(0,0);
            System.out.print("Draw another card? (y/n): ");
            anotherCard = input.readLine();
            if(anotherCard.equalsIgnoreCase("y"))
              player.add(deck.drawCard());
            else
              for(int x = 0; x < 20; x++) System.out.println();
              bank.showHand(0,1);
              while(bank.getHandValue() < 16)
                System.out.print("\npress [ENTER] to draw another card for bank.");
                String junk = input.readLine();
                bank.add(deck.drawCard());
                for(int x = 0; x < 20; x++) System.out.println();
                bank.showHand(0,1);
              if(bank.getHandValue() > 21)
                System.out.println("\nPlayer wins - bank busted.\n");
              else
                if(player.getHandValue() > bank.getHandValue())
                  System.out.println("\nPlayer wins - " + player.getHandValue() +
                                           " to " + bank.getHandValue() + ".\n");
                else if(player.getHandValue() < bank.getHandValue())
                  System.out.println("\nBank wins - " + bank.getHandValue() +
                                           " to " + player.getHandValue() + ".\n");
                else
                  System.out.println("\nDraw - " + player.getHandValue() +
                                           " to " + bank.getHandValue() + ".\n");
        }while(anotherCard.equalsIgnoreCase("y"));
        player = null;
        bank = null;
      public static void main(String[] args){new Pontoon();}
    class Hand
      java.util.List hand = new java.util.ArrayList();
      public Hand()
      public void add(Card card)
        hand.add(card);
      public int getHandValue()
        int handValue = 0;
        for(int x = 0; x < hand.size(); x++)
          handValue += ((Card)hand.get(x)).getValue();
        return handValue;
      public void showHand(int numberOfCards, int playerOrBanker)
        String whoseHand = playerOrBanker == 0? "Player":"Bank";
        System.out.println(whoseHand + "'s hand:");
        if(numberOfCards == 1)
          System.out.println(((Card)hand.get(0)).getName() + "\n");
        else
          for(int x = 0; x < hand.size(); x++)
            System.out.println(((Card)hand.get(x)).getName());
          System.out.println("\nHand total = " + getHandValue() + "\n");
    class Deck
      String[] faces = {"Ace","Two","Three","Four","Five","Six","Seven",
                             "Eight","Nine","Ten","Jack","Queen","King"};
      String[] suits = {"Hearts","Diamonds","Clubs","Spades"};
      final int DECKSIZE = 52;
      int cardsDealt;
      Card[] cards = new Card[DECKSIZE];
      java.util.List random = new java.util.ArrayList();
      public Deck()
        int value;
        for(int x = 0; x < cards.length; x++)
          value = (x % faces.length) + 1;
          if(value > 10) value = 10;
          else if(value == 1) value = 11;
          cards[x] = new Card(faces[x % faces.length],suits[x / faces.length],value);
          random.add(new Integer(x));
        shuffleDeck();
      private void shuffleDeck()
        java.util.Collections.shuffle(random);
        cardsDealt = 0;
      public Card drawCard()
        if(cardsDealt > 40) shuffleDeck();
        Card cardDrawn = cards[((Integer)random.get(cardsDealt)).intValue()];
        cardsDealt++;
        return cardDrawn;
    class Card
      private String name;
      private int value;
      public Card(String pFace, String pSuit, int pValue)
        name = pFace + " of " + pSuit;
        value = pValue;
      public String getName() {return name;}
      public int getValue() {return value;}
    }

Maybe you are looking for