package Threads;
public class Threads1 implements Runnable {
public void run(){
System.out.println("
* * * * *
");
}
public static void main(String[] args) {
[code]...
Java Code:
new Thread(new Threads1()).start(); mh_sh_highlight_all('java');
should execute the thread associated with the run() and then the control should return to the next statement in the calling thread (the thread from which the other thread (associated with run()) was called); isn't it?
I am trying to write a program for converting positive binary inputs into hex. in the hex output the point (".")is missing.
Suppose my expected output is e7.6 , but i am getting e76
only the "." is missing.
here is my BinToHex class..
import java.io.*; public class BinToHex { double tempDec,fractionpart; long longofintpart,templongDec; String input ="11100111.011"; String hexOutput=null,tempDecString,hex = null; static int i = 1;
I'm currently learning about Swing but I can't get my head round this piece of the code. Here is a simplified gui (not interested in the gui part but the execution)
public class SwingDemo implements ActionListener { SwingDemo(){ JFrame jfrm = new JFrame("Simple gui pro"); //rest of code public static void main(String[] args) { new SwingDemo(); }
I get the above, create a new instance of SwingDemo in the main thread which starts up the gui through the constructor. However, then the tutorial says that I should avoid doing the above but do this instead:
public class SwingDemo implements ActionListener { SwingDemo(){ JFrame jfrm = new JFrame("Simple gui pro"); //rest of code public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { //why do this instead? public void run(){ new SwingDemo(); } }); } }
Reading, it talks about an event-dispatching thread which has completely lost me... Why not just instantiate the object directly instead of creating another thread?
im having an issue with the 3rd thread that are supposed to merge the two sorted sub arrays , i pass the 2 subarrays to my runnable function sortlist and they are renamed IntSortList 1 and 2 and th1.start() and th1.join() are called and it works fine, but then i have another runnable constructor that takes IntSortList 1 and 2 but it does take a runnable. below is the code in my main,
Runnable InSortlist1 = new sortList(data2p1); Runnable InSortlist1 = new sortList(data2p1); Thread th1 = new Thread (IntSortlist1); Thread th2 = new Thread (IntSortlist2); try { th1.start(); th1.join();
char array[] = new char[10]; int i = 0; array[i++] = (char)('A' + i); System.out.println("char for array is: " + array[0]); mh_sh_highlight_all('java');
However, the result for array[0] is B. Not A. from my understanding, the array[0] should be 'A'.
I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).
Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).
It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.
On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).
What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....
My problem: Can't move my camera even tho it was working before.
I'm making a Hangman program for Java, here's my code:
import java.util.Scanner; public class Hangman { /** * @param args the command line arguments */ public static void main(String[] args) { String answerWord = WordList.getWord();
[Code] .....
The Compiler gives me this only error:
Hangman.java:39: error: unexpected type displayWord.charAt(i)=userInput.charAt(0); ^ required: variable found: value
I understand that charAt returns i as a value and not a variable. What do I use to return a variable as I intended?
I first time tried Java web service sample example using eclipse with axis2. First i wrote the provider class. Then by clicking create Web Service from the provider class It will show the following error "IWAB0014E Unexpected exception occurred." I have attached the screenshot for reference.
I'm trying to write data for three products to a random access file, but I have a problem. Each product has a code and a price. After writing them to my file, I want to get to the second field or product. I do this by getting the length for each record, and multiplying it by the field number I want to go to. I use the result for the seek() method of the RandomAccessFile object. It is giving me an EOFException, but when I use 0 for the seek method i get the data for the first poduct or field.
Java Code:
public static void main(String[] args) { final int RECORD_LENGTH = 16; try(RandomAccessFile productsOutput = new RandomAccessFile("C:UsersalfonsoDesktopBinaryTestRandom.ran", "rw")) { String[] codes = {"java", "jsps", "txtp"}; double[] prices = {49.5, 19.9, 29.9}; for(int i = 0; i < codes.length; i++) {
I want to try and run a thread that starts running on start and quits after pressing a key.I cant seem to detect keypresses. ci cant seem to add code: Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words.
its just a code snippit without links or anything..this is a small part... but how do i add a keyListener in here that listends to a random key?The class implements KeyListener and the overrided method "keyPressed" sets the isRunning boolean to false... but the keyPressed method is never executed.
public static void main(String[] args) { Thread thread = new Thread() { public void run() { while(isRunning){ System.out.println("running"); try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; thread.start(); }
public class pracDraw extends JFrame { private Color red=Color.red; public int i; private Color white = Color.white; JPanel pr=new JPanel(); JTextField t=new JTextField();
[code]....
If u run it you can see that the JTextField (t1) is drawn on the panel along the line but it does so with a gray border. How do i eliminate that grey border and only draw the text field along the line and finally make the text field green after it reaches the end of line?
I have a program ive been working on and it works, but the flags in the runnables seem to shift the output down 1. for instance i commented playa3. start(); to see whats going on, if i just run playa1 i got no issues, as soon as i enable playa2, i get this output:
Game continues... Dealer places King and Queen on the table.
Game continues... Dealer places Queen and Ace on the table. Player one with 'Ace' places his card on the table. Player one with 'Ace' wins the current deal. King Queen
Game continues... Dealer places Queen and King on the table. Player two with 'King' places his card on the table. Player two with 'King' wins the current deal. Queen Ace
the second time the dealer deals, player one places his cards on the table when he was supposed to do that for the first deal which he didnt. the last line there, (king queen) is just a print statement that is referring to the dealers hand that, that iteration is responding too. below is my code, i
public class P5 { public static int i, count, dealerFirstCard, dealerSecondCard, player1, player2, player3; public static String cardSet [] = {"Ace","King", "Queen"}; public static volatile boolean dealerFinished= false; public static volatile boolean playersFinished= false;
From within that thread I try to call a method from within the same class the contain the thread. This method is not being called. I have confirmed that that section of code is being executed in the thread.
If you look at the following code, the thread being run is called MainThread ln 114, and the method it calls that is not being executed is called onprogressTime() ln 105;
I start my thread, it's for a real basic game I'm learning. Everything was working fine, until I got to recognizing keys. It runs, and I can close using the mouse on the close command, but the keys aren't being generated from the keyboard. I copied it to a working sample, and here are the two files.
The idea was to set the return value to true if any key is pressed, thus quitting, for this short sample program. Problem, it never recognizes any keys pressed on the keyboard. New to java and threading.
I am new to java and still learning. I am trying to execute the code below which compiles successfully, but getting the following error:"Exception in thread "main" java.lang.NoSuchMethodError: main"
Code:
class Dog{ int size; String name; String breed; void bark(){ System.out.println("woof woof"); } } class DogTestDrive{
I have objects (baddies in a game) that have individual clocks/counters assigned to them (when I make an object, I fill an integer based array list with a new digit entry at a value of one) that all happens in threads. then in another thread, I am checking the whole list of clocks, to see if any are equal to a wanted value , then I am taking an action and reseting the clock at that point on the array list.
now, the problem is:even though my code says " yes, I've taken that action because the value of array position x was >= specified value and I will now reset the clock" it doesn't reset the clock. Here is what it looks like
*these are excerpts taken from a really big program, however they should stand on their own as they are individual classes
Java Code:
public class levelclock extends Thread { public void run() { while (Run2 == true) { if (Run == false) { try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace();
[code]....
(Attached, just open up the zip and read the .txt)
I created a main class called X and two Y and Z classes.
Y and Z implements Runnable classes.
class X contains a static array A that can be accessed in Y and Z.
The Run () method of the class Y reads an input file and populates the vector A.
The Run () method of the Z class uses data stored into the vector A to process some data.
The objective of using threads in this problem is: as the vector A is filled in the Run () method of class Y, the Run () method of the class Z will processing the received values in the vector A.
to do this I did the following calls in the main method of class X:
ObjectY y = new Y (); Thready thread = new Thread (objectY); threadY.start (); ObjectZ new Z = Z (); Threadz thread = new Thread (objectZ); threadZ.start ();
is that correct? I'm getting the expected results, but dont know if the code is parallelized in fact.