Why Does Traffic Light Jumps Over Red Light State

Nov 27, 2014

I have a TrafficLightsManager Thread class that create one new CarTrafficLight object, and manage him by synchronized semaphore.

Unfortunetly the line sleep(5000); after the traffic1.WaitToRed(); never happenned, and the class jumps very quickly over the Red State.

I added the Message "!!!" before moving out from the Red State to the orange to check if the red exists at all and the result was positive - the red status entered and then I got the "!!!" message,but at the second that I accepting the message the red state turns into the orange state......

I don't get it!!!

package MyTzomet;
import java.awt.Point;
import javax.swing.JOptionPane;
public class TrafficLightsManager extends Thread {
CarTrafficLight traffic1;
ViewFrame frm;

[Code] .....

View Replies


ADVERTISEMENT

Traffic Light Simulation Using Multithreading

Feb 2, 2015

I am writing a simple program to simulate a traffic light. What I want is to make them glow after each 1 second, one by one. For example: Firstly Red, then after 10 seconds, red will be put to off and yellow will start glowing and then accordingly green. This process shall continue incessantly (Just for experimental purpose). I have some arrangement done but could not figure out how to put them together in run() method of Runnable interface. I know how interthread communication works. But could not find any logic in this case when three threads will run together.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TrafficLight extends JFrame implements Runnable
{
JButton red, green, yellow ;
TrafficLight()

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Turn On Light Through ActionPerformed With OpenGL Java

Apr 29, 2015

I'm writing a java program with opengl and I'm trying to get it where the user would select something like lighting on in a JMenu and then it would turn the lighting on in the house/barn... I have a method called LightOn that I put gl.glEnable(gl.GL_LIGHT0); but it just doesn't seem to turn on when I call it from the action performed... Is there something I'm missing from my code that I'm supposed to use instead since I have tried it with a boolean.. So the boolean starts off as false and when the JMenuItem is clicked the actionPerformed will turn the boolean to true and call the method LightOn. In the display method I have what the light is supposed to be

Snippet of code in display method for lighting:

float [] whiteLight = {1.0f, 1.0f, 1.0f, 1.0f};
float [] ambientLight = {0.1f, 0.1f, 0.1f, 1.0f}; //default
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, whiteLight,0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, whiteLight,0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambientLight,0);
float [] lightPosition = {25, 25, 25, 1};

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Background Color Of JTabbedPane Is Light Blue?

Feb 18, 2014

No matter what I did, and searching for every piece of setBackground, The background color of the JTabbedPane is light blue.

public final class MainFrame extends javax.swing.JFrame implements Runnable, WindowListener,
WindowFocusListener,
WindowStateListener {
Container mainPanel;
JPanel bluePanel = new JPanel();
CloseButtonTabbedPane tabbedPane;

[Code] ....

View Replies View Related

Front End For Air Traffic Control Simulation?

Apr 1, 2014

I'm a student designing and developing an Air Traffic Control (ATC) system for incoming aircraft, mainly implementing the part which handles the queuing system for approaching aircraft.

View Replies View Related

JSP :: Would Template Based Framework Generates A Lot Of Request Traffic?

Nov 29, 2014

If I have a web page with a lot of data to show, say a lot of tables and graphics, would using non JSP based frameworks result in a lot more individual AJAX requests? For example if the page have 5 tables, with JSP the whole page will be returned to the browser with data for all 5 tables already. But if this is a pure HTML / Javascript based view, then we need to have each of the 5 tables to make individual AJAX requests in order to render the page. Is this indeed the down side for not using JSP?

The reason I'm asking is because I'm considering moving away from JSP to a template based framework such as Thymeleaf or Freemarker.

View Replies View Related

Running Java Application - Analyze Traffic Condition

Jun 18, 2014

I have a java application which uses Google Maps to analyze the traffic condition. But sometimes it can be run and work properly, sometimes not. On some computers on which there is installed java, the program can be run, and on some, again with installed java (jre), exactly the same version, the program can not be run. For example the application first run well on my desktop computer, connected in a LAN, and then stopped working well when run. But when I use laptop which uses the WiFi and run the same computer using VMWare, if I connect to the desktop on which the program can not be run, on the laptop the same program can be run well, in the same room, but using the Wifi.

View Replies View Related

Swing/AWT/SWT :: Traffic Simulation - Applet Not Initialized Error

Mar 25, 2006

I have a traffic simulation code that is producing a start:applet not initialized error each time i run it. This is the code

import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.lang.Thread;
class Node {

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Program That Record And Rerun Network Traffic

Sep 21, 2014

I have a program that records and reruns network traffic. It was developed in C and runs in my case under Windows 7 Professional but will run almost anywhere. I have observed a lack of stability.

First I have a JAVA stand alone GUI program that runs the program as follows:

g11_bttn_start_script_capture.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {

URI uri = null;
URL url = null;
String tempstr = "";
tempstr = "-s " + g11_txt_PATH_portnumber.getText() + " " + g11_txt_scriptname.getText() + ".both";

[Code] ....

Basically it launches the executable t3drive, hangs arounf so it gets a chance to start, and then connect to it via the embedded browser.

It frequently works, sometimes launches in the browser but then freezes, and sometimes fails to start at all.

t3drive works 100% of the time if I run it under cygwin and I can reliably connect to it using any browser.

Why this might not be stable? Just looking for a direction of what to try next.

View Replies View Related

Store A State Of A Project

Sep 23, 2014

Hello World program. We had to build it. Write a basic Java program that will implement one class to store a state of a project. The class should have one property to store a textual name of the state. When a object of this class is created the initial state should be "Open".

1) Class should have one method next() which will move the project to the next step in the sequence: Open - In progress - Closed.If next method is called for a project in the Closed state it should do nothing.

2) Class should have a method close() which will move the project into the Closed state.

3) Class should have a method print() that will output a current state of the project.

Submit a java code file as your assignment. Do not hesitate to contact me if you have any troubles with the assignment.

I have been working on this thing for almost a week, and really don't have a clue on what to do. I know I have to use a string = open, and I know I have to create an object. I don't have a clue on how to do this. I have read the chapter so many times, I almost memorized it, but what he wants is nothing like our demo in the book. the Book used set and get, and utility scanner, but he doesn't want any of that. Just a basic code that will move from Open --- in progress --- closed.

The best I can tell what he wants is when I set the object to open it will display " project is open", then when I set it to " in progress" it will read project is "in progress". I don't have a clue what close is suppose to do, or the print method.

View Replies View Related

State Machine Compiler

Oct 19, 2014

I am working in software testing, specifically automatic test cases generation. Among the existing forms of test cases, my focus is on the test cases that are composed of sequences of events such as _.event1.event2 eventx()

However, the events can be classified into: sensitive and insensitive. The latter does not affect the system's states, and hence, it can be ignored; while the former affects the states. Anyhow, the sensitive events in the test cases may lead to states explosion and there is a need to prevent that. Therefore, some techniques suggest using one variable to present states and group all similar states together such as using len variable in circular queue. Relatively, the states can be represented by using specific drawings such FSM.

For example, the test cases for circular queue may look like:

add(0).remove().add(1).Front()
add(0).add(1).remove().Front()

which produce the following states:

len=1, rear=0, front=0 and dataQ[0]=0
len=0, rear=0, front=1 and dataQ={0}
len=1, rear=1, front=1 and dataQ[1]=1

len=1, rear=0, front=0 and dataQ[0]=0
len=2, rear=1, front=0 and dataQ[1]=1
len=1, rear=1, front=1 and dataQ={1,0}

As can be seen, every addition/deletion produces a new state. A state is composed of 4 variables: len, rear, front and dataQ. The 1st three variables are integers while the dataQ is an integer array. Nonetheless, the states produced by different test cases can be identical which wastes effort and time. So, there is a need to optimize these states. The search techniques were suggested where the problem can be represented as a search problem and the technique is applied. If we consider Len as a state, then we will have: len=0; 0QSize. However, this does not represent the state but it suits for classifying the states into groups.

In terms of states representation, State Machine/Map Compiler (SMC) was suggested as a modeling mechanism that takes the state machines (i.e. FSM) drawing and generates the code in any preferred language. In SMC, the FSM is represented in a specific syntax (state---transition----next state) and saved in a file (.sm). This file will be compiled by SMC to generate a context class which includes definitions of states, transitions and actions in FSM but still need to be triggered by another class. This class has to call the transitions that modifies the state.

We had created that class and implemented all the methods with their transitions. However, the FSM used was based on 1 variable only (i.e. len). Besides, we are still looking for the SMC results as they will be the input for any search technique to be applied. Supposedly, the states generated by SMC can be used directly in the search technique but this is still questionable.

View Replies View Related

Stale Object State Exception

Aug 17, 2014

Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryI mpl.java:109)

