Start Client Actions Only Once All Clients Connected
Aug 30, 2014
I was tasked to do a 2-4 player network card game. Before I jumped into doing the card game. I decided to try out an a simple program which is the clients taking turns to type in their textfield.
I have a server that listens to 3 incoming client connections. once all 3 clients is being connected,
Steps
1) The first client will send the message first while the second and third client will wait for the first client to finish sending.
2) After the first client finished sending the message, it will be second client turn to send the message and the third client will wait for the second client to send finish.
3) After the third client finished sending the message, it will be third client turn to send the message and the first client will wait for the third client to send finish and (go back to step 1))
**The first client can only start typing once all 3 clients is being connected**
In my server class,I spawn a new Thread once a client is connected, I do a wait() on each time the client is being connected, I stored the thread in a arraylist as well. I have an id to keep track how many clients is currently connected. once the id reaches 3, I used notifyall() to notify all the threads and set the first position of my arraylist as my currentThread so that I can keep track which is the currentThread running.
I started 3 clients. and I typed the textfield of the first client but my server isn't receiving any messages.
class Server implements Runnable {
private List<SpawnNewThread> sntList = new ArrayList<SpawnNewThread>();
private SpawnNewThread currentThread;
private int id = 0;
[Code].....
View Replies
ADVERTISEMENT
Apr 5, 2015
I'm trying to create a server which sends the clients connected to it its local time. Looking at a few tutorials I've managed to connect the clients to the server, but can't send data to the clients. I've successfully done easier examples, without threading. I guess the problem might be im me not knowing what exceptions are for.
Client: When running the code "AAAAAAA" does execute but "BBBB" doesn't, so I guess the problem should be in fraseRecibida = entradaDesdeServidor.readLine();
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client {
public static void main(String[] args) throws Exception{
String fraseRecibida;
[code]....
I don't understand the exceptions, maybe I should give them a look before continuing with sockets. Being frank I'm not really sure why the while(true) is there.
import java.io.*;
import java.net.*;
import java.util.Calendar;
public class ServerThread extends Thread{
Socket socket;
ServerThread(Socket socket){
this.socket = socket;
[code].....
View Replies
View Related
Sep 4, 2014
How can I let Java Web Start download my application from the server every time I run it from the client (without keeping a copy on the client machine) ?
View Replies
View Related
May 28, 2013
I have some embedded systems (with web server) putting their states, sensor values into an XML file.
<sensor1>
<temp>21.4</temp>
<unit>°C</unit>
</sensor1>
Now I played a little with EJB3. I want to start a timer bean in a 10second interval which retrieves the IP of registered devices from a databases, opens client sockets with a Thread Pool and retrieves the XML file over HTTP GET of each device listed in the db.
Is it possbile with EJB3? how to start thread based background services like that within EJB3 timer bean?
View Replies
View Related
Oct 16, 2014
I am new to making an installer so far i have made only one and i used "install creator"
I just make a watch (clock) application and i want when the windows start its also starts automatically except if it is closed by the user
just like widows clock widget.
View Replies
View Related
Mar 9, 2014
I have made a server/multi Clients where Clients send Double data but my problem is that the clients send this data to Server only wonce, and the server waits again the connection from client. (I have to run the clients manually each time)what i'm looking: the client should always send data to server. like an infinite loop.
View Replies
View Related
Apr 16, 2014
I got my first project in which i need to receive some data from multiple client on network regularly(say every second) and then process that data and stored it to the database and then GUI needs to be created which display data accordingly.
While thinking for the design i thought blocking queue to implement the same. Like producer receive data from the port into a string builder and put that into the LinkedBlockingQueue. Consumer will take this data , process some work on it and store it into the database.I am using sybase ase 15 as a database.
My question is as i am receiving data very frequently which require insertion , updation and search almost every second into the database. What is the best way to improve the performance.
say i have 2 types of data is coming one having keyword 'Alarm' and other having 'ceased' so i need to use something like this
common fields in both is name and number.
if (ceased)
search into the database for particular event for which this ceased receive using name and numbe rand update the another field into it Also make separate entry for it
else
make a entry
Also as i am using 2-3 thread for consumers and thread = Number of client for the producer. So i thought to use synchronization at the consumer side which writes data into the database such that only 1 thread can write it.
View Replies
View Related
Nov 28, 2014
So I have to create an arraylist that is connected to check boxes. Here are my current codes that I am working with. I am just focusing on making the GUI before I get into making the price calculator and everything along with that.
I need to apply the check boxes that are in the listener to the arraylist that is in the original class
Java Code:
PizzOrderPA3 toppings2 = new PizzaOrderPA3
JCheckBox toppings2 = new JCheckBox();
toppings2.addTopping("Pepperoni");
toppings2.add("Sausage");
toppings2.add("Mushroom");
toppings2.add("Bacon");
toppings2.add("Extra cheese"); mh_sh_highlight_all('java');
That is the code that I am working with but how to go along with this.
Java Code:
import java.util.ArrayList;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
[Code] .....
View Replies
View Related
Nov 3, 2014
I am writing a program with different screens. At first you have to log in to access the program. So I have a problem with the variables username and password. I can't seem to get theme from the DbConnection class. I suppose it is a basic problem?
In the DbConnection class i have a problem with the returns.
In the Login class i have a problem with the connection.getUsername(); and connection.getPassword();
Here is some code:
class DbConnection
package kim.contracts.database;
import java.sql.*;
public class DbConnection {
private Connection conn;
private Statement st;
private ResultSet rs;
[Code] .....
View Replies
View Related
Oct 23, 2014
I've been asked to create an app for nutritionists to check what their clients are eating.
I've found a database of all foods with nutritional values. In the past I've dealt with databases which just have are just one dimensional, so it's been easy to just create a string array for it. But this is absolutely huge, it's got about 10,000 rows and 30 or so columns, so that's not going to work any more.
The app needs to ask what the client ate at which times, and then save this along with the nutritional values.
What would be the best way to go about storing and calling a database of this size in java?
Should I learn SQL and JDBC to tackle it or is there any easier way?
View Replies
View Related
Dec 16, 2013
How to store the images captured from a system using web cam(from where the web application accessed) to a folder of system(where the web application is deployed) connected through lan......?
I have used applets to connect to web cam.
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
[Code] ....
Through this applet I am capturing the image and saving in the application deployed directory and accessing this image through a servlet. Every thing works fine in my system but when i try to capture from other systems connected through lan the image not saving in my system.
View Replies
View Related
Jan 23, 2015
I have tried each and every thing in all the other answers. Like setting chunked to false, changing parameters, changing http1.1 -1.0. I am just writing a sample client to compare it with my real time client. Following is the code of client:
package com.webservicemart.ws;
import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
import com.webservicemart.ws.USZipStub.ValidateZip;
public class UsZipClient {
public static void main(String[] args) {
[Code] ....
And Following is the error :
[INFO] Unable to sendViaPost to url[http://www.webservicemart.com/uszip.asmx]
org.apache.axis2.AxisFault: Transport error: 404 Error: Not Found
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
[Code] ....
I have tried with other geoIP service and weather forecast too. I get the same error.
View Replies
View Related
Oct 16, 2012
I am working wit netbean 7.2 ide,oracle 10g. the servlet program does not connected to the oracle db. i always recieve a
HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.
Oracle GlassFish Server 3.1.2.2
View Replies
View Related
Dec 22, 2014
I have started to create a calculator using Java SWING. I am new to this and don't know a huge amount. I don't know what to do now.
How do I add actions to the buttons? So when the button is pressed it will appear in the text area?
Where do I put these commands also? Within public void gui?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
lic class Calc extends JFrame implements ActionListener {
private JButton ZeroButton = new JButton("0");
private JButton OneButton = new JButton("1");
[code]....
View Replies
View Related
Mar 18, 2014
My professor like us to make a salary, taxes and etc exercise. which we should type the name first then, input salary. then if we input the amount 8000 or higher. the system will ask another question about the marital status. and that is it.
My real problem is when we input 5000-7999 the system should ask a different question, stating do you want to pay for your premiums and a follow up of yes and no choices. if we input 0-4999 the system will just state that it is your current salary.... etc..
package exer5;
import java.util.Scanner;
public class Exer5 {
public static void main(String[] args) {
Scanner Kirk = new Scanner (System.in);
[code]....
View Replies
View Related
Dec 17, 2014
I'm trying to modify an existing code and I'm having trouble with it. I want to add two things to a java Sudoku menu. I added JMenu 5 and JMenu 6 but now I have to make them work. When the user clicks on "Aide" and then "Reglements", I need to have an image that pops and that disappear when the user clicks on it.
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
[Code] .....
View Replies
View Related
Feb 2, 2014
When I add an array of action-objects (the class extends AbstractAction)
to a combo box, I do receive the action performed events, great!
But the combo box items show the long string of the action object, of course!
How to render that string in a way that only the Action.NAME appears?
I was experimenting a little, but could not make it to work:
Java Code: private class ComboRenderer2 extends BasicComboBoxRenderer {
@Override
public Component getListCellRendererComponent(JList list,
[Code]....
View Replies
View Related
Jul 19, 2014
I have two dialogues: one name "dialog" and another named "queryDialog". Each dialog has one button among other things and they are supposed to make their respective dialogues hide when clicked. But the second button doesn't work.Here is my code:
Java Code:
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import java.lang.System;
[code]...
I tried to follow the example of How to add multiple ActionListeners for multiple buttons in Java Swing - Stack Overflow but there seems to be a problem.
View Replies
View Related
Apr 18, 2010
I have spent quite a few hours trying to follow an API on how to use Actions in a java program.
I have 3 JButtons and have just added a JMenu. What I want to do is to add an ACTION so that the JMenu performs the same function as the JButtons. (i.e. they both do the same thing).
I have tried to copy and follow the example from the API forum.
How to Use Actions (The Java > Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
The first error I get in compiling is on the following line:
Action loadFile = new LOADFILE();
However, I get the following error message:
softeng2final2.java:49: cannot find symbol
symbol : class LOADFILE
location: class softeng2final2
Action loadFile = new LOADFILE();
[Code] .....
View Replies
View Related
Aug 18, 2014
How to get my program to display a piece of text (upside down) on the first button press, and then display it right-side up on the second button press. I've looked all over the internet and I can't seem to find a example that fits my situation.
Here is the code:
package org.CIS407.Lab10;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JUpsideDown extends JFrame
implements ActionListener
[Code] ....
View Replies
View Related
Mar 24, 2014
I have read that when two threads have two steps (of execution) and each step involves many operations, then the operations of both the threads kind of overlap one-another. For example
I think I am not very clear about interleaving actions/operations? Especially when we say that atomic actions can not be interleaved. But
Java Code:
class Counter{
private int c=0;
void increment () {
c++;
}
void readIn () {
[Code] ....
And the following sequence of events occurs.
Thread A: Retrieve cThread A: Increment cThread A: Store the result in cThread B: Ask the user to enter a valueThread B: Read in the value, store it in c
Now the value of c obtained after increment will be lost (Thread Interference). Isn't this an example of interleaving operations?
View Replies
View Related
Apr 24, 2014
This is my modalPanel code:
<rich:modalPanel id="createManagedObject" moveable="false" autosized="true" width="500" rendered="true" domElementAttachment="form">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Create Managed Object"></h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:outputLink onclick="#{rich:component('createManagedObject')}.hide(); return false;">
[Code] ....
As shown in the above code:
I have following components in ModalPanel:
1) ComboBox
2) Instance
3) Save and Cancel
I wanted some validation here :
For example:
- The Instance Text box and SAVE button should be disabled. When the pop up appears.
- The Instance Text BOX gets enabled only when any selection happenes in COMBO Box
- The SAVE button gets enabled only when COMBO BOX and INSTANCE TEXT BOX is filled.
- Let the CANCEL button be enabled always.
View Replies
View Related
Oct 20, 2014
I'd like to change the text on the two buttons which I have in my Dialog Box, how should I do this?
Also, when I click the X Button in the top right of the Dialog Box, nothing happens, and the program only stops when I end it in jGrasp. How do I make this button close the program when clicked on?
import javax.swing.*;
import java.util.Random;
public class SwingInputExample {
public static void main(String args[]) {
[Code] .....
View Replies
View Related
Apr 27, 2014
how to start a new thread
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?
View Replies
View Related
May 4, 2015
package com.example;
import com.example.domain.Admin;
import com.example.domain.Director;
[Code]....
View Replies
View Related
Nov 24, 2014
So, I have a gameOver() method that should when oval goes out of bounds abort game but, as soon as I start the game it runs the gameOver method. I've been looking over it for a while trying different things. I think what stood out to me is removing the abort sequence the game runs mostly as it should after, popup is closed and that if I replace game.gameOver(); with ya = -1 the ball bounces off the wall.
gameOver()
public void gameOver(){
JOptionPane.showMessageDialog(this, "Game Over", "Game Over", JOptionPane.YES_NO_OPTION);
System.exit(ABORT);
[Code] ....
View Replies
View Related