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) {
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 ();
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.
I'm trying to add an image on an undecorated JFrame and make it translucent by adjusting its opacity. The problem is that my Image also becomes translucent.
Here is my code:
package Loading; import javax.swing.*; import java.awt.*; public class TransparentFrame extends JFrame{ public TransparentFrame(){ createAndShowGUI();
[Code] .....
How can i make my image opaque but the frame behind it completely invisible. Why I'm getting serialize class warning in this code? that is:
"The serializable class TransparentFrame does not declare a static final serialVersionUID field of type long"
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.*
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?
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"); }
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.
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));
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
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)
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) .
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?
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;
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();
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.
We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)
These are our instructions:
Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:
[import java.awt.*; import javax.swing.JFrame; public class TicTacToeView extends Rectangle public TicTacToeView(int x, int y, int w, int h) { super(50,60,w,h); this.setBackground(Color.red); JFrame win = new JFrame("Tic Tac Toe"); win.setBounds(10,10,w+100, h+100); win.setLayout(null); win.setVisible(true); win.setBackground(Color.gray);
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tables; import java.util.Date; import javax.swing.table.DefaultTableModel; import javax.swing.JOptionPane; import javax.swing.RowFilter; import javax.swing.table.TableRowSorter;
how to use JFrames and button and so on in Java. I found this video on youtube and followed it along, however even though my program is virtually identical to his, I'm still getting errors.
Here's the video I was watching: Video
And here's my code:
import javax.swing.*; //Imports JFrame and JButton for use import javax.swing.JFrame; import javax.swing.JPanel; import javax.*; import java.awt.*; import java.awt.event.*; public class swing
[code]....
The reason why I'm importing some many things is I'm trying everything to try fix my problem.
He's the error messages I'm getting:
frame2.add(panel); ^ C:UsersWindows 8Documentsswing.java:42: error: illegal start of expression frame2.add(panel);
[code]....
I used to make the button just create another frame without additional labels but I changed it to be even more similar to his program just to rule everything out. Also initially my program varied quite a bit, I've changed everything to be like his. Even without the ";" error I got, I kept telling me I was not allowed have my class as static, even though the guy in the video has it set to static. Also I don't think my "setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);" is working as it doesn't change color.
I think the problem is with my panel, it isn't adding to the frame for some reason.I'm using TextPad7 and I'm using Win8.
C:UsersWindows 8Documentsswing.java:42: error: '(' or '[' expected frame2.add(panel); ^ C:UsersWindows 8Documentsswing.java:42: error: illegal start of expression frame2.add(panel);
[code]....
I would also like to point out that some of the comments are out of date and are referencing the way the program was before I made it just like his. For example I know my second class isn't inheriting the first class.
how to build GUI's with JFrame and I was firstly very confused as to when and what is always needed for any GUI in Java. How do I know everything I need for a GUI? Are there certain things every GUI will need by default?
Additionally below I have a code snippet of when this person used the "this" as an argument to a JButton and Im just really confused for when I can use it and when I can't.
public UIStuff(){ super("Multiple Button Events"); init(); } // end multi-button