What are the common reasons for the above exception and the suitable fixes?

View Replies View Related

JSF :: Server-side State Saving

Nov 25, 2014

in my web.xml the.STATE_SAVING_METHOD setting is server

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

for measurement of application security isn't not allow to change this parameter to client , so the problem when I access for application and I open a new page via linker for print for example and I would access for my initial page to make change or modify my initial page it s no possible to make any modification because I have a empty bean , but if the state saving is a client I haven't a problem because a tree map is stored in client browser, so my version of JSF is 1.1.1 ,

View Replies View Related

How To Set State Of Radio Button Based On Configuration File

Apr 10, 2014

I am using Java Swing to create a GUI. I have some radio buttons on a JFrame that gets opened when the user makes a certain selection. I want to read a config file to have the radio buttons selected or deselected when the form is opened to indicate the current state of the radio button based on the saved config file.

How do I go about setting the radio button as selected (visibly selected) when I open up the JFrame?

I was trying to use RadioButton.setSelected(True); but this doesn't actually visibly select the radio button.

View Replies View Related

Illegal State Exception Thrown From RequestFocus In JavaFX

May 2, 2015

I am attempting to create a very simple game where two squares move around and each can see the other square moving. This is a multi-player game over a TCP network using JavaFX. I am getting an illegal state exception when I call requestFocus(). This is my server:

