Stop Watch Using Timer Class Isn't Working
Jun 6, 2014
I am trying to make a stopwatch using the timer class and JButtons. When I run my program and I hit start the time stays at zero. What I want my stopwatch to do is when I press start it shows the number of seconds that have passed. The start button will then become disabled and the stop button will be the only button able to be pressed. When you hit stop it should enable only the start and restart buttons. Here is my code.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class StopWatchPanel extends JPanel
{private final int DELAY = 1000;
[code]....
View Replies
ADVERTISEMENT
May 5, 2015
i am trying to make taxi meter which shows the current price.Rightnow I have to click startmeter afterevery 1 minute than it's update the new price but I want it to update automatically once the price change after 1 minute instead of me pressing startmeter everytime.This is my 1st time I am using timer class. I am not sure why timer is not working.
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.awt.event.*;
[code]....
View Replies
View Related
Jul 29, 2014
I am looking for a timer class that can measure how much time has passed since the timer started (like a stopwatch). I don't wan't to use the swing timer because then I would have to create an ActionListener that increments a variable every time an event is created and that seems like too much work for the simple things I want to do. I just want it to have methods for starting the timer, stopping the timer, pausing the timer, restarting the timer, and getting the time.
View Replies
View Related
Dec 10, 2014
I have this code for a Countdown Timer...
Java Code:
package javaproject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Countdown.Timer;
import java.util.Timer;
import javaproject.Countdown;
public class Minutes {
[Code] ....
Do I need to put more code in the Countdown class or in the Minutes Class...
View Replies
View Related
Nov 26, 2014
I am making a simple battleship program, you have the menu and click Start to get the board with the bombs (4 buttons as of now) Each button has either a bomb or a defualtbutton. I created my button so it can't be unselected. The problem is I have the button in a Class.java and I want that to close in a period of time. What do you recommend using?
/*
* 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 battleship;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagLayout;
[code]....
I can call the clas in my main jFrame but I want to close the class after a certain time.
View Replies
View Related
Dec 6, 2014
I'm trying to synchronize two folders and their sub directories between a client and a server. I have a modified version of this class which I've posted below. In my Client class, I create a WatchDir object and call its processEvents() method in an infinite loop. The method returns a myTuple object (a struct containing the event type and a path object) if an event is registered and null if not.
The problem is that this only seems to work for the first event to happen in the directory (i.e. if I add a file to the watched folder, my WatchDir object.processEvents() returns one Tuple with an ENTRY_CREATE event and never returns another Tuple for other file additions/deletions/modifications that happen after). I'd like for processEvents to be continuously called (hence the infinite while) returning a Tuple each time some event occurs.
My modified WatchDir:
import static java.nio.file.StandardWatchEventKinds.*;
import static java.nio.file.LinkOption.*;
import java.nio.file.attribute.*;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
[Code] ....
View Replies
View Related
Feb 27, 2014
I have written the java code using timer class to schedule the task , but i am getting error as } expected, i am not able to figure out the error, I have placed the { opening and closing curly bracket everywhere but still it is giving me error.
mport java.io.*;
import java.io.FileInputStream;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.mail.internet.MimeMessage.*;
import javax.mail.internet.InternetAddress.*;
[Code] ....
View Replies
View Related
Aug 31, 2014
I have written a java applet. Few months before It was working all fine but my client has some other requirements now and I have to edit it. I am getting two problems:
1. I could not execute it on my local computer as it always gives "your security settings have blocked a local application from running". I have edited the settings from Control Panel but it is then started giving permission error on including permission in manifest file it started giving trusted library error and still it is not resolved.
2. Can I know how to work with third party library with applets. I have imported the library and uses its few classes but when I tried to load applet it always give no class definition found error. I have some ways mentioned online like use comma separated names for all the jars but no luck so far.
View Replies
View Related
Oct 11, 2014
In the code that I am currently trying to do, I want to make it so that the program loops until the randomly generated number is 1, to a maximum of 4 loops.I have figured out how to make it stop at a randomly generated 1, but I can't quite figure out how to make it stop at four loops if it doesn't reach the 1 before the maximum number of loops.
View Replies
View Related
Dec 2, 2014
how many integers the user wants to use. The user will enter for example a 4. The user inputs a 2, 4, 6, and 10. So then we get our outputs...Then the code will ask if you want to run this program again. My question is, if the user inputs a -1 for example 2, 4, 6, -1....the code will not continue. I wanted to use a while loop, such as while (scores != -1) but it doesn't work.
Enter the amount of integers you want to use4
Intenger # 1 2
Intenger # 2 4
Intenger # 3 6
Intenger # 4 10
You entered 2.0 4.0 6.0 10.0
Average = 5.5
Variance = 8.75
Standard Deviation = 2.96
Do you have another set of numbers?
[code]....
View Replies
View Related
May 18, 2014
I made a check4 application with Java.It correctly works but sometimes the application just stop itself during the execution.I never had a problem like this. The application just stop itself and i can't even quit using the closing button..
View Replies
View Related
Mar 24, 2015
I am developing application called java compiler... It takes java program as input and compiles and run it, gives output. but if input program has infinite loop then how can identify and stop process execution.
View Replies
View Related
May 13, 2014
I am making a project that should play, stop, and loop three different songs (not at the same time). I am calling this SoundPlayer class from my main class:
import javax.sound.sampled.*;
import java.util.*;
public class SoundPlayer {
List<AudioInputStream> songs = new ArrayList<AudioInputStream>();
int currentSong, currentPlayType;
[Code] ....
When my class calls setPlayType(2), which should make it play, I get the following runtime error:
java.lang.NullPointerException
at SoundPlayer.playSong(SoundPlayer.java:32)
at SoundPlayer.setPlayType(SoundPlayer.java:64)
at MainPanel$AListener.actionPerformed(MainPanel.java:60)
(...)
Line 32 is if(clip.isOpen()), but I'm pretty sure I instantiated clip properly in the constructor.
View Replies
View Related
May 1, 2014
What I mean is, I have this set and it is supposed to take out all the duplicates. If I enter aaabbbcccd the output should be abcd, but instead my code just outputs the last word, or in this case letter entered.
import java.util.*;
public class setdemo
{
public static void main(String[] args)
[Code]....
View Replies
View Related
Oct 5, 2014
I am making a WebCrawler, and I am trying to work out a way to stop duplicate links from getting put in however ArrayList.contains() doesnt seem to be working for me can someone look at my code and see if I am doing something wrong? I have also tried variations of it such as
!link.contains(newLink)
and
!link.contains(newLink.getLinkUrl())
with no luck. The Problem area is
for(Element lnks: link){
linkSrc = lnks.absUrl("href");
WebPage newLink = new WebPage(linkSrc);
if(!link.contains(linkSrc)){
links.add(newLink);
[Code] .....
View Replies
View Related
Dec 28, 2014
I am trying to program a slot machine and as of now, I am trying to make my slots spin and randomly stop on one of the graphics. Right now, I am having difficultly making the animation/slot stop randomly.
Previously, I tried using a randomly set timer that would cancel the execution, but the image did not appear/stop on the screen.Right now, I am using a random generator and a while to say that if it is a certain number, then stop the image.Here's what I tried:
import java.applet.*;
import java.awt.*;
import hsa.*;
import java.util.Random;
public class SlotGraphics
{
Console c;
int x = 200;
int y = -100;
[code]....
View Replies
View Related
May 26, 2014
I have a Stream instace which produces values using an infinite Supplier (it supplies values taken from an electronic sensor -- so unless the battery is low, the sensor will provide "for ever").
The stream is processed by a Collector using Stream.collect() (e. g. imagine that the values from the sensor should be averaged; in fact what it does is a bit more compliacted maths).
The problem is that the collector does not produce a result but hangs up, as the supplier does never stop providing more sensor values.
So what I need is a limitation rule that stops the stream. While there is a Stream.limit(long) method, it actually does not solve my problem as in my case it is not practical to stop after a particular count, while I actually want to stop streaming when the sensor value exceeds a particular limit etc. (hence, voids an arbitrary rule).
To sum up, what I need is Stream.limit(Predicate), i. e. the stream will stopped once the predicate becomes true.
Unfortunately I did not find anything like that in JRE 8.
Is that planned for JRE 8.1 or JRE 9.0? Or is there a known (and sophisticated) workaround?
View Replies
View Related
Oct 9, 2014
Inside a While Loop (While Loop begins if a condition is True) I have an If Statement, the else part of the statement assigns False to the condition I mentioned earlier.
But I've tried de-bugging and even when the code goes through the else part of the statement, firstly it returns False but then it returns to the beginning of the loop as True again.
View Replies
View Related
Nov 13, 2014
Is there any way to compile a program without calling constructor.
View Replies
View Related
Apr 28, 2014
Let's say we have a matrics of coordinates:
(0,0) (0,10) (0,20)
(10,0) (10,10) (10,20)
(20,0) (20,10) (20,20)
And we have a class that draws a rectangle of 10 pixel height and 10 pixel width at 0,0 coordinates.
And we want to move with the arrows the rectangle but not to go off the frame.
The question is:
How can I do that if I draw another rectangle, it knows where is the other object and they not collapse. And so on, they move, but not collapse, just touch and stop.
View Replies
View Related
Dec 5, 2014
I have a servlet which sends HTML5 server sent events to the jsp client. The servlet sends data to the client every one second. The jsp client instantiates a new eventsource and recieves the data. When the window is about to close, the jsp client closes eventsource at the "beforeunload" event (shown in the code below).
However, I have noticed that even after the client closes the eventsource and the browser exits, the server continues sending data. As far as the documentation on eventsource goes, using eventsource.close() is enough to stop client from reconnecting to the server and the server will stop sending any further push notifications.
Why the server does not stop sending push notifications even after eventsource.close() and the browser exit? Do I write any other piece of code to notify the server to stop sending data once client exits?
Pasted below are the servlet (server ) code and the client code.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
[Code] .....
View Replies
View Related
Apr 26, 2014
I've got my clear button to work on most of the stuff I want, however I cant figure out how to fix the price to stop adding up. e.g. hit a button image with a price of 599.99, hit the clear button to empty, select price of 599.99 again then it display 1199.98.
sofa method
if (source == jBSofa) {
System.out.println("Sofa"); {
dTotal = dTotal + 599.99;
jTotal.setText(Double.toString(dTotal));
jTotal.setText(String.format("%.2f", dTotal));
}
Reset method
private void Reset() {
jTTotal.setText(" ");
jTotal.setText(" "); //sub total clear
jTTotalTotal.setText(" ");
Attached image(s)
View Replies
View Related
Apr 4, 2014
i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number.
import java.util.Scanner;
public class ticketmaster {
public static void main(String[] args) {
// Variable decoration uses strings , doubles and final doubles.
Scanner in = new Scanner(System.in);
[code]....
View Replies
View Related
Apr 4, 2014
i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number here is the code.
import java.util.Scanner;
public class ticketmaster {
public static void main(String[] args) {
// Variable decorationuses strings , doubles and final doubles.
Scanner in = new Scanner(System.in);
[code]....
View Replies
View Related
Apr 10, 2014
I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,
1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
2) The problem may be to display the JDesktopPane or JInternalFrame.
My working Server Code extends withe JFrame..Java Code:
package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
[code]....
View Replies
View Related
Jul 22, 2014
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.
View Replies
View Related