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()
I know what the error means but I don't think initializing the variable will make my code work as intended so I'm having a little dilemna here... here's the code and I'll highlight the part that is said to be not initialized:
Java Code:
import java.util.Scanner; public class ItemCost { public static void main (String []args){ int i=1,item=1,e=1, f=1, g=1; int items, d ; double gst, qst, subt, Tot = 1, PriceItems ;
[Code] ....
So I'm supposed to get the following output :
Java Code:
Please input the amount of items bought 2 Please input the price of the item 1 1 Please input the price of the item 2 2 Please input the rate of GST in % 20
Please input the rate of QST in % 18 mh_sh_highlight_all('java');
HOWEVER my program doesn't seem to add input of item 1, and 2 if I initialize subt= 0 initially. It'll only take the last value inputted in the loop. By the way, the increments are counters to count the amount of errors the user might input by accident ( or whatever). Some people have been pointing it out as useless but that's the only way I found it to work.
public class Test { private final int arg; private final Runnable runnable1 = new Runnable() { @Override public void run() { // No errors here, exactly as expected System.out.println("ARG: " + arg);
[Code] ....
The java compiler (version 1.8.0-b132) produces the following error when compiling this code:
"Error:(14, 46) java: variable arg might not have been initialized"
Actually, I do not expect the error here.
Both declarations 'runnable1' and 'runnable2' are essentially the same: these are just Runnable objects accessing value of the 'arg' field (which is initialized in the constructor).
The only difference between the declarations is that 'runnable1' - is an old-fashion instantiation of Runnable, whereas 'runnable2' - is an instantiation of Runnable via a lambda expression.
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) {
I want to use a try catch block, but I am not sure how to fix this problem:
int a;
try{ a = Integer.parseInt(A.getText()); } catch (Exception e){ Output1.setText("Error"); }
//do someting with a here
The purpose of the try-catch is to catch blank input.The problem with this is that underneath the try - catch I get an error saying that the variable might not have been initialized. I know why this happens. I know I could initialize the varaible before the try - catch, but there is no default or null I can set an int as. If I initialized it as 0, the blank input will no longer be catched.how to make this problem disappear?
I'm using jdk7 and I get this error when I compile Exception in thread "main" java.lang.Error: Unresolved compilation problem: at First.main(First.java:16)
When i run a applet file in browser(IE, Chrome, Firefox) it gives a error of security risk and block the application from running. All browser are giving same error. Programme is running correctly in Myeclipse
When I am trying to run an applet in command prompt I am getting an error message saying: System cannot find the file specified.
Initially I compiled my applet using javac BubbleSort1.java it works fine But when I tried running this using: appletviewer BubbleSort1.html I m getting the above error. Anyhow, both the html file n the java file are in same folder in C drive. (windows 7) .....
I was wondering where is the memory allocated for an applet; by the browser; by the JVM; some applet specific java option? I get an out of memory error when running my applet (loading pictures).
What's wrong with my Java program? When I open it using appletviewer, the applet opens but stays blank and an error message appears in Terminal.
Java Code:
import java.applet.*; import java.awt.*; public class DemoColor extends Applet { Font littleFont = new Font("Helvetica", Font.ITALIC, 6); public void paint(Graphics gr)
[Code] ....
Error Message:
Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue
at java.awt.Color.testColorValueRange(Color.java:310) at java.awt.Color.<init>(Color.java:395) at java.awt.Color.<init>(Color.java:369) at DemoColor.paint(DemoColor.java:24)
I coded up a simple applet and some html with an applet tag and it tested out OK using the applet viewer. But it doesn't do anything (except draw a grey empty box 100x200) when executed from the application server. For the applicaton server test, I put the applet tag in the HTML Body of the JSP page i.e.
I'm doing a project in which I must display prices of computer accessories in a Scroll Pane viewer. The if statements are all checkboxes. I am completely lost with how to print to the viewer if a checkbox is selected. Furthermore, I am also lost with how to add up all of the checkboxes.
private void USBCheckActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: double area = 0; double computerprice = 500.0; if (printerCheck.isSelected()){ double printer = 100.0;
I want to embed an existing JAVA applet in to my swing application which is a standalone application. The applet is used in some other application which is not developed by me or my company. The application is open source application (So I have the source code). The entire existing application is basically one of the parts of my new application.
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 continuously get an error for lines 34, 36, and 37 saying that the variables may not have been initialized.
import java.util.Scanner; import java.util.Random; public class MathTutor { public static void main(String[] args) { Random r = new Random (); Scanner input = new Scanner (System.in); /*int min=1; int max=10;*/ int num1,num2,operation; int n1= r.nextInt((9+1)+1); int n2= r.nextInt((9+1)+1); operation= r.nextInt(3); int correctAnswer; int userAnswer;
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 am reading input from a file that has following information:
line 1 = numbers of integers in array, line 2 = elements in array1, line 3 = elements in array2.
These lines constitute a test case. There are 1000 test cases in the input file.
So basically, I read the length of arrays, populate the arrays by reading from the file.
The code is below ( I have not included reading input code):
while(test_case<1000){ if (count == 1){ //count keeps track of lines in input file vec_length = Integer.parseInt (tokenizer.nextToken()); count++; continue; } if (count == 2){ //populates array1 vector1 = new int[vec_length]; for (int i = 0; i < vector1.length; i++) vector1[i] = Integer.parseInt (tokenizer.nextToken()); count++; continue; }
Array2 is populated using the same as above code. However when I use the following code:
for (int i=0; i<vec_length; i++) temp += vector1[i]*vector2[i];
I get " local variable vector1 and vector2 have not been initialized error". But both arrays have been initialized in the if{} block. Is it because initialization was local to if block?
class Super { static String ID = "QBANK"; } class Sub extends Super{ static { System.out.print("In Sub"); } } public class Test{ public static void main(String[] args){ System.out.println(Sub.ID); } }
According to me output should be "QBANK" In Sub...BECAUSE sub default constructor will call super() constructor.. below is the definition in jls which i am unable to understand ....
A class or interface type T will be initialized at its first active use, which occurs if:
T is a class and a method actually declared in T (rather than inherited from a superclass) is invoked.
T is a class and a constructor for class T is invoked, or T1 is an array with element type T, and an array of type T1 is created.
A non-constant field declared in T (rather than inherited from a superclass or superinterface) is used or assigned. A constant field is one that is (explicitly or implicitly) both final and static, and that is initialized with the value of a compile-time constant expression . Java specifies that a reference to a constant field must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field are never active uses.
All other uses of a type are passive. A reference to a field is an active use of only the class or interface that actually declares it, even though it might be referred to through the name of a subclass, a subinterface, or a class that implements an interface.