public class GameServer extends Application {
ObjectOutputStream p1out;
ObjectOutputStream p2out;
int PLAYER1 = 1;
int PLAYER2 = 2;

[Code] .....

View Replies View Related

How Does Threads Come Back To Ready State After Executing The Task

Mar 21, 2014

When a thread completes its execution, it will be destroyed.In Java thread pool implemenation, how does threads come back to ready state after executing the task.?

View Replies View Related

Thread Java - Illegal State Monitor Exception

May 30, 2014

Class A{
Public static synchronized void main(String args[]){
Thread t= new thread();
t.start();
Sysout("hi");
t.wait(1000);
Sysout("hello");
}}

Illegal state monitor exception. Why?

View Replies View Related

How To Change State Of Object - Main Method Exception Error

Jan 8, 2015

The error I get when I execute my java file.

Exception in thread "main" java.lang.NullPointerExceptionat DogTestDrive.main(DogTestDrive.java:19)

Here is the source

class Dog {
int size;
String name;
void bark () {
if (size < 60) {
System.out.println("Woof woof");

[code]....

Some background: I'm reading "Head first Java 2nd edition" and I'm going through the examples which is showing me how to change the state of an object. The original code looks like the code below, however the previous chapter went over creating array's of an object, so I created an array of the object "Dog" and wanted to re-write it this way. To my understanding, it should work but it's giving me that error when I execute it. The error itself isn't very clear, if I could get a line number pointed to, that would work.

class Dog {
int size;
String name;
void bark() {
if (size > 60) {
System.out.println(“Wooof! Wooof!”);
} else if (size > 14) {
System.out.println(“Ruff! Ruff!”);
} else {
System.out.println(“Yip! Yip!”);

[code]....

View Replies View Related

Extracting Kerala State Vehicle Number Plate From Image

Mar 25, 2015

code for extracting kerala state vehicle number plate from an image

View Replies View Related

JavaFX 2.0 :: Stage From Iconified State To Regular Size Via Shortcut

Jan 23, 2015

I would like to ask you about possibility to restore javafx 8 app from iconified mode (setIconified(true)) to regular size via shorcut for example: Ctrl + Shift + Ins I use Windows 7 and jdk 1.8.0_40 beta.

View Replies View Related

Custom Jtable Cell Editor Throwing Illegal Component State Exception

Jul 10, 2014

I've come across an interesting problem when using a Jcombobox as a custom cell editor(and renderer) in a jtable. I was hoping to add a keybinding in order to display the dropdown of the combobox instead of having to click on it however, when I make a call to showPopup() I get:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location Which is strange as my jtable is visible and the editor/renderer seems to be working fine.

Here's the cell editor + renderer I'm using:

class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
public MyComboBoxRenderer(String[] items) {
super(items);
} public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());

[code]....

View Replies View Related

Allow User To Change And View State Of Credit Card With Menu Driven Program

Apr 20, 2015

I am new to OOP, i am not sure if this is the correct approach or not. Write a class named CreditCard that has (at least) the following member variables:

- name. A String that holds the card holder's name.
- cardNumber. A field that holds the credit card number.
- balance. A double that stores the current credit card balance.
- spendingLimit. A double that stores the spending limit of the card holder.
- Bonus: additional fields that you can think of.

In addition, the class should have the following member functions:

- Constructor. The constructor should accept the card holder's name and card number and assign these values to the object's corresponding member variables. The constructor should initialize the spending limit to $2,000 and the balance to $0.
- Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's member variables.
- purchase. This function should add the amount specified as a parameter to the balance member variable each time it is called.
- increaseSpendingLimit. This function should add 500 to the spendingLimit member variable each time it is called.
- payBill. This function should reset the balance to 0.
- Input validation: Whenever a credit card number is modified, verify that it is of reasonable length.

Demonstrate the class in a program that creates a CreditCard object and allows the user to change and view the state of the credit card with a menu driven program.

View Card Information.

- Purchase an Item: ask the user the purchase amount and increase the card balance accordingly.
- Pay Bill: call payBill method to set the balance to 0.
- Increase Spending Limit: ask the user how much the spending limit should be, and call the increaseSpendingLimit function the appropriate number of times.

[CODE]

import java.io.*;
import java.util.Scanner;
public class CreditCard
{
Scanner input = new Scanner(System.in);
//data members
private String holderName;
private int cardNumber;
private int accountBalance;
private double spendingLimit;

[Code] ....

View Replies View Related







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