Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Rectangle won't draw on: 2012-08-19 16:50:06
Everything works as normal. All of my panels display appropriately, but this rectangle won't show up no matter where I put it.

I haven't tinkered with what you suggested, but I will when I get the chance.
2  Game Development / Newbie & Debugging Questions / Re: Rectangle won't draw on: 2012-08-18 22:37:51
I've been messing with this for a while and I just can't wrap my head around it, the little rectangle won't show up anywhere. I know I'm missing something so simple, but I guess I'm thinking so hard I keep missing it.
3  Game Development / Newbie & Debugging Questions / Re: Rectangle won't draw on: 2012-08-16 21:07:53
How would I go about doing that?

Do I have to call the draw method when the computer returns rock, do I draw the method in my run, or my when I create my JFrames?
4  Game Development / Newbie & Debugging Questions / Re: What else should I know? on: 2012-08-16 18:12:52
I'm in the same boat as you pretty much.

I took a class in programming at school, watched the Bucky tuts, and currently reading Killer Game Programming. They all have taught me a lot, but what has taught me the most is just programming. I've made a few programs with some mild success but right now I'm trying to make just a simple Rock, Paper, Scissors game and it is a lot harder than I initially thought. I find my self having to rifle through countless examples and asking tons of questions.

What I'm doing now, and I suggest to you, is get a copy of Killer Game Programming and read a chapter, after reading a chapter try to master what he is trying to do by creating a program of your own.

5  Game Development / Newbie & Debugging Questions / Rectangle won't draw on: 2012-08-16 17:50:11
I'm trying to draw a simple rectangle whenever the computer returns rock. I'm not sure why this isn't happening, I'm just stumped. I looked through my text box, went online, and performed a couple of searches on the forum and I can't find an answer.

If I make a separate class to draw a rectangle, then just add it in a JPanel in my main class, shouldn't it just pop up?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
import java.awt.*;
import java.awt.event.*;
import java.util.Random;

import javax.swing.*;


public class GamePanel implements ActionListener{
   private boolean isRunning = false;
   int playersco = 0;
   int compsco = 0;
   
   int player;
   int comp;
   String playerroc, playersis, playerpap ;
   String compprint, comproc, comppap, compsis;
   JButton roc, pap, sis;
   JPanel selectpanel, gamtex, compout;
   JLabel playerscore;
   JLabel compscore;
   JLabel compchoice;
   
   public JPanel ContentPane(){
     
      JPanel masterPanel = new JPanel();
      masterPanel.setLayout(null);
     
      gamtex = new JPanel();
      gamtex.setLayout(null);
      gamtex.setLocation(100, 10);
      gamtex.setSize(155,20);
      gamtex.setBackground(Color.yellow);
      masterPanel.add(gamtex);
     
      playerscore = new JLabel(""+ playersco +" Player");
      playerscore.setLocation(0,0);
      playerscore.setSize(90,20);
      playerscore.setHorizontalAlignment(0);
      gamtex.add(playerscore);
     
      compscore = new JLabel(""+compsco+" Computer");
      compscore.setLocation(20,0);
      compscore.setSize(190,20);
      compscore.setHorizontalAlignment(0);
      gamtex.add(compscore);
     
     
     
      compout = new JPanel();
      compout.setLayout(null);
      compout.setLocation(130,35);
      compout.setSize(110,100);
      masterPanel.add(compout);
      //compout.setBackground(Color.DARK_GRAY);
     
      compchoice = new JLabel();
      compchoice.setLocation(0,0);
      compchoice.setSize(85,20);
     
      compout.add(compchoice);
     
     
     
      selectpanel = new JPanel();
      selectpanel.setLayout(null);
      selectpanel.setLocation(0,15);
      selectpanel.setSize(100,190);
      //selectpanel.setBackground(Color.green);
     masterPanel.add(selectpanel);
     
      roc = new JButton("Rock");
      roc.setLocation(10,5);
      roc.setSize(80,30);
      roc.addActionListener(this);
      selectpanel.add(roc);
     
      pap = new JButton("Paper");
      pap.setLocation(10,45);
      pap.setSize(80,30);
      pap.addActionListener(this);
      selectpanel.add(pap);
     
      sis = new JButton("Sissors");
      sis.setLocation(10,85);
      sis.setSize(80,30);
      sis.addActionListener(this);
      selectpanel.add(sis);
     
      masterPanel.setOpaque(true);
      return masterPanel;
   

   
   }
   

   
   public void actionPerformed(ActionEvent e){
     
      if(e.getSource() == roc ){
         
         player = 1;
         
      }else if(e.getSource() == pap){
     
         player = 2;
         
      }else if(e.getSource() == sis){
         
         player = 3;
         
      }
     
      comprandom();
      gamebrain();
     
   }
   
   
   public void comprandom(){

   
     
      Random randomGenerator = new Random();
       int randomInt = randomGenerator.nextInt(3);
       if(randomInt == 1){
         
          comp = 4;
          compchoice.setText("Sicssors!");
         
       }else if(randomInt == 2){
         
          comp = 5 ;
         
          compchoice.setText("Rock!");
          RockComponent component = new RockComponent();
          compout.add(component);
       }else
       {
          comp = 6 ;
         compchoice.setText("Paper!");

       }
   }
   

     
   public void gamebrain()
   {
      if((player == 1 && comp == 4) ||( player == 3 && comp == 6)||( player == 2 &&  comp ==5 )){
         playersco = playersco +1;
         playerscore.setText(""+ playersco +" Player");
         
      }else if( (player == 1 && comp == 5) ||(player == 2 && comp == 6) ||(player == 3 && comp == 4) ){
     
         playerscore.setText(""+ playersco +" Player");
      }
     
      else{
         compscore.setText(""+ compsco +" Computer");
         compsco = compsco + 1;}
   }

   
   
