Timer Conversion On JApplet - Implement 6 Seconds Delay Before Every Loop
Jul 7, 2014
So I'm trying to make an applet and I found that Thread.sleep() to simply delay is a bad idea.
I'm not sure how to use the Timer class to implement a same version of sleep() to delay 6 seconds. I am trying to do this in a for loop to delay before every loop. How can I implement this?
This code is after the init() method. For simplicity I didn't include. Assuming I did:
Timer t = new Timer(6000, null);
public void actionPerformed(ActionEvent e) {
try {
URL rsUrl = new URL("http://rscript.org/lookup.php?type=namecheck&name=" + n1);
BufferedReader br = new BufferedReader(new InputStreamReader(rsUrl.openStream()));
for (count = 0; count < maxCount; count++) {
[Code] ....
View Replies
ADVERTISEMENT
Jul 11, 2014
How can I time my while loop to executeevery 3 seconds?
Here is my code:
class Info{
public String name;
public String version;
public String arch;
double CPUSpeed;
};
Info info = new Info();
Info[] queue = new Info[100];
[Code]...
I seem to have done it right, but it doesn't work... What is wrong?
View Replies
View Related
Jun 10, 2015
How do I impliment a clock/timer in Java? The program saves files in memory for future use. I've included part of the program below I'd like to add a timer to check if the file was changed every 10 minutes. I have included part of the program below.
static FastDateFormat fastDateFormat = FastDateFormat.getInstance("MM/dd/yy HH:mm:ss");
private static final class FileContentsObject {
private long cachedTime; // currentTime
private long lastModifiedTimestamp;
private List<String> contents;
[Code] .....
View Replies
View Related
Aug 3, 2014
I just started to teach myself loops. I am trying to convert the while loop into for loops, however somehow I do not get the same printout.
While loop:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int i = 1;
int sum = 0;
[Code] ....
Print:
sum is 0 and i is 1
sum is 1 and i is 2
sum is 3 and i is 3
sum is 6 and i is 4
View Replies
View Related
Jan 2, 2014
I got Key Bindings for a game I'm working on. They're supposed to move objects when keys are pressed.
(currently, each println(..) represents actual code to move things on the screen, will be added later).
The printing in the console works, but with delays. The words "left", "right", etc. appear with a delay in the console, sometimes half a second delay, sometimes a few seconds delay.
There is no delay at all sometimes, but when a lot of keys are pressed one after the other, there's a delay of several seconds, and only then the words suddenly appear in the console (like the computer had too much to handle at the same time).
When I did the same Key Bindings in a different project without all the game logic, only pressing buttons that print words in the console - it worked perfectly without delay.
So I suspect the problem is something with the game code, or the way I used Key Bindings inside the game code.
I tried putting the Key Bindings code in the thread that contains the game-loop (before the game-loop), and in the constructor. Same problem.
Here is the relevant code of the Board class (extending JPanel), the main JPanel of the game which displays the graphics and manipulates objects.
Java Code:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Board extends JPanel implements Runnable {
Tank tank1,tank2;
boolean[] keysPressed1,keysPressed2;
[Code] ....
As I said, I suspect the program demands too much of the computer, so pressing a lot of keys one after the other, freezes the program for several seconds, and then suddenly prints the words on the console.
View Replies
View Related
Sep 26, 2014
It is possible to delay the creation of a file until I know I am writing to it.
View Replies
View Related
Nov 16, 2014
I'm trying to write a program the simulates the time delay of an elevator door and I want to know how I can add an interactive time in delay in Java.
I know that this is how you delay a Java program:
try {
Thread.sleep(60000);
}
catch(InterruptedException ex) {
}
But how can I make it so that the user can make the timer last longer or end faster through user input.
View Replies
View Related
Feb 25, 2014
I want to execute my jsp code to compare two dates after every 10 seconds if user enter date and current sys date are equal it will send the mail to the user automatically. Below is my jsp code
this if condition i want to check the date after every 10 seconds and when two dates are equal it will send the mail using below mail code
if(ExpcReDt.compareTo(dateStr)>0) {
out.println("Expected return date is greater than current date");
}
else if(ExpcReDt.compareTo(dateStr)==0)
[code]....
View Replies
View Related
Apr 8, 2014
I am trying to convert time in seconds to hhmmss format.How do i get the minutes and seconds.
View Replies
View Related
Jun 11, 2014
I've got a problem with my home made game. When I created it as a JFrame application it runs smoothly, but when I tried to convert it to a JApplet the graphic is "lagging". I can see the graphics blinking/flashing .....
Here is the code:
public class FallingBalls extends JApplet implements KeyListener,
ActionListener {
// VARIABLES //
boolean gameOver;
boolean win;
// Buttons
JButton start, pause, restart;
// Character "The Runner" (32px x 32 px)
[code]....
View Replies
View Related
Feb 6, 2014
I just created an applet that I want to call from a html file.The applet code looks like this (and works):
Java Code:
package jav12
import java.awt.*;
import javax.swing.*;
public class Welcome extends JApplet {
public Welcome(){
[code]...
When I click on the html file the content of the page is blocked and the applet isn't loaded. URL...
View Replies
View Related
Apr 27, 2013
I want to compare two times. What I am doing is
java.util.Date date = new java.util.Date();
java.sql.Time cur_time = new java.sql.Time(date.getTime());
/*this is my database connectivity code from where I am getting second date that I am comparing. This is right. Don't bother it.
Connection c= ConnectionManager.getConnection();
String sql = "select t from datesheet where subjectCode=? and sessional=? and d=?";
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1,subjectCode);
ps.setString(2,sessional);
ps.setDate(3,cur_date);
ResultSet rs = ps.executeQuery();*/
if(rs.next())
{
java.sql.Time t = rs.getTime("t");
long diff = cur_time.getTime()-t.getTime();
}
Then I am converting it to seconds, minutes and hours, but the problem is time that we get from cur_time.getTime() has more digits than time that we get from t.getTime(), so it is always greater than t.getTime() even when it is not.
long seconds = (diff/1000)%60;
long minutes = (diff/60000)%60;
long hours = (diff/(60*60*1000))%24;
View Replies
View Related
Jun 12, 2014
I've got a problem with my applet when I run it in a browser (firefox mainly but nothing else is working neither). First of all, the program is "unsigned" according to firefox security system, but I don't think that's where to problem lies. When I start the applet (as an html application) it says:
AccessControlException
Then it says: Access denied ("java.io.FilePermission" "bla, bla, bla (img source on my harddrive)" "read")
How do I get this to work? This is the picture I'm trying to implement: [URL]...
View Replies
View Related
Oct 6, 2014
I made an Analog Clock and its working but when a remove the filloval (Background) the seconds hand keep repeating itself..here is the code
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.swing.JFrame;
import javax.swing.JPanel;
[code]....
View Replies
View Related
Mar 4, 2014
I am busy programming a clone of the popular phone game they had on Nokia cellphones a long time ago called Snake II but since I know very little about programming I will be using ASCII graphics instead of a 2D graphics engine.
My idea for implementation is having a main class called game which should refresh a grid of ascii characters every, say 0.2 seconds. Then I have another class called Dot. Each Dot object has x and y coordinates, and a direction in the x and y planes (dirx = -1 means left, dirx = 1 means right, diry = 1 means up, diry = -1 means down, and obviously the snake cant move the diagonals)
The Game class prints a "*" symbol where the Dot is, and what I'm trying to do is get the screen to refresh (I think I need to use the sleep() function for this to slow the game down to a reasonable pace), and go in the direction it is supposed to go.
(I haven't programmed this in yet but the snake will be an array of Dot, and at each refresh Dot at position 0 will pass it's coordinates and direction to Dot at position 1, Dot1 to Dot2, Dot2 to Dot3, etc.
Here's my code so far:
A first class called Game.
Java Code: //Not done yet but this is the start to my game of Snake. Basically the class Game generates a Grid of ASCII characters
import java.util.Scanner;
public class Game {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
final int WIDTH = 79;
[Code] .....
My problem now is that I am taking input from the Scanner class. What it does is wait for my input, then it goes on to executing the rest of the code in other words refresh the ASCII grid. This is a problem because I need the snake to keep moving at constant pace while listening to the keyboard.
How can I get my while loop to keep going (i will add a sleep() function later) while listening to the keyboard without stopping?
View Replies
View Related
Feb 6, 2014
I just created an applet that I want to call from a html file.
The applet code looks like this (and works):
package jav12;
import java.awt.*;
import javax.swing.*;
public class Welcome extends JApplet {
public Welcome(){
}
public void init() {
getContentPane().add(new Label("Yessss it works",Label.CENTER));
[Code] ....
When I click on the html file the content of the page is blocked and the applet isn't loaded. What can I do to fix this. I think it has something to do with rights. This is a crosspost to JApplet content blocked
View Replies
View Related
Jan 14, 2014
I am developing a game where a player has to find a path in a maze. Right now the player can only click the buttons on the maze. I need an option to use the arrow keys.
I have picked up pieces from my code to illustrate my problem. Below is the code. If I call "AnyClass" in the "AppletClass" it works but when I call "MiddleClass" in the "AppletClass" and MiddleClass" calls "AnyClass" it does not work. In my project at www.hiredforoneday.com I call 4 panels in CardLayout before I call "AnyClass" which is the "Maze"
package keymapingincardlayout;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
[Code] .....
View Replies
View Related
Dec 16, 2014
I am trying to make a japplet that has open, zoom in and zoom out buttons for pictures. I am not sure how to go about an open button that will read the file. I have the picture url hard coded in the file to open but would like an open button with a file/folder dialogue.
This is what I have so far
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
[Code] ......
View Replies
View Related
Apr 15, 2014
I'm not exactly sure what the draw button is supposed to do specifically, all i know is that it is supposed to draw both rectangles and ovals. The problem I am having is that when ever I click Draw Rectangle, it draws rectangles jusst the way I want but when ever I click Draw Oval, the program keeps drawing rectangles. I've tried repaint and clearRect methods but I did not manage to get them to work. I'm not sure what the problem is right here, I just cannot get it to work. Is there anything you guys can see that might be causing this? It's always good to have a different person look at it then myself. Also, I'm trying to implement a boolean for draw oval but I don't know where to put the if then.
public void init() {
length = new JTextField(10);
width = new JTextField(10);
btnDraw = new JButton("Draw");
btnClear = new JButton("Clear");
btnDrawRectangle = new JButton("Draw Rectangle");
btnDrawOval = new JButton("Draw Oval");
[Code] .....
View Replies
View Related
Aug 17, 2012
I am involving in airline booking engine project.
There is a requirement to view a completed booking ticket details continually in each 30 seconds.
Application is already developed using struts / spring and deployed on jBoss server.
I heard spring scheduler and queues. Which is the better solution?
View Replies
View Related
Nov 6, 2013
This is what he wants: He wants us to prompt the user to input x values and y values (that will be entered into an array when clicking one of the two buttons (this one will say: Add point)). When they click the second button (draw lines), it should take all the points and draw a line that connects all the points together using a method that we write. In the method we have to call the paint method up which the lines will be drawn. The lines drawn should be touching every point added. It shouldn't have parameters. It will also use Graphics painter = getGraphics(); We can't use frames either.
I have everything up until the method understood.
How to write a method that will draw a line from points inputted that is called up in the action listener when the second button (draw lines) is pressed.
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
Aug 19, 2014
i have a client side program that grabs information about the computer it runs on. I want to have it grab the same info every so often, and check it against the original.
what can be used to do something like that? end game would be having it start up with the pc, then check periodically. if the values are different, send them to the database
View Replies
View Related
Apr 26, 2015
[attachment=38859:bcourt.jpg]I/m not used to Timers, so this will be my first time using it and I don't know how. I've been searching the internet for an hour but I can't find an answer into it. I'm currently doing a basketball game which has a Buttons (Shoot,Dribble,Hold) and I need those timers for my buttons to work. Her's the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BasketBall extends JPanel implements ActionListener
{
JButton shootButton = new JButton("SHOOT");
JButton drbblButton = new JButton("DRIBBLE");
JButton holdButton = new JButton("HOLD");
[Code]...
View Replies
View Related
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
Jan 5, 2014
One of the classes that i need to serialize includes a few Timers. When I serialize it and then load it up again, the Timers are stopped. How do I start the timers where they left off?I'm using Swing Timers. Should I be using the other kind?
I using the Timers in this case to change something after a countdown, but only once, then the Timers are stopped. I set the Timer tick interval to the time I want it to wait. Should I be using smaller tick intervals, and just waiting for the tenth (or so) tick, or is my way fine?
View Replies
View Related