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.
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()
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.
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.
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) {
A data entry form is on the front end. This allows one to enter say emails, addresses, etc. It utilizes a jsp, jstl, servlets, and beans. The backend sql has say a size of 50 for email. If more than 50 char are entered on the form, w/o any intervention, a truncation error is thrown. A static class was set up to hold the input element names and max sizes. It seems to work well keeping all in check, names and sizes on form, names in servlets, size of sql.
servlet .getInputElement("date").getInputName() //static map...shared with above objects
Is there any other system of keeping everything in sync. I am building it all, but I was wondering how this is parsed out if there are separate sql, middle-tier, and front-end developer? It seems better just to have good documentation that would be shared between the different implementers.
For the assignment, we are supposed to make a checkerboard with alternating colors, then put images on top of certain spaces to act like "pieces." I did the checkerboard, but whenever I go to try and put an image the checkerboard, it doesn't appear! I put the image in the same directory as my other code as well. I did some experimenting and discovered that the image is appearing, but behind the checkerboard.
Here is the code:
import java.awt.*; import javax.swing.*; public class CheckerBoard extends JApplet{ public void paint(Graphics g){ super.paint(g); Image img1= getImage(getCodeBase(),"arrow1_nw.png"); g.drawImage(img1,500,500,this);
I'm using Dr.Java and doing a numbershifter lab. I have to create a random array of number from 1-10. Then move all of the 7s to the front of the array. The order of the other numbers is not important as long as all numbers follow the group of Lucky 7s. Files needed Numbershifter.java and numbershifterrunner.java. All data is random.I have done the following:
public class NumberShifter { public static int[]makeLucky7Array( int size) { int [] newRay = new int[size]; for( int i=0;i<newRay.length; i++) { newRay[i] = (int)Math.round(Math.random()*10+1);
basically I'm a good way through developing a Poker game which I've been developing just for fun(!?) and also to improve my skills, which it has done substantially. The logic involved with some of the hand comparisons and the evaluations of the winner is pretty complex.
Nonetheless, once I've finished the threaded timer to control the regulation of rising blind levels, and the betting mechanics for the Computer players I'll be looking to start creating the front end and this is where I'm a little confused.
Obviously for what I want, neither swing or AWT would be sufficient, so I guess the gap in my knowledge is how to integrate my back end code with a web front end. Is this possible? - What options exist for integration? just pure CSS / JS, or would Angular.js be viable? I'm looking to utilise some ready made images as graphics with maybe some minor animation effects.
I am messing around with a Swing application and am a bit stuck as to how to join the front and back ends.This is the code for the DataManager class which is responsible for loading and saving objects and interfacing with rest of the system. The data I need displayed comes from a .txt file in the applications directory. I need to show certain aspects of the data in the JComboBoxes in the GUI class.
Java Code:
package programdataapplication; import java.io.*; import java.util.*; public class DataManager {
Code for implementing a simple computerised version of Battleships has been supplied. Examine the code ensuring that you understand it. The game is played against the computer.
A number of ships (default is 6) are place randomly on a 4 x 4 grid. A ship occupies one square only. The player then guesses the position of a ship. If he/she guesses correctly the ship is HIT and sinks. If the guess is incorrect the player loses a life. The default number of lives is 7. If the location has been guessed already, no lives are lost.
When the game starts, a 4 x 4 grid should be displayed.
The user should be allowed to enter/select a cell location. If the selected cell contains a ship, the ship will be destroyed. If not the player loses a life. The cell should display an appropriate picture, icon or message informing the user of its current state.
The number of lives and number of ships remaining should be displayed.
When the game ends an appropriate message should be shown informing the player whether he/she has won or lost. The positions of the ships should also be shown.
The purpose of this assignment is that students demonstrate an understanding of the Java Swing library and that he/she can navigate and use the API effectively.
Your finished GUI should be both user-friendly and aesthetically pleasing.
Ideally, the user should have the option to play another game, to quit or give up mid-game. You may also wish to include other options such as different levels of difficulty, etc.
I'm creating UI's that run on top of backend tools that can run from seconds to days and output GB's of generated data (imagine running tar on the Google servers).
I understand how to execute my backed tools using a runtime process and how to interact with them, and running a simple text as a command line Java app works as expected. The issue occurs when I wrap the code in a JavaFX frount end UI try to update the UI elements in a reasonable manner. If I simply use System.out.println() as in the command line version, I see the output from my task. However, simply trying to put that same output into a TextArea using .appendText() doesn't update the TextArea until the background process completes.
I see all sorts of clippings relating to Task, CreateProcess, invokeLater, updateProgress, but none of them seem to solve their original posters' question (nor mine at this point).
I have a doubt about how to design a web application which has their persistent objects in a service layer in a remote server, i mean a business application. So, once we have a web application as a client of this remote business application, how those persistent objects should be mapped in web front?
Should I either pack all jpa annotated classes into the web front application or there is another neat way to do this? I was intending in copy all persistent classes present in the remote business application into the web app package, i know it's not the best way to get what i need.
What is a more appropriate design for a web application which must get some objects from a remote business application and persist some other objects there?
I was thinking to make a game where two cars are going to race against each other. I already have two gif pictures which are the cars. I do now have a background and a racer track. So we can start from here.
I have made a object with construction which I called Racers. Inside that, i wrote a PaintWindow (Where the window and much more is inside), -car1, -car2. All these is private. So I made something like this now:
package p2; public class Race { private Object window; private Car car1; private Car car2; public Race(PaintWindow window, Car c1, Car c2) {
[Code] .....
But the problem is now that im kinda lost and I dont really know what to write anymore. How can I get a for example a green background on the whole PaintWindow with two Racers tracks and inside the racers tracks (Each car have each track) does it have to be cars. So I need to somehow import the cars inside it too. But thats the problem I need. that I dont really know what more to do. To make it easier, I have a Main-method in another class.
public static void main(String[] args) { PaintWindow window = new PaintWindow(); Car c1 = new Car(new ImageIcon("C:/Users/Sarah/Desktop/CarBlue.GIF")); Car c2 = new Car(new ImageIcon("C:Users/Sarah/Desktop/CarRed.GIF")); Race race = new Race(window,c1,c2); race.action(); if(args.length>0) { Paintwindow.pause(2000); window.dispose();
I'd like to learn more in Java security, namly Kerberos and SSO. The question is weather I have too weak laptop. I have 8 GB ram. How many virtualbox instances od I have to run in order to JAAS, SSO kerberos demo to simulate. For instance VM with Windows 2008 Server -> 3 GB RAM, Centos VM -> 1GB. Is 8 GB RAM in my laptop not too little?
BTW
I do not have yet experience in SSO/Kreberos but I want to know what to do in order to simulate and exercise.
I have a class "ExecuteJob" which has Print Q in the form of Priority Q.
You can keep adding job to the Q by calling one of the method in the class. However, and object cant do things simultaneity can it? While im adding a new job to the print queue, can it be executing and existing job in the print Q.
To achieve that, I would need to implement process and threads? I believe am I right? So that adding a job is independent to being removed?
So what I want to do is have a method that allows me to use the callRandomNumber method so that the matrix location with that random value is marked true for all of the boards.
I'm very new to Java (I literally started learning it yesterday) and I've been working on a simple program that's meant to simulate interactions between optics objects and light rays.
Everything has been going really well, except that my mirrors only reflect the first ray that comes in contact with them.
Here's a screenshot : 2014-09-13 at 7.39.23 PM.jpg
I wrote 7 classes:
Main class to create the optics objectOptics class. the most important class that uses a recursive function to detect the nearest intersection point of a ray with the nearest optics object. It then calculates a reflected ray and inputs it back into the function until no intersections are found or the max recursion depth is met.Ray. creates a rays (in parametric form O + tD where O is the origin, D is the direction and t is a non-negative scalar)Object. empty abstract class used for polymorphism (so when i add more optics objects like prisms and lenses they'll share the object type)Mirror. Basically a line segment created with the Line classLine. Creates a line segmentDraw. JComponent with paintComponent function that loops through an array of shapes and draws them to the screen.
What I know so far is that the problem boils down to the checkRay() function in the Optics class. When a mirror has already reflected a ray, the line:
Intersection sec = new Intersection(ray,(Mirror)obj);
creates an intersection with a null point.
I debugged it line by line and found the problem was that my variable 't' (that is the parameter for the parametric line which represents the mirror) in the Intersection class got big values when it's meant to be between 0 and 1 (since it's a line segment), which resulted in the function returning null (as it should when 't' is not between 0 and 1).
I've confirmed with tests that this has nothing to do with the specific mirror or angle of incidence. It only occurs when a mirror has already been intersected with by a ray.
I've found out that my function:
public PVector getNormal(PVector D){ D.normalize(); return new PVector(D.y,-D.x); }
Changes the value of the 'D' PVector of the mirror inside my 'objects' ArrayList. How can it access the private PVector 'D' from outside the Mirror class? This normalization to the direction vector is what causes the Intersection class to return null the second time around!
The problem was that in the getNormal function, the input vector argument was a reference to the 'D' vector for the mirror in my 'objects' ArrayList so the .normalize() function acted upon the original vector, changing it's value and screwing things up. The two classes I talked about:
Optics: (note line 64. this line returns a null intersection when it shouldn't)
package ofer.davidson; import java.util.ArrayList; public class Optics { //Arrays to store all the optics objects and rays that are created ArrayList<Object> objects; ArrayList<Ray> rays;
I am making a elevator simulator for my class. It needs to be "event time". I am having trouble understanding how I can make an "event time" simulator. Initially I was using a while loop to run a clock time simulation of x seconds for each event, until I ran into a concrete wall and had to call another method which took X seconds, while still needing to execute code.
An example of what I did is:
Spawn person -> person.goToElevator (Takes x seconds) - > person.waitForElevator (Until elevator arrives, x seconds). While this is happening, I needed to create another person and do the same thing, this will add another to the queue if the first person is still waiting. Etc etc, you get the point.
We have not learnt about multi threading, that is the next assignment.
Here is a quote from my lecturer:
"That's right, it requires multi-threading which we're not doing in this paper. Here's a solution that can work:
The person waiting for the lift and then doing lots of other things should do all that in a fraction of a second. So, you don't let the person really wait. Instead, you will set a timestamp in the future in the person object that "he's busy till that time". In all other steps in your simulation you will first check if a person is "busy" (i.e. has a timestamp in the future). If so, you can't use this object, otherwise, you can.
How does it create a bigger queue? Outputs I would have in my final simulation would be, averageQueueLength, numOfPeopleInBuilding etc.
I am attempting to create a 2d game that has a realistic space simulation. The map is supposed to be set so that you are looking from the top down. The problem I am having exists in my interaction between the sun and a planet. Simply put, the planet will only move in a single diagonal direction without ever changing direction. The formulas I am using are F=(G*M1*M2)/D^2 and A=F/M. The code below is simplified.
Things I have already tried: 1. Setting G to negative 2. changing the order of the subtraction in determining D 3. some weird pythagorean theorem thing someone suggested
how to setup a program that simulates the progression of a line over time.The scenario involves a bank and 5 tellers. There is one line of customers that starts off with an initial length of 20. Every minute, 10 more customers are added to the line. As this is meant to be a FIFO queue the first 11 customers in the line will be distrusted among the 5 bank tellers as follows: Teller #1 will process 1 customer per minute, Teller #2 and #3 can each process 2 customers per minute, and Teller #4 and #5 can each process 3 customers per minute. Therefore, the first 11 customers in line will be processed within the first minute of the programs execution.
Unfortunately, I am not sure how to attack this thing. I am thinking that I need to setup a queue for the initial 20 customers and an array for the 10 customers that will be joining the line every minute. However, I am not sure how I can set this up to work automatically.