Results 1 to 1 of 1
  1. #1
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Post Java-programmed card game pairs

    Hi. Can somebody help me out figure out why my program has different outcome every time I run it? Sometimes, the image appears first, sometimes, the buttons do. Help please.Thanks

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class FindingMemo2{
    public static void main(String[] args){
    Memo frame = new Memo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setVisible(true);

    }
    }
    class Memo extends JFrame implements ActionListener{
    Image mypic;
    JLabel label;
    JRadioButton yes,no;
    ButtonGroup radioGroup;
    public Memo(){

    mypic=Toolkit.getDefaultToolkit().getImage("5.jpg" );
    // get screen dimensions
    Toolkit kit = Toolkit.getDefaultToolkit();//returns something of type dimension
    Dimension screenSize = kit.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    // center frame in screen
    setSize(screenWidth, screenHeight);//half the size of whole=screenwidth/2
    //setLocation(screenWidth / 4, screenHeight / 4);//this will be used if screenwidth/2

    Container c= getContentPane();
    c.setLayout(null);
    label=new JLabel("Would You Like to Play?");
    radioGroup=new ButtonGroup();//
    yes=new JRadioButton("Yes", true);//TRUE IF SELECTED
    no=new JRadioButton("No", false);//FALSE IF SELECTED
    //ButtonGroup.addActionListener(this);
    yes.addActionListener(this);
    no.addActionListener(this);
    radioGroup.add(yes);//INSURES THAT ONLY ONE IS CHOSEN
    radioGroup.add(no);
    label.setBounds(400,250,150,50);
    yes.setBounds(380,300,180,20);
    no.setBounds(570,300,200,20);
    c.add(label);//PLACES IN THE CONTAINER
    c.add(yes);//PLACES IN THE CONTAINER
    c.add(no);//PLACES IN THE CONTAINER

    }
    public void paint(Graphics g){//g= acts like a pen
    g.drawImage(mypic, 3,20,this);
    }

    public void actionPerformed(ActionEvent e){
    if(e.getSource()==yes){
    JOptionPane.showMessageDialog(null,"Welcome to Finding Memo!");
    //startGame();
    }else {
    JOptionPane.showMessageDialog(null,"Thanks for Visiting Memo!");
    System.exit(0);
    }

    }



    }
    Last edited by Galore; 10-16-2009 at 04:58 AM.

Similar Threads

  1. Help with creating the game pairs
    By dave141000 in forum New To Java
    Replies: 1
    Last Post: 08-15-2009, 06:25 PM
  2. Creating a Card Game in Java
    By Natrix in forum New To Java
    Replies: 1
    Last Post: 05-05-2009, 05:55 PM
  3. card game Rummy
    By javafox in forum New To Java
    Replies: 4
    Last Post: 03-14-2009, 03:53 PM
  4. A Online Card Game
    By GonzaloP in forum Networking
    Replies: 0
    Last Post: 12-28-2008, 06:37 PM
  5. RSSI calculation using Java Card STK....
    By vickytulla in forum Advanced Java
    Replies: 0
    Last Post: 07-14-2008, 08:56 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
  •