How To Display Players Score In Panel

Jun 19, 2014

So I'm working on this game for a school project and I have 2 problems

1.I do not know how to display the players score in the panel
2.Every single time the console reads the second button I click on as a 0 instead of the number underlining it

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.*;
public class Matchgame extends JPanel implements ActionListener { 
private final JPanel Brd = new JPanel(new BorderLayout(3, 3));

[Code]...

View Replies


ADVERTISEMENT

Creating Leaderboard For Game - Display Top 5 Players

Feb 26, 2014

I'm in the process of building an algorithm for a leaderboard for my game, but now I'm stuck.

- It is a two-player game.
- The leaderboard is supposed to display the top 5 players.
- Scores will be saved to an external .txt file as a reference.

Also, may I add that I still cannot decide if I should only consider the winner's score for the leaderboard, or also the loser's.

For example:

Player 1 is Juliet.
Player 2 is Romeo.

At the end of the match, Juliet's score is greater than Romeo's.

Should I only evaluate Juliet's score for the leaderboard, or both of their scores? As of now my algorithm considers only the winner's score.

As of the moment I'm also only thinking of using JLabel to display the scores, but I'm not sure if this is the most efficient way to do it. I'm considering JTable.

So here's my current algorithm:

1) When the user starts a new match/returns to menu/exits game: (I provided 4 options: new game (scores remain but the board is reset), new match (everything is reset), menu, and exit.)

public class Game
{
//This class also holds the code for the operation of the game
if (event.getSource() == newmatch)//or menu or exit {
if (p1score != 0 || p2score != 0) {
Leaderboard x;

[Code] .....

3) The next step which is I'm highly unsure of is to create an ArrayList for the scores (I'm missing the part about the player's name because well I'm not sure as well how I will approach it) and then sort it, but the problem after that would be how to make the score agree with the player's name, if you get what I mean.

Like for example the scores are:

Anna = 1
Pamela = 5
Gabby = 3
Sorted: 5, 3, 1

Pamela has the highest score, but how will I be able to display her name together with her score?

4) I have a checker which determines if the ArrayList of scores is empty, and if it is, it will automatically display the player's name and score (this is for the first pair of players).

It's something like this:

if (board.isEmpty()){
label1.setText(winnername);
scorelabel1.setText(winnerscore);
} else {
//
}

There's a whole lot of buzz going on and now I don't know how I should proceed.

View Replies View Related

JOptionPane - Display Total Number Of Goals Scored By All Players

May 22, 2014

JOptionPane.showMessageDialog(null,myRoster.totalGoalsScored + " is the total number of goals scored by all the players on the roster");

HOW CAN I CALL THE METHOD totalGoalsScored and display it using JOptionPane

ERROR: CAN NOT FIND SYMBOL

View Replies View Related

Animating Score To Count Up Or Just Displaying Score

May 30, 2014

I am using Eclipse programming for android. I have a game working fine but looking to add a little flare to it. Currently more scoring system just displays the current sore so if your score is 3,000 and you score 300 more it just changes to 3,300.

My question is how can I get the score to count from 3,000 to 3,300 really fast giving it the arcade feel of your score counting up? I tried timers with delays but it gets slowed down and buggy.

View Replies View Related

Swing/AWT/SWT :: Panel From Nested Class Does Not Display

Sep 26, 2014

I have this panel in a nested class in the MainPanel class and it does not display, when I launch the applet, or more like, the two menus "LineColor" and "BackColor" from the nested class ColorPanel do not display .

This is the code:

package ui.panels;
import interfaces.Resettable;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Panel;

[code].....

View Replies View Related

How To Display New Panel With Text Field And Label It

Apr 19, 2014

I want to display a new panel with a text field and a label in it, and add the text from that textfield to an array list each time i press enter. here is what i am trying to do:

public JPanel startStateNoPanel(){
startStateNoPanel = new JPanel(null);
startStateNoPanel.setBackground(Color.YELLOW);
stateNo = new JLabel();
stateNo.setText("Enter Start State Number: ");
stateNo.setBounds(5,40,200,20);

[Code]...

Here is my method to add Panel to Action Panel which is further added to the Frame

public void addPanel(JPanel panel, String name){
ActionPanel.add(panel, name); // there is the card layout on action panel
}

symbolCountPanel is a panel which consists of a text field to take numberOf alphabets

if((symbolCountPanel.isShowing()) && (ex.getSource() == symbolCountF)){
if(!isTextFieldEmpty(symbolCountF)){
new SwingWorker<Void, Void>() {
protected Void doInBackground() throws Exception {
AlphabetCountF.setText(symbolCountF.getText());
setNumberOfAlphabets(Integer.parseInt(symbolCountF.getText())); // setting Number of Alphabets

[Code]....

View Replies View Related

Creating A Score List And High Score List?

Jan 7, 2015

I am creating a program called "Mad Math Machine". This program is to generate random arithmetic questions, with integers ranging from -12 to 12, for the user to answer. The user has three lives. Once they get more than three questions wrong, they run out of lives, and their "score" (the number of questions they answered correctly) is taken.

I have the large chunk of the program (the arithmetic questions and answers) completed. The only part I am stuck on is the scoring system. I believe that arrays would be useful for this task, but I have little idea of where to start. Here is what the scoring list should be able to do:

- It should print out the top ten recent players and their scores.
- A separate list should show the top-two highest scores of all time.

*I didn't think it was relevant, but I can include the program code. Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.*

View Replies View Related

Swing/AWT/SWT :: When Click On Button From Bottom Panel Top Panel Need To Be Redrawn

Apr 1, 2014

When i click on the button from bottom panel, top panel need to be redrawn. But redrawing is not happening. It happens only when resizing the applet.

public class Graphics_Chart(){
public init(){
JScrollPane topPane = new JScrollPane(new ImagePanel2());
topPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
topPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

[code]...

View Replies View Related

Board Of Colors And Players

Sep 14, 2014

My assignment is for a game where there is a board of colors and each player draws a color and moves to that position on the board. It will then output how many cards total in the game it took whichever player to win. If no winner it outputs the number of cards that none won by going through. I attached the file that corresponds with my code.

This is the desired output:

Player 1 won after 7 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 2 won after 4 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 4 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.

import java.io.*;
import java.util.Scanner;
public class ProgrammingAssignment1 {
/**
* @param args the command line arguments
*/
public static int players;
public static int cards;
public static int boardlength;
public static String board;

[Code] .....

The output that I get is:

Player 1 won after 3 cards.
Player 2 won after 8 cards.
No player won after 8 cards.
Player 1 won after 3 cards.
No player won after 6 cards.
Player 2 won after 8 cards.
Player 1 won after 3 cards.
Player 2 won after 8 cards.
Player 1 won after 1 cards.
No player won after 200 cards.
Player 4 won after 100 cards.I guess I'm supposed to set the playerPos[] to -1, but I'm unsure how.

Attached File(s) : colors.in.txt (1.5K)

View Replies View Related

Football Manager - Find Out Optimal First Eleven Amongst 25 Or 30 Players

Nov 26, 2014

I am looking into making a program, that will find out the optimal first eleven (in football or soccer for americans) amongst 25 or 30 players. This is going to apply for a computer game: "Football manager 2015"

I was thinking one class would be the player class that is going to have the variables:

player_number (unique) integer
name string
position (there are eleven positions)
position_rating for each position capable of playing

constructor would be add_player(int number, string name)

and a method would be add_position(position, position_rating)

one player can have more than one positions

another class would be the position

position name (unique) string

that's all I can think of now.

the main class would do a loop

starting with a random or defined position it would do all combinations of every single player into each position.

For example it could start with center forward position. There are 5 available players for that position. Lets say the program picks the first player that is also capable of playing in wide position. If the player is picked for center forward he is not avaialable for wide position.

Then the program would move to the wide position and lets say there are 4 players available. It would pick one.

Once 11 players are selected it would add the 11 ratings.

and start over for a different player in center forward position.

at the end of all loops it would print out the 11 players into their respective positions that got the best score.

View Replies View Related

How To Switch From One Panel To Another Panel

Apr 5, 2014

I have two(panel1 and panel2) panels in a jframe,all three of them are different classes .

In jframe there is a display panel on which the panel1 and panel2 are called and displayed.

now i have a button in panel1 .i want that when i will click on that button panel2 will be displayed or added to the dispalypanel of jframe.

View Replies View Related

If Else Statement Not Allow To Add To The Score

Mar 13, 2014

I'm trying to make a test on java. So far I'm on Question 1 and I'm having this issue. The if else statement won't allow me to add to the score.

class ExamEngine {
static CinReader Cin= new CinReader();
static int Score=0;
public static void main(String[] args) {
System.out.println("Type in your name.");
String name=Cin.readString();

[Code] ....

If I remove the "Score++;" bit, everything is fine. But I need to add to the score when they answer a question right. However, with "Score++;" there, I get this issue: 'else' without 'if'.

Note that this cannot be multiple choice, so that's why I'm using if-else, because I don't think a case system would work here.

Is there a way I can make this work while adding to the score?

View Replies View Related

How To Make The Score Appear In The JFrame

Mar 28, 2014

I was thinking to make a game where a button is appearing in random spots and you have to click it, and once you click it you're score goes up. But I don't know how to make the score appear in the JFrame, and I want the score to update everytime the Button is Clicked.

Here is the code:

Java Code:

package clickmegame;
import java.awt.Dimension;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ClickMeGame {
public static void main(String[] args) {

[Code]...

View Replies View Related

JSP :: Develop Live Score Webpage?

Apr 1, 2014

I am trying to develop a live score webpage using ONLY JSP.

View Replies View Related

Adding Values - How To Get Total Score

Jan 11, 2015

Alright, so i'm working on this and what I want to do is calculate all of the answers when the values of the correct answer = 1 and the incorrect answer = -1 so at the end of the test I can calculate answer + answer2 + answer3 and so on to get a total score...How do I do this? I've been looking online for 3 hours and i'm just stumped.

import java.util.Scanner;
class HorticultureQuiz {
public static void main(String[] args){
String name;
String major;
String confidence;
 
[Code] ....

I thought I could make each answer = to 1 but then I would need a -1 if the answer was incorrect so I tried this.

char answer = sc.nextLine().toLowerCase().charAt(0);
if (answer == 't' || answer == 'T')
answer = 1;
{
System.out.print("Great Job, that is correct!");
} else
answer = -1;
{
System.out.print("Correct answer is false"); }

but that doesn't work!

View Replies View Related

Average Score Assignment Using Netbeans

Sep 27, 2014

I've been working on this same assignment using netbeans. I've completed the exercise and when I run it, it works. However, netbeans still had errors listed in the left hand numerical column and it asks me if I still want to run the program with errors when I hit run?

package TestScores;
import java.util.Scanner;
// Name: Joe
// Date: ........
// Desc: Test Score Averages
 
[code].....

I found this thread while doing a google search trying to find out the error in my code.

View Replies View Related

Counter And Score Variables In Jeopardy Game?

Apr 21, 2015

Most of my code is done for making this Jeopardy game, the only problem I seem to have is to have variables that retain values after going through a loop, in this case the variables counter and score in the method responsePrompt

After going through the 25 questions, the value counter remains at 1, and score is either 1 or -1, nothing more, nothing less. I've had the variables initialized at 1 both inside and outside of the for loop. Full code below just in case it's something outside the method

import java.util.*;
import java.io.*;
public class Project10
{
public static void main(String[] args)
throws java.io.IOException

[Code] ....

View Replies View Related

Test Score Average Program In Java

Jun 16, 2014

I'm working on a homework assignment and I keep getting a compiler message this is the message

GradesAverage.java:44: error: variable totalgrade might not have been initialized
System.out.println("Over all you have " + totalgrade);
^
1 error

The homework is this Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test stores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table:

Test Score Average Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

This is my code

import javax.swing.JOptionPane; // Needed for JOptionPane class
import java.util.Scanner; // Needed for the scanner class
public class GradesAverage
{
public static void main (String[] args)

[code]....

View Replies View Related

Can't Do Table Score Which Updates New Scores After Each Turn

Dec 20, 2014

i am a french student in France and i am studying informatics . For validating my term at the beginning of January i have a projet in JAVA to do called YAHTZEE. It's a game which i have to code WITHOUT USING AN OBJECTS. I already started the coding, i did all the beginning stuff ( to call the number and the names of players, to roll the 5 dices, i made the code for all the scoring points too(rules) ) but i can't do the table score which updates the new scores after each turn ( 3 turns in total) .

View Replies View Related

Store A Number Of Different Value Cards For A Number Of Players?

Feb 18, 2014

i am trying to store a number of different value cards for a number of players. E.g there can be 2 , 4 or more players and each player can have any number of cards.

I have decided to use an arraylist for cards and tried using an array for players. But after coding and reading some information online, i realised that it is not possible to have an array of arraylist.

View Replies View Related

Assigning Empty Score To Strings In Text File

May 27, 2014

I have a txtfile which I read and go through. My question is what are the ways I could do to read a txtfile of words and assign an empty score to each of the word in it. So each word will have a 0 value. Later on I will manipulate the score but for now I want each word to have a 0 score.What I have at the moment is reading a text file full of words eg:

private void readtextfile() {
try {
Scanner rd = new Scanner(
new File("filename"));
List<String> lines = new ArrayList<String>();
while (sc.hasNextLine()) {
lines.add(sc.nextLine());

[code]...

how to make each of the words to have a score of zero 0?

View Replies View Related

Print Inputted Data - Name / Score And Average Using Array

Aug 22, 2014

Conditions : Need to print all the inputted data(name,score) and the average.

import java.util.Scanner;
public class Case2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] score = new int[5];
String[] name = new String[5];
int ave = 0;

[Code] .....

View Replies View Related

Score Board - Constructor Null Pointer Exception

Sep 7, 2014

I'm getting constructor null pointer exception but i don't know what has gone wrong...

private int capacity; // maximum capacity of the board
private double minimum; // minimum distance of the flyer
private SortedLinkedList sortedList;
private int size = 0;
public ScoreBoard() {
capacity = 10;
minimum = 0.0;
sortedList = new SortedLinkedList();

[Code] ....

View Replies View Related

Array Of Scores - Return True If Each Score Is Equal Or Greater Than One Before

Mar 8, 2014

Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.

scoresIncreasing({1, 3, 4}) → true
scoresIncreasing({1, 3, 2}) → false
scoresIncreasing({1, 1, 4}) → true

Java Code:

public boolean scoresIncreasing(int[] scores)
{
for (int i = 0; i< scores.length-1; i++) {
if (scores[i] < scores[i+1] || scores[i] == scores [i+1]) {
return true;
} else {
return false;
}
}
return false;
}

Unsure what the problem is, it will always return True for some reason...

View Replies View Related

Unable To Make Gradebook That Uses Random Number Generator To Give Score

Nov 7, 2014

I`m trying to make a gradebook that uses random number generator to give the score, I also need to implement student numbers and sort everything with a total at the bottom. But I cant figure out how the bubblesorting works. This is my code so far:

package karakterbok;
import static java.lang.Math;
import java.util.Random;
public class Karakterbok {
public static void main(String[] args) {
Random karakterer = new Random();
Random studid = new Random ();

[Code]...

how to sort this using bubblesort?

View Replies View Related

Write A JAVA Program That Will Input 10 Scores And Output Highest And Lowest Score

Jan 9, 2015

1.Write a JAVA program that will input 10 scores and output the Highest and Lowest score.

2.Write a JAVA program that will input the base and power and display the result: Example: Base is 4 Power is 2 the answer is 16 (Note: Math.pow( ) method is not allowed)

3.Write a JAVA program that will input an integer number, and then will output the sum of all inputted numbers. The program will stop in accepting inputs if the user entered 0.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved