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 5 of 5

Thread: Help Pls..

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

    Unhappy Help Pls..

    PHP Code:
    How to resize the "button stop and roll" like this on the picture below 
    When I clicked a start the start button are still true when i clicked a stop the stop button are also still true Boolean
    roll dice.jpg

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    	public class LabEx4 extends JFrame{
     
    	private JLabel rollgame, rid1, rid2, rid3, rid4, rid5, rid6, led1, led2, led3, led4, led5, led6;
    	private JButton Roll, Stop;
    	private StartButtonHandler sbh;
    	private StopButtonHandler stbh;
    	private boolean stop = false;
    	private int pict = 1;
     
     
    	public void Runner(){
    	rollgame = new JLabel("Rolling Dice for Games");
    	rollgame.setFont(new Font("Grease", Font.BOLD, 40));
    	rollgame.setLocation(180, 20);
    	rollgame.setSize(300, 80);
     
    	ImageIcon rd1 = new ImageIcon(
    	getClass().getResource("Dice1.jpg"));
    	rid1 = new JLabel(rd1);
    	rid1.setVisible(true);
     
    	ImageIcon rd2 = new ImageIcon(
    	getClass().getResource("Dice2.jpg"));
    	rid2 = new JLabel(rd2);
    	rid2.setVisible(false);
     
    	ImageIcon rd3 = new ImageIcon(
    	getClass().getResource("Dice3.jpg"));
    	rid3 = new JLabel(rd3);
    	rid3.setVisible(false);
     
    	ImageIcon rd4 = new ImageIcon(
    	getClass().getResource("Dice4.jpg"));
    	rid4 = new JLabel(rd4);
    	rid4.setVisible(false);
     
    	ImageIcon rd5 = new ImageIcon(
    	getClass().getResource("Dice5.jpg"));
    	rid5 = new JLabel(rd5);
    	rid5.setVisible(false);
     
    	ImageIcon rd6 = new ImageIcon(
    	getClass().getResource("Dice6.jpg"));
    	rid6 = new JLabel(rd6);
    	rid6.setVisible(false);
     
    	ImageIcon ld1 = new ImageIcon(
    	getClass().getResource("Dice1.jpg"));
    	led1 = new JLabel(ld1);
    	led1.setVisible(true);
     
    	ImageIcon ld2 = new ImageIcon(
    	getClass().getResource("Dice2.jpg"));
    	led2 = new JLabel(ld2);
    	led2.setVisible(false);
     
    	ImageIcon ld3 = new ImageIcon(
    	getClass().getResource("Dice3.jpg"));
    	led3 = new JLabel(ld3);
    	led3.setVisible(false);
     
    	ImageIcon ld4 = new ImageIcon(
    	getClass().getResource("Dice4.jpg"));
    	led4 = new JLabel(ld4);
    	led4.setVisible(false);
     
    	ImageIcon ld5 = new ImageIcon(
    	getClass().getResource("Dice5.jpg"));
    	led5 = new JLabel(ld5);
    	led5.setVisible(false);
     
    	ImageIcon ld6 = new ImageIcon(
    	getClass().getResource("Dice6.jpg"));
    	led6 = new JLabel(ld6);
    	led6.setVisible(false);
     
    	Container pane = getContentPane();
    	pane.setLayout(new FlowLayout(FlowLayout.CENTER, 40,40));
     
    	JButton Roll = new JButton("ROLL");
    	Roll.setFont(new Font("Georgia", Font.BOLD, 12));
    	Roll.setSize(100,50);
    	sbh = new StartButtonHandler();
    	Roll.addActionListener(sbh);
    	pane.add(Roll);
     
    	JButton Stop = new JButton("STOP");
    	Stop.setFont(new Font("Georgia", Font.BOLD, 12));
    	Stop.setSize(100,50);
    	stbh = new StopButtonHandler();
    	Stop.addActionListener(stbh);
    	pane.add(Stop);
     
    	pane.add(rollgame);
    	pane.add(rid1);
    	pane.add(rid2);
    	pane.add(rid3);
    	pane.add(rid4);
    	pane.add(rid5);
    	pane.add(rid6);
    	pane.add(led1);
    	pane.add(led2);
    	pane.add(led3);
    	pane.add(led4);
    	pane.add(led5);
    	pane.add(led6);
     
    	JPanel pan = new JPanel();
    	pan.setLayout(new FlowLayout(FlowLayout.CENTER, 45,45));
    	pan.add(Roll);
    	pane.add(pan, BorderLayout.CENTER);
    	pan.add(Stop);
     
    	setTitle("Two Roll Dice");
    	setSize(600, 500);
    	setResizable(false);
    	setVisible(true);
    	setDefaultCloseOperation(EXIT_ON_CLOSE);
    	}
    	private class StartButtonHandler implements ActionListener{
    	public void actionPerformed(ActionEvent ev){
    	stop = false;
     
    	Thread to = new Thread(){
    	public void run(){
    	while(!stop){
    	try{
    	if(pict == 1){
    	rid1.setVisible(true);
    	rid2.setVisible(false);
    	rid3.setVisible(false);
    	rid4.setVisible(false);
    	rid5.setVisible(false);
    	rid6.setVisible(false);
    	led1.setVisible(false);
    	led2.setVisible(false);
    	led3.setVisible(false);
    	led4.setVisible(false);
    	led5.setVisible(false);
    	led6.setVisible(true);
    	pict++;
    	sleep(200);
    	}
    	else if(pict == 2){
    	rid1.setVisible(false);
    	rid2.setVisible(true);
    	rid3.setVisible(false);
    	rid4.setVisible(false);
    	rid5.setVisible(false);
    	rid6.setVisible(false);
    	led1.setVisible(false);
    	led2.setVisible(false);
    	led3.setVisible(false);
    	led4.setVisible(false);
    	led5.setVisible(true);
    	led6.setVisible(false);
    	pict++;
    	sleep(200);
    	}
    	else if(pict == 3){
    	rid1.setVisible(false);
    	rid2.setVisible(false);
    	rid3.setVisible(true);
    	rid4.setVisible(false);
    	rid5.setVisible(false);
    	rid6.setVisible(false);
    	led1.setVisible(false);
    	led2.setVisible(false);
    	led3.setVisible(false);
    	led4.setVisible(true);
    	led5.setVisible(false);
    	led6.setVisible(false);
    	pict++;
    	sleep(200);
    	}
    	else if(pict == 4){
    	rid1.setVisible(false);
    	rid2.setVisible(false);
    	rid3.setVisible(false);
    	rid4.setVisible(false);
    	rid5.setVisible(true);
    	rid6.setVisible(false);
    	led1.setVisible(false);
    	led2.setVisible(false);
    	led3.setVisible(true);
    	led4.setVisible(false);
    	led5.setVisible(false);
    	led6.setVisible(false);
    	pict++;
    	sleep(200);
    	}
    	else if(pict == 5){
    	rid1.setVisible(false);
    	rid2.setVisible(false);
    	rid3.setVisible(false);
    	rid4.setVisible(false);
    	rid5.setVisible(true);
    	rid6.setVisible(false);
    	led1.setVisible(false);
    	led2.setVisible(false);
    	led3.setVisible(false);
    	led4.setVisible(false);
    	led5.setVisible(true);
    	led6.setVisible(false);
    	pict++;
    	sleep(200);
    	}
    	else{
    	rid1.setVisible(false);
    	rid2.setVisible(false);
    	rid3.setVisible(false);
    	rid4.setVisible(false);
    	rid5.setVisible(false);
    	rid6.setVisible(true);
    	led1.setVisible(false);
    	led2.setVisible(false);
    	led3.setVisible(false);
    	led4.setVisible(false);
    	led5.setVisible(false);
    	led6.setVisible(true);
    	pict=1;
    	sleep(200);
    	}
    	}
    	catch(InterruptedException e){
    	}
    	}
    	}
    	};
    	to.start();
    	}
    	}
     
    	private class StopButtonHandler implements ActionListener{
    	public void actionPerformed(ActionEvent ev){
    	stop = true;
    	}
    	}
    }

    Main Class
    public class MainEx4 {
     
       public static void main(String [] args){
     
    	javax.swing.SwingUtilities.invokeLater(new Runnable() {
    	public void run() {
    	new LabEx4().Runner();
    	}
    	});
    	}
    }


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

    Default Re: Help Pls..

    start the start button are still true
    What do you mean by "true" for a button? Are you asking about their being enabled? The button class has methods that will change that.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Help Pls..

    Oh I'm sorry, "Roll" I mean... and I mean in the true. When i click a button "Roll". Roll "Button" should be an Unclickable when a program or an animation are running the "stop" button are true boolean or clickable.. Then when you click a button "stop" are the same as of "roll" button that you clicked the stop button are unclickable or false boolean..
    Sorry for my Grammar that you not understand.. Because i am from philippines .. and i will study learn English language..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help Pls..

    "Button" should be an Unclickable
    Read the API doc for the button class. It has a method to disable the button. Also look at the doc for any class that the button class extends.


    New thread at http://www.javaprogrammingforums.com...am-button.html
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Help Pls..

    ok tnx

Similar Threads

  1. HI PLS HELP
    By Virat Pandey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 23rd, 2012, 06:12 AM
  2. pls.pls.pls.help with this
    By izzahmed in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 25th, 2011, 11:30 AM
  3. Pls help me
    By rose_brit3 in forum Loops & Control Statements
    Replies: 3
    Last Post: September 28th, 2010, 09:57 AM
  4. Pls Help
    By randika11 in forum JDBC & Databases
    Replies: 3
    Last Post: July 20th, 2010, 05:52 AM
  5. pls help me
    By sandeep_636338fae in forum Java Theory & Questions
    Replies: 1
    Last Post: January 4th, 2010, 04:03 PM