   private void showgame(){
     
      JFrame frame = new JFrame("Rock, Paper, Scissors");
      frame.setContentPane(ContentPane());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(280, 190);
     
     
      frame.setVisible(true);
     
   }



   public void run() {
   
   
      showgame();
      while(isRunning){
         
         
         
               
         try{
         Thread.sleep(20);
           
         }catch(Exception e){}
         
   
     
     
      }
   }
   
   public GamePanel(){
      isRunning = true;
      run();
   }
   public static void main(String[] args){

      new GamePanel();
       }
             
   }
       
   
         
   
   

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import javax.swing.JComponent;


public class RockComponent extends JComponent{
   public void paintComponent(Graphics g)
   {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
     
      Rectangle box = new Rectangle (5,10, 100,100);
     
      g2.setColor(Color.blue);
      g2.draw(box);
   }
}


I want to thank everyone again. Thank all you for being so patient and respectful and providing such clear and well thought out answers. I can't wait to get better at programming in Java so I can give back to the community.
6  Game Development / Newbie & Debugging Questions / Re: While loop help on: 2012-08-15 17:31:31
Thanks everyone for the input. I was able to get my game running the way that I want it to and I took out all of the statics that shouldn't of been, but I'm still having a problem with my loop. My loop right now is empty, as I implemented all of the actions of the game into my ActionPerformed method. What I would like to know is can I get my game running through a Loop? I ready the tutorials and played around and just got things going in infinite loops.

Also, I'm planning to add some very, very simple graphics to the game. If I can't use my current loop for my game logic and updates can I use this loop for the graphics?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.*;


public class GamePanel implements ActionListener{
   private boolean isRunning = false;
   int playersco = 0;
   int compsco = 0;
   
   int player;
   int comp;
   String playerroc, playersis, playerpap ;
   String compprint, comproc, comppap, compsis;
   JButton roc, pap, sis;
   JPanel selectpanel, gamtex, compout;
   JLabel playerscore;
   JLabel compscore;
   JLabel compchoice;
   
