Computer Programming

Shoot the breeze with other Olympians.
User avatar
binary010101
Member
Member
Posts: 406
Joined: Thu Apr 19, 2007 12:51 pm
Division: Grad
State: PA
Has thanked: 0
Been thanked: 0

Computer Programming

Post by binary010101 »

Anybody here good at programming in java? I could use some help with a program.
Image ...NOT Communist.

Dual-Booting Windows 7 and Ubuntu 9.10

THE GAME.

"Mentat, solve thyself." ~ Dune
I follow the Path of the Beam.
andrewwski
Admin Emeritus
Admin Emeritus
Posts: 961
Joined: Fri Jan 12, 2007 7:36 pm
Division: Grad
Has thanked: 0
Been thanked: 17 times

Re: Computer Programming

Post by andrewwski »

Eh, wouldn't call myself good but maybe I can help. Took AP CS last year.
User avatar
binary010101
Member
Member
Posts: 406
Joined: Thu Apr 19, 2007 12:51 pm
Division: Grad
State: PA
Has thanked: 0
Been thanked: 0

Re: Computer Programming

Post by binary010101 »

I have to make a "dice" class that will draw the dice, and I'm too lazy to use Turtle Graphics (is that the problem?) and I'd like to figure out how the make dice "pause" after every roll if I use the graphics class.
Image ...NOT Communist.

Dual-Booting Windows 7 and Ubuntu 9.10

THE GAME.

"Mentat, solve thyself." ~ Dune
I follow the Path of the Beam.
andrewwski
Admin Emeritus
Admin Emeritus
Posts: 961
Joined: Fri Jan 12, 2007 7:36 pm
Division: Grad
Has thanked: 0
Been thanked: 17 times

Re: Computer Programming

Post by andrewwski »

Oh god I hated drawing and graphics.

What code are you working with?
User avatar
binary010101
Member
Member
Posts: 406
Joined: Thu Apr 19, 2007 12:51 pm
Division: Grad
State: PA
Has thanked: 0
Been thanked: 0

Re: Computer Programming

Post by binary010101 »

Should I post it here, or something?
Image ...NOT Communist.

Dual-Booting Windows 7 and Ubuntu 9.10

THE GAME.

"Mentat, solve thyself." ~ Dune
I follow the Path of the Beam.
andrewwski
Admin Emeritus
Admin Emeritus
Posts: 961
Joined: Fri Jan 12, 2007 7:36 pm
Division: Grad
Has thanked: 0
Been thanked: 17 times

Re: Computer Programming

Post by andrewwski »

Sure. Try the code tags to make it more readable.
User avatar
binary010101
Member
Member
Posts: 406
Joined: Thu Apr 19, 2007 12:51 pm
Division: Grad
State: PA
Has thanked: 0
Been thanked: 0

Re: Computer Programming

Post by binary010101 »

Code tags?
(I have no idea what they are)

Comments, maybe?
Image ...NOT Communist.

Dual-Booting Windows 7 and Ubuntu 9.10

THE GAME.

"Mentat, solve thyself." ~ Dune
I follow the Path of the Beam.
andrewwski
Admin Emeritus
Admin Emeritus
Posts: 961
Joined: Fri Jan 12, 2007 7:36 pm
Division: Grad
Has thanked: 0
Been thanked: 17 times

Re: Computer Programming

Post by andrewwski »

When you post a reply, the fifth button from the left is the code tags. Encase the code in this and it shows up as follows:

Code: Select all

 public class HelloWorld
 {
 	public static void main (String[] args)
 	{
 
 		System.out.println("Hello, world!");
 
 	}
 
 }
instead of this:

public class HelloWorld
{
public static void main (String[] args)
{

System.out.println("Hello, world!");

}

}
User avatar
binary010101
Member
Member
Posts: 406
Joined: Thu Apr 19, 2007 12:51 pm
Division: Grad
State: PA
Has thanked: 0
Been thanked: 0

Re: Computer Programming

Post by binary010101 »

