I am coding a game and I am trying to implement a pause and unpause button. in the BoardPanel class I've added the button's 'p' and 'o' to game.wait() and game.notify() (main code is in game class). however the game.wait is having issues and even if i throw interrupted exception or try/catch it doesn't work. I'd like to code it to a single button if at all possible.
I've been learning Java in school for lika a year now. Our teacher wanted us to make a game called "Game of Life" .Now it's not very optimized because the only type of GUI we know how to make it with JButtons so if I want a 100x100 grid that means the program has to load 10000 buttons and change text and color on them which I can imagen cause lags and so on but if we ignore that lagg our teacher wanted us to make it loop-able and well I kinda succeeded but the only problem is that I can't get it to wait between every loop so if I tell the program to loop 100 times, the program processes that and that takes forever and then updates the board and sometimes it takes forever and sometimes you cant even see the "cells" moving. Is it possible to get my program to loop and if so how? Here is the code:
By using FileReader, FileWriter and their constituents, I am creating a file to contain employee information ( name, age, hours, etc. ). The user is to input all of the data on a single line and we were asked to implement StringTokenizer to assign that data to the file. I have never used the StringTokenizer before, but I have a rough idea how it is to function. I used pw.println to test what I have so far, now I would like to let the user build the initial file with the "first employees" of the company, and then view the file, and then go back and append new employee data to that same file. My question is, how can I take the user input as a StringTokenizer and add that to the file?
In the for loop below, I thought I would see if it would work, but it does not. The loop only executes once and does not allow me to enter data.
public class Records { public static void main(String [] args) throws IOException { Scanner input = new Scanner(System.in); FileWriter fw = new FileWriter("dbs3.java"); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw); System.out.println("NEW EMPLOYEE DATA SHEET"); System.out.print("Number of new employees: "); int number = input.nextInt();
What I want to do is very clear, just play sound and pause it. The problem is that I can't pause the music. When I click the pause button music keeps playing .I have been working on for 2 hours. I can't find the mistake; what am I doing wrong?
public class MainC extends JFrame implements Runnable,ActionListener { private JPanel contentPane; private JTextField txtname; JButton btnopen; JButton btnSave; JButton btnplay;
Here I want to make a simple program where a Ball keep bouncing forever, then I add a MouseClick Listener to stop and resume thread (I mean, to stop moving Ball and to resume again). The problem is I can stop the thread using wait(), But I can not resume it. Below is the code
public class TestResumePauseBall { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public synchronized void run() { Field aField = new Field();
[code]....
At first I think that notify() must be called from another active thread. So I add a 'class Timing implements Runnable'. Then I call notifyAll() from class Timing. But still it was failed.
After wait() called on Ball's thread, the whole frame also freeze. I can not understand why this happen?
If this test success, I will add 1 one more ball and add keyboard keys as controller of ball's movement.
Example : I have code and name but my code must start with the first letter of the inputed name if the 2 input is match it will be inserted into database
code = "A"001 name ="Angela" = success this will inserted into database
else
code ="B"002 name="Angela" =failed this will not inserted into database
else
code="A"003 name="Andy" =success still accepts the input cause they have diff code number
What I am thinking on this was compare the code the name? if == it will be inserted but how do i get the 1st letter of the input name?
In my card game applet I have to play some music and the user must have the ability to play, stop and pause the song using buttons. I got the play and stop to work easy but I'm unable to add the pause option/method.
why exactly this isn't printing out the correct way.I'm supposed to print out 100 elements from an array but assign them random integers between 0 and 9.I've tried troubleshooting the issue and when I do it seems i'm only getting one element assigned.
public class Exercise_6_7{ public static void main(String[] args){ int[] counts = new int[100]; for(int i=0; i<counts.length; i++){ counts[i] = (int)(Math.random()*10);
When I click on "Clean and Build" NetBeans generates a .jar file and inside the folder "dist" it add a directory called "lib" with all the java libraries used to implement the program. I would like to achieve with this IDE an unique .jar file that includes everything you need such as Eclipse does by default. Is it possible?
Is there a way to multiply two single arrays in which the corresponding iteration from one array multiplies with the corresponding iteration from the second array. For example say you have array1[] and array2[]. Each array has a length of 5. Is there a way to multiply array1[0] by array2[0] and array1[1] by array2[1] and so on.... without having to actually write out the equation of array1[0] + array2[0] = someValue for all iterations of the two arrays?
i'm currently going over single linked list, and i'm coming across an error which i do not know how to get by. I'm using single linked list for now just for study purposes, then i would move on to double.
Error: No enclosing instance of type LList is accessible. Must qualify the allocation with an enclosing instance of type LList (e.g. x.new A() where x is an instance of LList).
public class LList { private static class Node<E>{ private E data; private Node<E> next;
i'm currently studying over single linkedLists and i'm just writing various methods for it. One method i'm currently stuck on is writing a remove method where it returns a boolean true if its found and it will delete it, and false if the target isn't found. My problem is that it always comes up as flase and i know that the target is in the linked list. Here is the code for my method.
i want to know how i can add more than one frame in a single frame means main window or frame will be constant and only components will be chang or vary as in a software or game .
I want to have two threads running in my class, one will be downloading info from a website then putting the thread to sleep for a little bit, then repeating. The other will be sending information to a website then putting the thread to sleep for a little bit, then repeating. Is it possible to do this in my main class? I already have one thread using run() for downloading the info and sleeping can i make another?
I have a project which has a set of configuration files, where each configuration file represents an environment specific configurations. In other words, I have 3 environments, development, staging, and production. The configuration for each environment is different, e.g. DB name, url etc.
Whenever I want to deploy the same code, on each environment, I have to manually generate environment specific .war file, so that it has environment specific configuration file in it.
What I am looking for is a kind of solution where i have to compile only once in maven and it generates only one .war file, which I can use on every environment. In other words, i want the environment specifi application server/tomcat to identify which configuration to pick.
That way, I'll be sure that we are deploying and testing the same .war file on every environment/application server.
How can i restructure the application to achieve this functionality?
I have an application where the WebContent folder has a number of .jsp pages like navigation.jsp, primarytabs.jsp etc.
The navigation.jsp contains a vertical menu and the primarytabs.jsp contains a tab on top, and some other jsps contain individual components.
When I run the application of the application server, it opens up a welcome page, and all these navigation items, and tabs and others merge into a single view and show us a well formed combination of all these components.
I did some studying and read about "composite views". But I wasn't sure if I can call this composite view or not.
How JSF combines all these jsps into one view and where to find that "binding" within the code so I can make the relevant changes?
package progProject5; // Implementation of single linked list. public class SingleLinkedList<E> { private Node<E> head = null; private int size = 0; // Methods
[Code] ......
I am in learning process and I know its very basic question but I got stucked at addAfter() where I need to insert the node after the given node.
I am currently trying to build some programs using google's lanterna library, but I still can't find a method to remove single characters from a Terminal/Screen/Window object. Does such a method exist, at least for one those three?
My application depends on eight default user roles (or account types). They can be renamed or disabled, but should not be deleted. I want to protect them from deletion using their uuid value from the db. How can I pass their uuids into a single variable so I can use that single variable in my conditional statement? If I should use an array, any example of how I might do this?
Is there a method to search a single word or a phrase in an web page? And maybe when it have found the word it say me the line and the number of the character where the word or the phrase begin.
I'm making a game to teach myself programming java so I can start making android. I have this game I'm making where there will be objects(so far its asteroids) will be falling with a progressive velocity (they will move faster as time goes on). The object is the click on the objects before they hit the bottom. It's still early meaning not all the parts I want to implement are there but it works the way I want it to so far besides my click function.
I'm using the Mouse.isButtonDown(0) to record left click but It lets me hold it down and hover over them instead of clicking on each one. Here is a snippet of the part of the code im talking about :
I uploaded a .jar and a exe file so you can see what I mean [URL] .... -jar [URL] .... -exe
public void update(GameContainer gc, int d) throws SlickException { posX = Mouse.getX(); posY = (Mouse.getY()-height)*-1; timePassed += d; deltaTime= deltaTime();
I am working on an project in which some data needs to be received through socket , do some processing on it and then store on the database. After that it will display on GUI. GUI should be updated automatically.
I am able to implement basic model in which data is storing in the database and displayed then on the GUI. I tried to implement MVC design patter as well.
Now i need to create a GUI which can be used by several users at a time means several jvm session for the GUI. I got struck at this point.
Some detail: i have one jvm session in which i am receiving , processing and storing the data. Now i want to fire an alert whenever any new entry is made into the database. Also each time new GUI is opened it should be registered with the model so that model send updated data alert to all this users.
When i am trying to open several GUI and trying to register with the Model then it is not increasing count of registered user. For each time it is showing 1 count only and whenever a new entry is made count is showing 0. Is it because both are running in different jvm sessions ?
Some code for the model which is running in different package and jvm
GUI..
private void runApp() { //some gui code WindowListenerClass windowListener = new WindowListenerClass(this); frame.addWindowListener(windowListener) //registering viewer with the model Model.setNewAlarmEvent(this); tableModel = windowListener.getDefaultTableModel();