   public JPanel ContentPane(){
     
      JPanel masterPanel = new JPanel();
      masterPanel.setLayout(null);
     
      gamtex = new JPanel();
      gamtex.setLayout(null);
      gamtex.setLocation(100, 10);
      gamtex.setSize(155,20);
      gamtex.setBackground(Color.yellow);
      masterPanel.add(gamtex);
     
      playerscore = new JLabel(""+ playersco +" Player");
      playerscore.setLocation(0,0);
      playerscore.setSize(90,20);
      playerscore.setHorizontalAlignment(0);
      gamtex.add(playerscore);
     
      compscore = new JLabel(""+compsco+" Computer");
      compscore.setLocation(20,0);
      compscore.setSize(190,20);
      compscore.setHorizontalAlignment(0);
      gamtex.add(compscore);
     
      compout = new JPanel();
      compout.setLayout(null);
      compout.setLocation(130,35);
      compout.setSize(110,100);
      masterPanel.add(compout);
      //compout.setBackground(Color.DARK_GRAY);
     
      compchoice = new JLabel(compprint);
      compchoice.setLocation(0,0);
      compchoice.setSize(85,20);
      compout.add(compchoice);
     
      selectpanel = new JPanel();
      selectpanel.setLayout(null);
      selectpanel.setLocation(0,15);
      selectpanel.setSize(100,190);
      //selectpanel.setBackground(Color.green);
     masterPanel.add(selectpanel);
     
      roc = new JButton("Rock");
      roc.setLocation(10,5);
      roc.setSize(80,30);
      roc.addActionListener(this);
      selectpanel.add(roc);
     
      pap = new JButton("Paper");
      pap.setLocation(10,45);
      pap.setSize(80,30);
      pap.addActionListener(this);
      selectpanel.add(pap);
     
      sis = new JButton("Sissors");
      sis.setLocation(10,85);
      sis.setSize(80,30);
      sis.addActionListener(this);
      selectpanel.add(sis);
     
      masterPanel.setOpaque(true);
      return masterPanel;
   

   
   }
   

   
   public void actionPerformed(ActionEvent e){
     
      if(e.getSource() == roc ){
         
         player = 1;
         
      }else if(e.getSource() == pap){
     
         player = 2;
         
      }else if(e.getSource() == sis){
         
         player = 3;
         
      }
     
      comprandom();
      gamebrain();
     
   }
   
   
   public void comprandom(){
     
      Random randomGenerator = new Random();
       int randomInt = randomGenerator.nextInt(3);
       if(randomInt == 1){
         
          comp = 4;
          compchoice.setText("Sicssors!");
         
       }else if(randomInt == 2){
         
          comp = 5 ;
          compchoice.setText("Rock!");
         
       }else
       {
          comp = 6 ;
         compchoice.setText("Paper!");
      }
   }
   

     
   public void gamebrain()
   {
      if((player == 1 && comp == 4) ||( player == 3 && comp == 6)||( player == 2 &&  comp ==5 )){
         playersco = playersco +1;
         playerscore.setText(""+ playersco +" Player");
     
      }else if( (player == 1 && comp == 5) ||(player == 2 && comp == 6) ||(player == 3 && comp == 4) ){
     
         playerscore.setText(""+ playersco +" Player");
      }
     
      else{
         compscore.setText(""+ compsco +" Computer");
         compsco = compsco + 1;}
   }

   
   private void showgame(){
     
      JFrame frame = new JFrame("Rock, Paper, Scissors");
      frame.setContentPane(ContentPane());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(280, 190);
      frame.setVisible(true);
     
   }
   
   public void run() {
   
     
      showgame();
      while(isRunning){
   
         
         
         
         
      try{
         Thread.sleep(20);
           
         }catch(Exception e){}
   }
   }
   
   public GamePanel(){
      isRunning = true;
      run();
   }
   public static void main(String[] args){

      new GamePanel();
       }
             
   }
       


Ok, time for me to get back to messin' around!
7  Game Development / Newbie & Debugging Questions / Re: While loop help on: 2012-08-14 14:10:47
Whoa, I never expected such detailed responses. Thank you guys for the clearly and well explained answers! But, what is this argument between non-static, static, and who cares stuff? I know Micheal Scott feels strongly against the whole it doesn't matter approach.

I reason why I choose to use statics everywhere was because Eclipse told me to do it  Cry
I actually had no idea why it wanted me to do it, but after listening to Eclipse's suggestions my program would run without any problems so I thought I was doing good. I guess I was super wrong.

The reason why I made player == 0, ReBirth, was so that the game would start the player off with nothing and then as soon as the player chose something it would change it's value, then the game would compare that value against the computers randomized value. But, nope that isn't true. Thanks for pointing that out, because I know it would of caused a headache later.
8  Game Development / Newbie & Debugging Questions / While loop help on: 2012-08-14 00:54:47
Hey everyone, I'm trying to make a simple rock, paper, scissors game using JButtons and a simple random AI. I believe I have everything in order but the order of execution in my main. I'm trying to display the games options, wait for the user to select an option, next have the computer randomly select an option, then have the game compare the two choices then see who has won and display a score on the top of the window.

I think I need to tackle this problem with a nested while loops. I think I need to create a Boolean for my first while loop so that the program runs normally and then have my second while look wait for input from the user to execute the rest of the code. I've been stumped for some days so I thought I ask for help. If someone could point me the right direction I would be very appreciative!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.*;


public class GamePanel implements ActionListener{
   
   static int playersco = 0;
   static int compsco = 0;
   
   static int player = 0;
   static int comp;
   String playerroc, playersis, playerpap ;
   static String compprint, comproc, comppap, compsis;
   JButton roc, pap, sis;
   JPanel selectpanel, gamtex, compout;
   static JLabel playerscore;
   JLabel compscore;
   JLabel compchoice;
   
   public JPanel ContentPane(){
     
      JPanel masterPanel = new JPanel();
      masterPanel.setLayout(null);
     
      gamtex = new JPanel();
      gamtex.setLayout(null);
      gamtex.setLocation(100, 10);
      gamtex.setSize(155,20);
      gamtex.setBackground(Color.yellow);
      masterPanel.add(gamtex);
     
      playerscore = new JLabel(""+ playersco +" Player");
      playerscore.setLocation(0,0);
      playerscore.setSize(90,20);
      playerscore.setHorizontalAlignment(0);
      gamtex.add(playerscore);
     
      compscore = new JLabel(""+compsco+" Computer");
      compscore.setLocation(20,0);
      compscore.setSize(190,20);
      compscore.setHorizontalAlignment(0);
      gamtex.add(compscore);
     
      compout = new JPanel();
      compout.setLayout(null);
      compout.setLocation(130,35);
      compout.setSize(110,100);
      masterPanel.add(compout);
      //compout.setBackground(Color.DARK_GRAY);
     
      compchoice = new JLabel(compprint);
      compchoice.setLocation(0,0);
      compchoice.setSize(85,20);
      compout.add(compchoice);
     
      selectpanel = new JPanel();
      selectpanel.setLayout(null);
      selectpanel.setLocation(0,15);
      selectpanel.setSize(100,190);
      //selectpanel.setBackground(Color.green);
     masterPanel.add(selectpanel);
     
      roc = new JButton("Rock");
      roc.setLocation(10,5);
      roc.setSize(80,30);
      roc.addActionListener(this);
      selectpanel.add(roc);
     
      pap = new JButton("Paper");
      pap.setLocation(10,45);
      pap.setSize(80,30);
      pap.addActionListener(this);
      selectpanel.add(pap);
     
      sis = new JButton("Sissors");
      sis.setLocation(10,85);
      sis.setSize(80,30);
      sis.addActionListener(this);
      selectpanel.add(sis);
     
      masterPanel.setOpaque(true);
      return masterPanel;
   }
   
   public void actionPerformed(ActionEvent e){
     
      if(e.getSource() == roc ){
         
         player = 1;
         
      }else if(e.getSource() == pap){
     
         player = 2;
         
      }else if(e.getSource() == sis){
         
         player = 3;
         
      }
     
   
   }
   
   
   public static  void comprandom(){
     
      Random randomGenerator = new Random();
       int randomInt = randomGenerator.nextInt(3);
       if(randomInt == 1){
         
          comp = 4;
          compprint = "Sissors!";
         
       }else if(randomInt == 2){
         
          comp = 5 ;
          compprint = "Rock!";
         
       }else
       {
          comp = 6 ;
          compprint = "Paper!";
         
       }
   }
   

     
   public static  void gamebrain()
   {
      if(player == 1 && comp == 4 ){
         playersco = playersco +1;
         playerscore.setText(""+ playersco +" Player");
      }else if( player == 2 &&  comp == 5) {
         playersco = playersco +1;
         playerscore.setText(""+ playersco +" Player");
      }else if( player == 3 && comp == 6){
         playersco = playersco +1;
         playerscore.setText(""+ playersco +" Player");
      }else{compsco = compsco + 1;}
   }

   
   private static void showgame(){
     
      JFrame frame = new JFrame("Rock, Paper, Sissors");
     
      GamePanel show = new GamePanel();
      frame.setContentPane(show.ContentPane());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(280, 190);
      frame.setVisible(true);
     
   }
   
   public static void main(String[] args){
     
   while(){
       showgame();
       
       while(!(player == 0)){
             gamebrain();
               comprandom();
       }
             
   }
       
     
         
   
   }


}
9  Game Development / Newbie & Debugging Questions / Re: Help with non-working JButton on: 2012-08-10 23:39:18
Hahaha oh man, thanks a ton for the speedy answer. Everything is working as it should. Once again, Thank you coltonoscopy!
10  Game Development / Newbie & Debugging Questions / Help with non-working JButton on: 2012-08-10 22:22:44
Hello I'm new to the forum, I wanted to make a proper introduction but I can't find the right place to make it Huh

I'm having some trouble with my JButtons. I'm trying to make a simple rock-paper-scissors game where the player picks either rock, paper, or scissors, but for some reason my JButtons for the user to pick won't work. For right now I just want the player score to increase by one whenever the user clicks on one of the buttons. I know this is very newbie stuff but I've gone over the code a hundred times and I just can't figure out whats wrong. Thanks in advance.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.*;


public class GamePanel implements ActionListener{
   
   int playersco = 0;
   static int compsco = 0;
   
   
   
   String playerroc, playersis, playerpap, player;
   static String compprint, comproc, comppap, compsis, comp;
   JButton roc, pap, sis;
   JPanel selectpanel, gamtex, compout;
   JLabel playerscore, compscore, compchoice;
   
   public JPanel ContentPane(){
     
      JPanel masterPanel = new JPanel();
      masterPanel.setLayout(null);
     
      gamtex = new JPanel();
      gamtex.setLayout(null);
      gamtex.setLocation(100, 10);
      gamtex.setSize(155,20);
      gamtex.setBackground(Color.yellow);
      masterPanel.add(gamtex);
     
      playerscore = new JLabel(""+ playersco +" Player");
      playerscore.setLocation(0,0);
      playerscore.setSize(90,20);
      playerscore.setHorizontalAlignment(0);
      gamtex.add(playerscore);
     
      compscore = new JLabel(""+compsco+" Computer");
      compscore.setLocation(20,0);
      compscore.setSize(190,20);
      compscore.setHorizontalAlignment(0);
      gamtex.add(compscore);
     
      compout = new JPanel();
      compout.setLayout(null);
      compout.setLocation(130,35);
      compout.setSize(110,100);
      masterPanel.add(compout);
      //compout.setBackground(Color.DARK_GRAY);
     
      compchoice = new JLabel(compprint);
      compchoice.setLocation(0,0);
      compchoice.setSize(85,20);
      compout.add(compchoice);
     
      selectpanel = new JPanel();
      selectpanel.setLayout(null);
      selectpanel.setLocation(0,15);
      selectpanel.setSize(100,190);
      //selectpanel.setBackground(Color.green);
     masterPanel.add(selectpanel);
     
      roc = new JButton("Rock");
      roc.setLocation(10,5);
      roc.setSize(80,30);
      roc.addActionListener(this);
      selectpanel.add(roc);
     
      pap = new JButton("Paper");
      pap.setLocation(10,45);
      pap.setSize(80,30);
      pap.addActionListener(this);
      selectpanel.add(pap);
     
      sis = new JButton("Sissors");
      sis.setLocation(10,85);
      sis.setSize(80,30);
      sis.addActionListener(this);
      selectpanel.add(sis);
     
      masterPanel.setOpaque(true);
      return masterPanel;
   }
   
   public void actionPerformed(ActionEvent e){
     
      if(e.getSource() == roc ){
         playersco = playersco +1;
         player = playerroc;
      }else if(e.getSource() == pap){
         playersco = playersco +1;
         player = playerpap;
      }else if(e.getSource() == sis){
         playersco = playersco +1;
         player = playersis;
      }
     
   
   }
   
   
   public static  void comprandom(){
     
      Random randomGenerator = new Random();
       int randomInt = randomGenerator.nextInt(3);
       if(randomInt == 1){
         
          comp = compsis;
          compprint = "Sissors!";
         compsco = compsco+1;
       }else if(randomInt == 2){
         
          comp = comproc ;
          compprint = "Rock!";
         compsco = compsco+1;
       }else
       {
          comp = comppap ;
          compprint = "Paper!";
         compsco = compsco + 1;
       }
   }
     
   

   
   private static void showgame(){
     
      JFrame frame = new JFrame("Rock, Paper, Sissors");
     
      GamePanel show = new GamePanel();
      frame.setContentPane(show.ContentPane());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(280, 190);
      frame.setVisible(true);
     
   }
   
   public static void main(String[] args){
     
      SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                  comprandom();
               showgame();
               
             
            }
        });
     
         
   
   }


}
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!