Dice class: (haven't drawn "6" dice yet)

Code: Select all

import java.util.Random;
import java.awt.*;
import BreezySwing.*;

public class Dice extends GBPanel{
	private int number;
	private int number2;
	private Random rng = new Random();
	private Graphics g;
	private int modr = 200;
	private int modr2 = 2;
	public Boolean betted = false;
	
	public Dice(){
		number = 0;
	}
	
	public void paint(Graphics g){
		if(betted == true){
			repaint();
			super.paintComponent(g);
			draw(g);
			betted = false;
		}
	}
	
	public void bettedTrue(){
		betted = true;
	}
	
	private void draw(Graphics g){
		number = rng.nextInt(6) + 1;
		number2 = rng.nextInt(6) + 1;
		
		g.drawLine(20,20,220,20);
		g.drawLine(20,20,20,220);
		g.drawLine(20,20,110,110);
		g.drawLine(220,20,310,110);
		g.drawLine(20,220,110,310);
		g.drawRect(110,110,200,200);
		g.drawString("Dice 1", 195, 330);
		
		g.drawLine(420,20,620,20);
		g.drawLine(420,20,420,220);
		g.drawLine(420,20,510,110);
		g.drawLine(620,20,710,110);
		g.drawLine(420,220,510,310);
		g.drawRect(510,110,200,200);
		g.drawString("Dice 2", 600, 330);
		
		if(number == 1){
			g.fillOval(190,190,40,40);
			g.fillOval(87,110,16,30);
			g.fillOval(57,150,16,30);
			g.fillOval(27,190,16,30);
			g.fillOval(110,87,30,16);
			g.fillOval(190,27,30,16);
		}
		else if(number == 2){
			g.fillOval(123,123,40,40);
			g.fillOval(257,257,40,40);
			g.fillOval(57,150,16,30);
			g.fillOval(110,87,30,16);
			g.fillOval(150,57,30,16);
			g.fillOval(190,27,30,16);
		}
		else if(number == 3){
			g.fillOval(123,255,40,40);
			g.fillOval(189,189,40,40);
			g.fillOval(255,123,40,40);
			g.fillOval(150,57,30,16);
			g.fillOval(87,110,16,30);
			g.fillOval(27,190,16,30);
		}
		else if(number == 4){
			g.fillOval(123,123,40,40);
			g.fillOval(257,257,40,40);
			g.fillOval(257,123,40,40);
			g.fillOval(123,257,40,40);
			g.fillOval(87,110,16,30);
			g.fillOval(32,190,16,30);
			g.fillOval(115,87,30,16);
			g.fillOval(181,87,30,16);
			g.fillOval(242,87,30,16);
			g.fillOval(58,27,30,16);
			g.fillOval(124,27,30,16);
			g.fillOval(190,27,30,16);
		}
		else if(number == 5){
			g.fillOval(123,123,40,40);
			g.fillOval(257,257,40,40);
			g.fillOval(257,123,40,40);
			g.fillOval(123,257,40,40);
			g.fillOval(189,189,40,40);
			g.fillOval(58,27,30,16);
			g.fillOval(190,27,30,16);
			g.fillOval(115,87,30,16);
			g.fillOval(242,87,30,16);
			g.fillOval(57,150,16,30);
		}
		
		if(number2 == 1){
			g.fillOval(590,190,40,40);
			g.fillOval(487,110,16,30);
			g.fillOval(457,150,16,30);
			g.fillOval(427,190,16,30);
			g.fillOval(510,87,30,16);
			g.fillOval(590,27,30,16);
		}
		else if(number2 == 2){
			g.fillOval(523,123,40,40);
			g.fillOval(657,257,40,40);
			g.fillOval(457,150,16,30);
			g.fillOval(510,87,30,16);
			g.fillOval(550,57,30,16);
			g.fillOval(590,27,30,16);
		}
		else if(number2 == 3){
			g.fillOval(523,255,40,40);
			g.fillOval(589,189,40,40);
			g.fillOval(655,123,40,40);
			g.fillOval(550,57,30,16);
			g.fillOval(487,110,16,30);
			g.fillOval(427,190,16,30);
		}
		else if(number2 == 4){
			g.fillOval(523,123,40,40);
			g.fillOval(657,257,40,40);
			g.fillOval(657,123,40,40);
			g.fillOval(523,257,40,40);
			g.fillOval(487,110,16,30);
			g.fillOval(432,190,16,30);
			g.fillOval(515,87,30,16);
			g.fillOval(581,87,30,16);
			g.fillOval(642,87,30,16);
			g.fillOval(458,27,30,16);
			g.fillOval(524,27,30,16);
			g.fillOval(590,27,30,16);
		}
		else if(number == 5){
			g.fillOval(523,123,40,40);
			g.fillOval(657,257,40,40);
			g.fillOval(657,123,40,40);
			g.fillOval(523,257,40,40);
			g.fillOval(589,189,40,40);
			g.fillOval(458,27,30,16);
			g.fillOval(590,27,30,16);
			g.fillOval(515,87,30,16);
			g.fillOval(642,87,30,16);
			g.fillOval(457,150,16,30);
		}
	}
}
"Activator class":

Code: Select all

import java.awt.*;
import javax.swing.*;
import BreezySwing.*;
import TerminalIO.KeyboardReader;

public class LuckySevens extends GBFrame{
	private GBPanel p;
	private JMenuItem betMI, cashOutMI, reportMI;
	private String b;
	private Integer i;
	private int bet;
	private Graphics g;
	private Dice dice = new Dice();
	int choice;
	
	//TODO:  Fix Dice problem (stop between generations)
	
	public LuckySevens(){
		p = addPanel(dice,1,1,1,1);
		betMI     = addMenuItem("Action", "Bet Now");
		cashOutMI = addMenuItem("Action", "Cash Out");
		reportMI  = addMenuItem("Action", "Earnings Report");
	}
	public void menuItemSelected(JMenuItem mi){
		if(mi == betMI){
			b = JOptionPane.showInputDialog("How much do you want to bet?");
			bet = i.parseInt(b);
			System.out.println(bet);
			dice.bettedTrue();
		}
		else if(mi == cashOutMI){
			System.exit(0);
		}
		else if(mi == reportMI){
			
		}
	}
    public static void main(String[] args) {
		LuckySevens theGUI = new LuckySevens();
		
		theGUI.setSize(750,400);
		theGUI.setVisible(true);
		theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
}
Image ...NOT Communist.

Dual-Booting Windows 7 and Ubuntu 9.10

THE GAME.

"Mentat, solve thyself." ~ Dune
I follow the Path of the Beam.
andrewwski
Admin Emeritus
Admin Emeritus
Posts: 961
Joined: Fri Jan 12, 2007 7:36 pm
Division: Grad
Has thanked: 0
Been thanked: 17 times

Re: Computer Programming

Post by andrewwski »

OK, so what do the classes do? "Dice" draws the dice, correct?

"Activator" rolls the dice? You run Activator, I assume?

Return to “General Chat”