Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Rolling Dice problem.. How to insert letter in JLabel and Button roll and stop into JFrame

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Location
    philippines
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Rolling Dice problem.. How to insert letter in JLabel and Button roll and stop into JFrame

    I don't know if the code i did are correctly .. please debug


    And how to insert and resize title "Rolling Dice For Games" .
    I want you to set the title and Button roll and stop except the pictures of dice like on the pictures.. plsssssss.. sorry for my english grammar if aren't correctly..
    here's the example picture..roll dice.jpg


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class LabEx4 extends JFrame{
    		private boolean stop = false;
    		private JLabel lbltitle, dice1, dice2;
    		private RollButtonHandler rollHandler;
    		private StopButtonHandler stopHandler;
     
    		public void showWindow(){
    			Container pane = getContentPane();
    			pane.setLayout(new FlowLayout(FlowLayout.CENTER ));
    			pane.add(new JLabel("Rolling Dice for Games"));
    			pane.setFont(new Font("TAHOMA", Font.BOLD, 20));
    			pane.setBackground(Color.white);
     
     
    			JButton roll  = new JButton("ROLL");
    			rollHandler = new RollButtonHandler();
    			roll.addActionListener(rollHandler);
    			roll.setLocation(200,100);
    			roll.setFont(new Font("Tahoma", Font.BOLD, 14));
     
    			JButton stop2  = new JButton("STOP");
    			stopHandler = new StopButtonHandler();
    			stop2.setLocation(400,200);
    			stop2.addActionListener(stopHandler);
     
     
    			setTitle("Two Roll Dice");
    			setSize(600,500);
    			setResizable(false);
    			setLocation(190,50);
    			setVisible(true);
    			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		}
    			private class RollButtonHandler implements ActionListener{
    				public void actionPerformed(ActionEvent evt){
    					stop = false;
     
    					Thread to = new Thread(){
    						public void run(){
    							while(!stop){
     
    								try {
    									sleep(500);
    							}catch(InterruptedException ex){
    								System.out.println("Interrupted");
    							}
     
    							}
    						}
    					};
    				}
    			}
    			private class StopButtonHandler implements ActionListener{
    				public void actionPerformed(ActionEvent evt){
    					stop = true;
    				}
    			}
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Rolling Dice problem.. How to insert letter in JLabel and Button roll and stop into JFrame

    I don't know if the code i did are correctly
    Please explain what the problem is and how you want to change the program.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Dice Rolling Probability - How Do I Start It Off?
    By iAce in forum Java Theory & Questions
    Replies: 11
    Last Post: December 16th, 2012, 10:01 PM
  2. Can't figure out how to roll individual dice.
    By mortiz492 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 19th, 2012, 02:07 PM
  3. Need help coding Dice rolling simulation
    By DavidBowie in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 23rd, 2011, 02:03 PM
  4. Help with creating a dice rolling program in Java
    By lilmiss in forum Object Oriented Programming
    Replies: 4
    Last Post: October 26th, 2011, 09:27 PM
  5. [SOLVED] Dice Rolling Simulation
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 12th, 2011, 06:51 PM