I am curently working on a GUI and when clicking a certain button:
settingsB.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
System.out.println("Settings");
}
});
Instead of just printing it there should a new window open where you can adjust settings with sliders textboxes, ... How would you approach that? With new classes or all inside the action listener?
Edit:
My "current solution" is based on the great suggestion from user Holger to call a method showSettingsDialogue():
private void showSettingsDialogue() {
if(settingsOpen) {
return;
}
else {
settingsOpen = true;
settingWindow = new SettingsWindow();
settingWindow.addWindowListener(new WindowListener() {
#Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowClosed(WindowEvent e) {
settingsOpen = false;
}
#Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
}
Unfortunally with this way I have to write down even unimplemented methods. Any bether solution then this?
Hello guys,
I have been trying to implement google play services with LibGDX and am trying to create a Quickgame() where everyone is auto matched. However, on the public void onRoomCreated(int arg0, Room arg1) method, the when i print out the status code, it keeps giving me 6.
I have tried several solutions but to no avail
Relinking the game and ensuring the SHA1 code is correct. (Sign in works correctly)
Checking my phones network status, it is connected to the internet.
Does anyone perhaps have a solution? Thank you!
public class GSGameHelper extends GameHelper implements RoomUpdateListener, RealTimeMessageReceivedListener,RoomStatusUpdateListener {
final static String TAG = "ButtonClicker2000";
static final int RC_SELECT_PLAYERS = 10000;
static final int RC_WAITING_ROOM = 10002;
private Activity activity;
private String mRoomID;
private MacroHardv2 game;
public GSGameHelper(Activity activity, int clientsToUse) {
super(activity, clientsToUse);
this.activity = activity;
// TODO Auto-generated constructor stub
}
public void quickGame(){
Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.setAutoMatchCriteria(am);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
public void initMatch(){
Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, 1);
this.activity.startActivityForResult(intent, RC_SELECT_PLAYERS);
}
private RoomConfig.Builder makeBasicRoomConfigBuilder() {
return RoomConfig.builder((RoomUpdateListener) this)
.setMessageReceivedListener((RealTimeMessageReceivedListener) this)
.setRoomStatusUpdateListener((RoomStatusUpdateListener) this);
}
public void onActivityResult(int request,int response, Intent data){
if (request == GSGameHelper.RC_WAITING_ROOM){
if (response == Activity.RESULT_CANCELED || response == GamesActivityResultCodes.RESULT_LEFT_ROOM ){
Games.RealTimeMultiplayer.leave(getApiClient(), this, mRoomID);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
BaseGameUtils.showAlert(activity, "Partida abandonada");
}else{
BaseGameUtils.showAlert(activity, "Comenzando partida");
this.game.multiplayerGameReady();
}
}
else if (request == GSGameHelper.RC_SELECT_PLAYERS){
if (response != Activity.RESULT_OK) {
// user canceled
return;
}
// get the invitee list
Bundle extras = data.getExtras();
final ArrayList<String> invitees =
data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
// get auto-match criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers =
data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers =
data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
Gdx.app.log("J", "Jmin" + minAutoMatchPlayers + " Jmax:" + maxAutoMatchPlayers);
for (String invitee : invitees){
Gdx.app.log("L" , invitee);
}
if (minAutoMatchPlayers > 0) {
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
minAutoMatchPlayers, maxAutoMatchPlayers, 0);
} else {
autoMatchCriteria = null;
}
// create the room and specify a variant if appropriate
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.addPlayersToInvite(invitees);
if (autoMatchCriteria != null) {
roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}else{
super.onActivityResult(request, response, data);
}
}
#Override
public void onJoinedRoom(int arg0, Room arg1) {
if (arg0 != GamesStatusCodes.STATUS_OK) {
Gdx.app.log("R", "Joined FAILED");
}else{
Gdx.app.log("R", "Joined Room");
}
}
#Override
public void onLeftRoom(int arg0, String arg1) {
BaseGameUtils.makeSimpleDialog(activity, "Abandonado partida");
Gdx.app.log("LEAVE", "Me fui de la Room");
}
#Override
public void onRoomConnected(int arg0, Room arg1) {
// TODO Auto-generated method stub
}
public void setGame(MacroHardv2 game){
this.game = game;
}
#Override
public void onRoomCreated(int arg0, Room arg1) {
if (arg0 != GamesStatusCodes.STATUS_OK) {
//BaseGameUtils.showAlert(activity, "Room creation error");
BaseGameUtils.makeSimpleDialog(activity, "Error al crear la partida", "Room creation error " + arg0).show();
Gdx.app.log("R", "Room Created FAILED");
}else{
Gdx.app.log("R", "Room Created");
mRoomID = arg1.getRoomId();
Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(getApiClient(), arg1, 2);
this.activity.startActivityForResult(i, RC_WAITING_ROOM);
}
}
public void sendPos(float x,float y){
try{
byte[] mensaje;
mensaje = ByteBuffer.allocate(8).putFloat(x).putFloat(y).array();
Games.RealTimeMultiplayer.sendUnreliableMessageToOthers(getApiClient(), mensaje, mRoomID);
}catch(Exception e){
}
}
#Override
public void onRealTimeMessageReceived(RealTimeMessage rtm) {
float x, y;
byte[] b = rtm.getMessageData();
ByteBuffer bf = ByteBuffer.wrap(b);
x = bf.getFloat();
y = bf.getFloat();
game.updateGameWorld(x,y);
}
#Override
public void onConnectedToRoom(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDisconnectedFromRoom(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onP2PConnected(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onP2PDisconnected(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPeerDeclined(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerInvitedToRoom(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerJoined(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerLeft(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeersConnected(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeersDisconnected(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onRoomAutoMatching(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onRoomConnecting(Room arg0) {
// TODO Auto-generated method stub
}
}
Based on this documentation, you need to check if multiplayer support is enabled for your client ID. You need to enable real-time multiplayer support in the Developer Console. Check this link on how to enable multiplayer support.
This SO ticket might also help.
I am trying to establish a websocket connection with port:5280,but unable to connect(server is not listening).
public static WebSocketClient cc;
public static void main(String[] args) throws URISyntaxException
{
cc=new WebSocketClient(new URI("ws://localhost:5280"))
{
#Override
public void onOpen(ServerHandshake arg0)
{
// TODO Auto-generated method stub
System.out.println("onOpen" +arg0);
}
#Override
public void onMessage(String arg0)
{
// TODO Auto-generated method stub
System.out.println("onMessage");
}
#Override
public void onError(Exception arg0)
{
// TODO Auto-generated method stub
System.out.println("onError");
}
#Override
public void onClose(int arg0, String arg1, boolean arg2)
{
// TODO Auto-generated method stub
System.out.println("onClose");
}
};
cc.connect();
Above one is working with new URI("ws://localhost:8887/8080/5120") but having some problem with port no-5280.
Give me any Fix??
I want to execute my javascript code in DJ native swing jwebbrowser, but I should wait for the page loading, how can I set listener for it?
I try the following, but after loading it always run the script also it operate late!
webBrowser.addWebBrowserListener(new WebBrowserListener(){
#Override
public void commandReceived(WebBrowserCommandEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void statusChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");");
}
#Override
public void titleChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowClosing(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
frame.dispose();
}
#Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
// TODO Auto-generated method stub
}
});
what should i do?
I should override loadingProgressChanged(WebBrowserEvent arg0) not statusChanged(WebBrowserEvent arg0)
#Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");
}
but still it takes time to load my html!
i have to read data from finger print reader and convert into image file. I am using Digital Persona 's device U and U 4500 with Platinum SDK . I am new biometric field. Till now I am only able to detect the device means whether it is connected to system or not.Please guide me what should i do to accomplish this task
i have used this Code(only to check whether device is working )
import com.digitalpersona.onetouch.DPFPGlobal;
import com.digitalpersona.onetouch.DPFPSample;
import com.digitalpersona.onetouch.capture.DPFPCapture;
import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
import com.digitalpersona.onetouch.capture.event.DPFPDataListener;
import com.digitalpersona.onetouch.capture.event.DPFPErrorEvent;
import com.digitalpersona.onetouch.capture.event.DPFPErrorListener;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusListener;
import com.digitalpersona.onetouch.capture.event.DPFPSensorEvent;
import com.digitalpersona.onetouch.capture.event.DPFPSensorListener;
public class Demo {
public static void main(String args[]){
//byte[] a=null;
DPFPCapture capture=DPFPGlobal.getCaptureFactory().createCapture();
capture.addReaderStatusListener(new DPFPReaderStatusListener() {
#Override
public void readerDisconnected(DPFPReaderStatusEvent arg0) {
//TODO Auto-generated method stub
System.out.println("I m Dis-connected");
}
#Override
public void readerConnected(DPFPReaderStatusEvent arg0) {
// TODO Auto-generated method stub
System.out.println("I m connected");
}
});
capture.addSensorListener(new DPFPSensorListener() {
#Override
public void imageAcquired(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("acquired");
}
#Override
public void fingerTouched(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("s");
}
#Override
public void fingerGone(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("gone");
}
});
capture.startCapture();
capture.addDataListener(new DPFPDataListener() {
#Override
public void dataAcquired(DPFPDataEvent arg0) {
// TODO Auto-generated method stub
DPFPSample sample=DPFPGlobal.getSampleFactory().createSample();
sample=arg0.getSample();
byte a[]=sample.serialize();
for(byte i:a){
System.out.print(i);
}
}
});
capture.addErrorListener(new DPFPErrorListener() {
#Override
public void exceptionCaught(DPFPErrorEvent arg0) {
// TODO Auto-generated method stub
System.out.println("error");
}
#Override
public void errorOccured(DPFPErrorEvent arg0) {
// TODO Auto-generated method stub
System.out.println("error");
}
});
}
}
I am also currently working on a Digital Persona Finger Print Reader, I actually had the same Problem but now i have overcome it,
I think the code to add the Listeners should be in the init() method and also start the init method in the constructor of the class
The main method should only instantiate the Class.